Skip to content

Commit

Permalink
chore: Building charm in independent step (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gmerold authored Apr 26, 2024
1 parent 66ed44f commit 2300bc7
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ on:
jobs:
codeql:
name: CodeQL Analysis
uses: canonical/sdcore-github-workflows/.github/workflows/codeql-analysis.yml@v0.0.1
uses: canonical/sdcore-github-workflows/.github/workflows/codeql-analysis.yml@v1.0.0
2 changes: 1 addition & 1 deletion .github/workflows/dependabot_pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ permissions:

jobs:
auto-merge:
uses: canonical/sdcore-github-workflows/.github/workflows/dependabot_pr.yaml@v0.0.1
uses: canonical/sdcore-github-workflows/.github/workflows/dependabot_pr.yaml@v1.0.0
2 changes: 1 addition & 1 deletion .github/workflows/issues.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ on:
jobs:
update:
name: Update Issue
uses: canonical/sdcore-github-workflows/.github/workflows/issues.yaml@v0.0.1
uses: canonical/sdcore-github-workflows/.github/workflows/issues.yaml@v1.0.0
secrets:
JIRA_URL: ${{ secrets.JIRA_URL }}
34 changes: 20 additions & 14 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,34 @@ on:

jobs:
check-libraries:
uses: canonical/sdcore-github-workflows/.github/workflows/check-libraries.yaml@v0.0.1
uses: canonical/sdcore-github-workflows/.github/workflows/check-libraries.yaml@v1.0.0
secrets:
CHARMCRAFT_AUTH: ${{ secrets.CHARMCRAFT_AUTH }}

lint-report:
uses: canonical/sdcore-github-workflows/.github/workflows/lint-report.yaml@v0.0.1
uses: canonical/sdcore-github-workflows/.github/workflows/lint-report.yaml@v1.0.0

static-analysis:
uses: canonical/sdcore-github-workflows/.github/workflows/static-analysis.yaml@v0.0.1
uses: canonical/sdcore-github-workflows/.github/workflows/static-analysis.yaml@v1.0.0

terraform-check:
uses: canonical/sdcore-github-workflows/.github/workflows/terraform.yaml@v0.0.1
uses: canonical/sdcore-github-workflows/.github/workflows/terraform.yaml@v1.0.0

unit-tests-with-coverage:
uses: canonical/sdcore-github-workflows/.github/workflows/[email protected]
uses: canonical/sdcore-github-workflows/.github/workflows/[email protected]

build:
needs:
- lint-report
- static-analysis
- unit-tests-with-coverage
uses: canonical/sdcore-github-workflows/.github/workflows/[email protected]
secrets: inherit

integration-test:
uses: canonical/sdcore-github-workflows/.github/workflows/[email protected]
with:
charm-file-name: "sdcore-upf-k8s_ubuntu-22.04-amd64.charm"
needs:
- build
uses: canonical/sdcore-github-workflows/.github/workflows/[email protected]

publish-charm:
name: Publish Charm
Expand All @@ -39,9 +47,8 @@ jobs:
- unit-tests-with-coverage
- integration-test
if: ${{ github.ref_name == 'main' }}
uses: canonical/sdcore-github-workflows/.github/workflows/publish-charm.yaml@v0.0.1
uses: canonical/sdcore-github-workflows/.github/workflows/publish-charm.yaml@v1.0.0
with:
charm-file-name: "sdcore-upf-k8s_ubuntu-22.04-amd64.charm"
track-name: 1.5
secrets:
CHARMCRAFT_AUTH: ${{ secrets.CHARMCRAFT_AUTH }}
Expand All @@ -54,10 +61,9 @@ jobs:
- unit-tests-with-coverage
- integration-test
if: ${{ (github.ref_name != 'main') && (github.event_name == 'push') }}
uses: canonical/sdcore-github-workflows/.github/workflows/publish-charm.yaml@v0.0.1
uses: canonical/sdcore-github-workflows/.github/workflows/publish-charm.yaml@v1.0.0
with:
branch-name: ${{ github.ref_name }}
charm-file-name: "sdcore-upf-k8s_ubuntu-22.04-amd64.charm"
track-name: 1.5
secrets:
CHARMCRAFT_AUTH: ${{ secrets.CHARMCRAFT_AUTH }}
Expand All @@ -81,7 +87,7 @@ jobs:
- publish-charm
- fiveg-n3-lib-needs-publishing
if: ${{ github.ref_name == 'main' }}
uses: canonical/sdcore-github-workflows/.github/workflows/publish-lib.yaml@v0.0.1
uses: canonical/sdcore-github-workflows/.github/workflows/publish-lib.yaml@v1.0.0
with:
lib-name: "charms.sdcore_upf_k8s.v0.fiveg_n3"
secrets: inherit
Expand All @@ -105,7 +111,7 @@ jobs:
- publish-charm
- fiveg-n4-lib-needs-publishing
if: ${{ github.ref_name == 'main' }}
uses: canonical/sdcore-github-workflows/.github/workflows/publish-lib.yaml@v0.0.1
uses: canonical/sdcore-github-workflows/.github/workflows/publish-lib.yaml@v1.0.0
with:
lib-name: "charms.sdcore_upf_k8s.v0.fiveg_n4"
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/promote.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ on:
jobs:
promote:
name: Promote Charm
uses: canonical/sdcore-github-workflows/.github/workflows/promote.yaml@v0.0.1
uses: canonical/sdcore-github-workflows/.github/workflows/promote.yaml@v1.0.0
with:
promotion: ${{ github.event.inputs.promotion }}
track-name: ${{ github.event.inputs.track-name }}
Expand Down
12 changes: 8 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,14 @@ There are some pre-configured environments
that can be used for linting and formatting code when you're preparing contributions to the charm:

```shell
tox -e lint # code style
tox -e static # static analysis
tox -e unit # unit tests
tox -e integration # integration tests
tox -e lint # code style
tox -e static # static analysis
tox -e unit # unit tests
tox -e integration -- --charm_path=PATH_TO_BUILD_CHARM # integration tests
```

```note
Integration tests require the charm to be built with `charmcraft pack` first.
```

## Build
Expand Down
38 changes: 38 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python3
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

import os

import pytest


def pytest_addoption(parser: pytest.Parser) -> None:
"""Add options to the pytest command line.
This is a pytest hook that is called when the pytest command line is being parsed.
Args:
parser: The pytest command line parser.
"""
parser.addoption(
"--charm_path",
action="store",
default=None,
help="Path to the charm under test"
)


def pytest_configure(config: pytest.Config) -> None:
"""Validate the options provided by the user.
This is a pytest hook that is called after command line options have been parsed.
Args:
config: The pytest configuration object.
"""
charm_path = str(config.getoption("--charm_path"))
if not charm_path:
pytest.exit("The --charm_path option is required. Tests aborted.")
if not os.path.exists(charm_path):
pytest.exit(f"The path specified for the charm under test does not exist: {charm_path}")
13 changes: 6 additions & 7 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ async def _deploy_grafana_agent(ops_test: OpsTest):


@pytest.fixture(scope="module")
async def build_and_deploy(ops_test):
"""Build the charm-under-test and deploy it."""
charm = await ops_test.build_charm(".")
async def deploy(ops_test: OpsTest, request):
"""Deploy required components."""
assert ops_test.model
charm = Path(request.config.getoption("--charm_path")).resolve()
resources = {
"bessd-image": METADATA["resources"]["bessd-image"]["upstream-source"],
"pfcp-agent-image": METADATA["resources"]["pfcp-agent-image"]["upstream-source"],
Expand All @@ -46,10 +47,8 @@ async def build_and_deploy(ops_test):


@pytest.mark.abort_on_fail
async def test_given_charm_is_built_when_deployed_then_status_is_active(
ops_test,
build_and_deploy,
):
async def test_given_charm_is_built_when_deployed_then_status_is_active(ops_test: OpsTest, deploy):
assert ops_test.model
await ops_test.model.integrate(
relation1=f"{APP_NAME}:logging", relation2=GRAFANA_AGENT_APP_NAME
)
Expand Down

0 comments on commit 2300bc7

Please sign in to comment.