Skip to content

Commit

Permalink
Cache charmcraft pack container, skip unstable tests except on schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
carlcsaposs-canonical authored and deusebio committed Mar 14, 2023
1 parent 9145888 commit 3ded862
Show file tree
Hide file tree
Showing 15 changed files with 172 additions and 288 deletions.
147 changes: 56 additions & 91 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,132 +1,97 @@
name: Testing
# Copyright 2022 Canonical Ltd.
# See LICENSE file for licensing details.
name: Tests

on:
pull_request:
schedule:
- cron: '53 0 * * *' # Daily at 00:53 UTC
# Triggered on push to branch "main" by .github/workflows/release.yaml
workflow_call:

jobs:
lint:
name: Lint
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install dependencies
uses: actions/checkout@v3
- name: Install tox
# TODO: Consider replacing with custom image on self-hosted runner OR pinning version
run: python3 -m pip install tox
- name: Run linters
run: tox -e lint
run: tox run -e lint

unit-test:
name: Unit tests
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install dependencies
run: python -m pip install tox
uses: actions/checkout@v3
- name: Install tox
# TODO: Consider replacing with custom image on self-hosted runner OR pinning version
run: python3 -m pip install tox
- name: Run tests
run: tox -e unit
run: tox run -e unit

security-test:
name: Security tests
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install dependencies
run: python -m pip install tox
- name: Install tox
# TODO: Consider replacing with custom image on self-hosted runner OR pinning version
run: python3 -m pip install tox
- name: Run tests
run: tox -e security
run: tox run -e security

integration-test-charm:
name: Integration tests (microk8s)
needs:
- lint
- unit-test
- security-test
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
with:
provider: microk8s
# This is needed until https://bugs.launchpad.net/juju/+bug/1977582 is fixed
bootstrap-options: "--agent-version 2.9.29"
- name: Run integration tests
run: tox -e integration-charm
build:
name: Build charms
uses: canonical/data-platform-workflows/.github/workflows/build_charms_with_cache.yaml@v1

integration-test-scaling:
name: Integration tests for scaling (microk8s)
integration-test:
strategy:
fail-fast: false
matrix:
tox-environments:
- integration-charm
- integration-scaling
- integration-provider
- integration-password-rotation
- integration-tls
name: ${{ matrix.tox-environments }}
needs:
- lint
- unit-test
- security-test
runs-on: ubuntu-22.04
- build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Setup operator environment
# TODO: Replace with custom image on self-hosted runner
uses: charmed-kubernetes/actions-operator@main
with:
provider: microk8s
# This is needed until https://bugs.launchpad.net/juju/+bug/1977582 is fixed
bootstrap-options: "--agent-version 2.9.29"
- name: Run integration tests
run: tox -e integration-scaling

integration-test-provider:
name: Integration tests for provider (microk8s)
needs:
- lint
- unit-test
- security-test
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
- name: Download packed charm(s)
uses: actions/download-artifact@v3
with:
provider: microk8s
# This is needed until https://bugs.launchpad.net/juju/+bug/1977582 is fixed
bootstrap-options: "--agent-version 2.9.29"
- name: Run integration tests
run: tox -e integration-provider

integration-test-password-rotation:
name: Integration tests for password rotation (microk8s)
needs:
- lint
- unit-test
- security-test
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
with:
provider: microk8s
# This is needed until https://bugs.launchpad.net/juju/+bug/1977582 is fixed
bootstrap-options: "--agent-version 2.9.29"
- name: Run integration tests
run: tox -e integration-password-rotation

integration-test-tls:
name: Integration tests for TLS (microk8s)
needs:
- lint
- unit-test
- security-test
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
with:
provider: microk8s
# This is needed until https://bugs.launchpad.net/juju/+bug/1977582 is fixed
bootstrap-options: "--agent-version 2.9.29"
name: ${{ needs.build.outputs.artifact-name }}
- name: Select tests
id: select-tests
run: |
if [ "${{ github.event_name }}" == "schedule" ]
then
echo Running unstable and stable tests
echo "mark_expression=" >> $GITHUB_OUTPUT
else
echo Skipping unstable tests
echo "mark_expression=not unstable" >> $GITHUB_OUTPUT
fi
- name: Run integration tests
run: tox -e integration-tls
run: tox run -e ${{ matrix.tox-environments }} -- -m '${{ steps.select-tests.outputs.mark_expression }}'
env:
CI_PACKED_CHARMS: ${{ needs.build.outputs.charms }}
142 changes: 6 additions & 136 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Check libs
Expand All @@ -20,150 +20,20 @@ jobs:
credentials: "${{ secrets.CHARMHUB_TOKEN }}" # FIXME: current token will expire in 2023-07-04
github-token: "${{ secrets.GITHUB_TOKEN }}"

lint:
name: Lint
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install dependencies
run: python3 -m pip install tox
- name: Run linters
run: tox -e lint

unit-test:
name: Unit tests
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install dependencies
run: python -m pip install tox
- name: Run tests
run: tox -e unit

security-test:
name: Security tests
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install dependencies
run: python -m pip install tox
- name: Run tests
run: tox -e security

integration-test-charm:
name: Integration tests (microk8s)
needs:
- lint
- unit-test
- security-test
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
with:
provider: microk8s
# This is needed until https://bugs.launchpad.net/juju/+bug/1977582 is fixed
bootstrap-options: "--agent-version 2.9.29"
- name: Run integration tests
run: tox -e integration-charm

integration-test-scaling:
name: Integration tests for scaling (microk8s)
ci-tests:
needs:
- lint
- unit-test
- security-test
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
with:
provider: microk8s
# This is needed until https://bugs.launchpad.net/juju/+bug/1977582 is fixed
bootstrap-options: "--agent-version 2.9.29"
- name: Run integration tests
run: tox -e integration-scaling

integration-test-provider:
name: Integration tests for provider (microk8s)
needs:
- lint
- unit-test
- security-test
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
with:
provider: microk8s
# This is needed until https://bugs.launchpad.net/juju/+bug/1977582 is fixed
bootstrap-options: "--agent-version 2.9.29"
- name: Run integration tests
run: tox -e integration-provider

integration-test-password-rotation:
name: Integration tests for password rotation (microk8s)
needs:
- lint
- unit-test
- security-test
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
with:
provider: microk8s
# This is needed until https://bugs.launchpad.net/juju/+bug/1977582 is fixed
bootstrap-options: "--agent-version 2.9.29"
- name: Run integration tests
run: tox -e integration-password-rotation

integration-test-tls:
name: Integration tests for TLS (microk8s)
needs:
- lint
- unit-test
- security-test
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
with:
provider: microk8s
# This is needed until https://bugs.launchpad.net/juju/+bug/1977582 is fixed
bootstrap-options: "--agent-version 2.9.29"
- name: Run integration tests
run: tox -e integration-tls
- lib-check
uses: ./.github/workflows/ci.yaml

release-to-charmhub:
name: Release to CharmHub
needs:
- lib-check
- lint
- unit-test
- security-test
- integration-test-charm
- integration-test-scaling
- integration-test-provider
- integration-test-password-rotation
- integration-test-tls
- ci-tests
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Select charmhub channel
Expand Down
16 changes: 8 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@ juju relate kafka-k8s zookeeper-k8s

## Developing

You can use the environments created by `tox` for development:
You can create an environment for development with `tox`:

```shell
tox --notest -e unit
source .tox/unit/bin/activate
tox devenv -e integration
source venv/bin/activate
```

### Testing

```shell
tox -e fmt # update your code according to linting rules
tox -e lint # code style
tox -e unit # unit tests
tox -e integration # integration tests
tox # runs 'lint' and 'unit' environments
tox run -e format # update your code according to linting rules
tox run -e lint # code style
tox run -e unit # unit tests
tox run -e integration # integration tests
tox # runs 'lint' and 'unit' environments
```

## Canonical Contributor Agreement
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ show_missing = true
minversion = "6.0"
log_cli_level = "INFO"
asyncio_mode = "auto"
markers = ["unstable"]

# Formatting tools configuration
[tool.black]
Expand Down
6 changes: 0 additions & 6 deletions tests/__init__.py

This file was deleted.

Loading

0 comments on commit 3ded862

Please sign in to comment.