-
Notifications
You must be signed in to change notification settings - Fork 129
docs: add how-to guide about CI #2405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dwilding
wants to merge
14
commits into
canonical:main
Choose a base branch
from
dwilding:ci-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
209dbf8
remove CI content from testing explanation doc
dwilding 5463569
remove CI content from write & structure how-to guide
dwilding b3fe881
add new how-to guide
dwilding 82d07aa
update homepage and landing page
dwilding 2874d88
update "Manage charms"
dwilding e86c8e8
fix link to logging how-to
dwilding 0febefd
add missing pack
dwilding e1690c4
add comment about packing
dwilding 3e4d713
clarify about library publishing
dwilding 582b868
recommend a single yaml file
dwilding 18ba457
update workflow after review and real testing
dwilding 8781f4a
remove charm-logdump-action and add link to how-to guide
dwilding 4c76084
add a page description, following Canonical's guidelines
dwilding 7a220e9
use non-hidden dir for logs
dwilding File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
docs/howto/set-up-continuous-integration-for-a-charm.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| --- | ||
| myst: | ||
| html_meta: | ||
| description: Learn how to set up CI for your Juju charm, so that your charm's tests run on every pull request. | ||
| --- | ||
|
|
||
| (set-up-ci)= | ||
| # How to set up continuous integration for a charm | ||
|
|
||
| ```{admonition} Best practice | ||
| :class: hint | ||
|
|
||
| The quality assurance pipeline of a charm should be automated using a continuous integration (CI) system. | ||
| ``` | ||
|
|
||
| This guide demonstrates how to automatically run your charm's tests against any PR into the main branch of your GitHub repository. | ||
|
|
||
| You might also want to automatically publish your charm on Charmhub or publish charm libraries on PyPI. [charming-actions](https://github.com/canonical/charming-actions) has some useful GitHub actions for publishing on Charmhub. For guidance about publishing libraries on PyPI, see {external+charmlibs:ref}`How to distribute charm libraries <python-package-distribution-pypi>`. | ||
|
|
||
| (set-up-ci-linting-unit)= | ||
| ## Run linting and unit tests in CI | ||
|
|
||
| Create a file called `.github/workflows/ci.yaml`: | ||
|
|
||
| ```yaml | ||
| name: Charm tests | ||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| pull_request: | ||
| workflow_call: | ||
| workflow_dispatch: | ||
dwilding marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| permissions: {} | ||
|
|
||
| jobs: | ||
| lint: | ||
| name: Linting | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| persist-credentials: false | ||
| - name: Set up uv | ||
| uses: astral-sh/setup-uv@cec208311dfd045dd5311c1add060b2062131d57 # v8.0.0 | ||
| - name: Set up tox and tox-uv | ||
| run: uv tool install tox --with tox-uv | ||
| - name: Lint the code | ||
| run: tox -e lint | ||
|
|
||
| unit: | ||
| name: Unit tests | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| persist-credentials: false | ||
| - name: Set up uv | ||
| uses: astral-sh/setup-uv@cec208311dfd045dd5311c1add060b2062131d57 # v8.0.0 | ||
| - name: Set up tox and tox-uv | ||
| run: uv tool install tox --with tox-uv | ||
| - name: Run unit tests | ||
| run: tox -e unit | ||
| ``` | ||
|
|
||
| (set-up-ci-integration)= | ||
| ## Run integration tests in CI | ||
|
|
||
| Integration tests require a Juju controller and a cloud in which to deploy your charm. We recommend that you use [Concierge](https://github.com/canonical/concierge) to prepare the CI environment. | ||
|
|
||
| If your charm is a Kubernetes charm, add the following job to `.github/workflows/ci.yaml`: | ||
|
|
||
| ```yaml | ||
| integration: | ||
dwilding marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| name: Integration tests | ||
| runs-on: ubuntu-latest | ||
| needs: | ||
| - unit | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| persist-credentials: false | ||
| - name: Set up uv | ||
| uses: astral-sh/setup-uv@cec208311dfd045dd5311c1add060b2062131d57 # v8.0.0 | ||
| - name: Set up tox and tox-uv | ||
| run: uv tool install tox --with tox-uv | ||
| - name: Set up Concierge | ||
| run: sudo snap install --classic concierge | ||
| - name: Set up Juju and charm development tools | ||
| run: sudo concierge prepare -p k8s | ||
| - name: Pack the charm | ||
| # The integration tests don't pack the charm. Instead, they look for a .charm | ||
| # file in the project dir (or use CHARM_PATH, if set). | ||
| run: charmcraft pack | ||
| - name: Run integration tests | ||
dwilding marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| run: tox -e integration -- --juju-dump-logs logs | ||
| - name: Upload logs | ||
| if: ${{ !cancelled() }} | ||
| uses: actions/upload-artifact@v7 | ||
| with: | ||
| name: juju-dump-logs | ||
| path: logs | ||
| ``` | ||
|
|
||
| The option `-p k8s` tells Concierge that we want a cloud managed by Canonical Kubernetes. | ||
|
|
||
| If your charm is a machine charm, use `-p machine` instead. | ||
|
|
||
| The "Upload logs" step assumes that your integration tests use Jubilant together with `pytest-jubilant`. See [How to write integration tests for a charm](#write-integration-tests-for-a-charm-view-juju-logs). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.