Skip to content

Commit

Permalink
Switch from tox build wrapper to charmcraft.yaml overrides (#178)
Browse files Browse the repository at this point in the history
https://warthogs.atlassian.net/browse/DPE-5046

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Carl Csaposs <[email protected]>
  • Loading branch information
renovate[bot] and carlcsaposs-canonical authored Sep 26, 2024
1 parent 309117b commit 2f14032
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:

build:
name: Build charm
uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v21.0.1
uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v22.0.0
with:
# Use of cache blocked by https://github.com/canonical/charmcraft/issues/1456
# Details: https://github.com/canonical/charmcraftcache/issues/3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ jobs:

build:
name: Build charm
uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v21.0.1
uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v22.0.0

release:
name: Release charm
needs:
- ci-tests
- build
uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v21.0.1
uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v22.0.0
with:
channel: dpe/edge
artifact-prefix: ${{ needs.build.outputs.artifact-prefix }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sync_docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
jobs:
sync-docs:
name: Sync docs from Discourse
uses: canonical/data-platform-workflows/.github/workflows/sync_docs.yaml@v21.0.1
uses: canonical/data-platform-workflows/.github/workflows/sync_docs.yaml@v22.0.0
with:
reviewers: a-velasco
permissions:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ tox # runs 'lint' and 'unit' environments
Build the charm in this git repository using:

```shell
tox run -e build-dev
charmcraftcache pack
```

### Deploy
Expand Down
43 changes: 31 additions & 12 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,42 @@ parts:
files:
plugin: dump
source: .
build-packages:
- git
override-build: |
# Workaround to add unique identifier (git hash) to charm version while specification
# DA053 - Charm versioning
# (https://docs.google.com/document/d/1Jv1jhWLl8ejK3iJn7Q3VbCIM9GIhp8926bgXpdtx-Sg/edit?pli=1)
# is pending review.
python3 -c 'import pathlib; import shutil; import subprocess; git_hash=subprocess.run(["git", "describe", "--always", "--dirty"], capture_output=True, check=True, encoding="utf-8").stdout; file = pathlib.Path("charm_version"); shutil.copy(file, pathlib.Path("charm_version.backup")); version = file.read_text().strip(); file.write_text(f"{version}+{git_hash}")'
craftctl default
stage:
# Exclude requirements.txt file during staging
# Workaround for https://github.com/canonical/charmcraft/issues/1389 on charmcraft 2
- -requirements.txt
prime:
- charm_version
- workload_version
charm:
override-pull: |
craftctl default
if [[ ! -f requirements.txt ]]
then
echo 'ERROR: Use "tox run -e build-dev" instead of calling "charmcraft pack" directly' >&2
exit 1
fi
# TODO: enable after https://github.com/canonical/charmcraft/issues/1456 fixed
charm-strict-dependencies: false
charm-entrypoint: src/machine_charm.py
build-snaps:
- rustup
build-packages:
- libffi-dev
- libssl-dev
- pkg-config
- rustc
- cargo
override-build: |
rustup default stable
# Convert subset of poetry.lock to requirements.txt
curl -sSL https://install.python-poetry.org | python3 -
/root/.local/bin/poetry export --only main,charm-libs --output requirements.txt
craftctl default
stage:
# Exclude charm_version file during staging
- -charm_version
# TODO: enable after https://github.com/canonical/charmcraft/issues/1456 fixed
charm-strict-dependencies: false
charm-requirements: [requirements.txt]
charm-entrypoint: src/machine_charm.py
15 changes: 8 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ pytest-mock = "^3.14.0"
[tool.poetry.group.integration.dependencies]
pytest = "^8.2.2"
pytest-operator = "^0.35.0"
pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v21.0.1", subdirectory = "python/pytest_plugins/pytest_operator_cache"}
pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v21.0.1", subdirectory = "python/pytest_plugins/pytest_operator_groups"}
pytest-github-secrets = {git = "https://github.com/canonical/data-platform-workflows", tag = "v21.0.1", subdirectory = "python/pytest_plugins/github_secrets"}
pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v22.0.0", subdirectory = "python/pytest_plugins/pytest_operator_cache"}
pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v22.0.0", subdirectory = "python/pytest_plugins/pytest_operator_groups"}
pytest-github-secrets = {git = "https://github.com/canonical/data-platform-workflows", tag = "v22.0.0", subdirectory = "python/pytest_plugins/github_secrets"}
juju = "^3.5.2.0"
mysql-connector-python = "~8.0.33"
tenacity = "^8.5.0"
Expand Down
31 changes: 0 additions & 31 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,6 @@ set_env =
allowlist_externals =
poetry

[testenv:build-{production,dev,wrapper}]
# Wrap `charmcraft pack`
pass_env =
CI
GH_TOKEN
allowlist_externals =
{[testenv]allowlist_externals}
charmcraft
charmcraftcache
mv
commands_pre =
# TODO charm versioning: Remove
# Workaround to add unique identifier (git hash) to charm version while specification
# DA053 - Charm versioning
# (https://docs.google.com/document/d/1Jv1jhWLl8ejK3iJn7Q3VbCIM9GIhp8926bgXpdtx-Sg/edit?pli=1)
# is pending review.
python -c 'import pathlib; import shutil; import subprocess; git_hash=subprocess.run(["git", "describe", "--always", "--dirty"], capture_output=True, check=True, encoding="utf-8").stdout; file = pathlib.Path("charm_version"); shutil.copy(file, pathlib.Path("charm_version.backup")); version = file.read_text().strip(); file.write_text(f"{version}+{git_hash}")'

poetry export --only main,charm-libs --output requirements.txt
commands =
build-production: charmcraft pack {posargs}
build-dev: charmcraftcache pack {posargs}
commands_post =
mv requirements.txt requirements-last-build.txt
mv charm_version.backup charm_version

[testenv:format]
description = Apply coding style standards to code
commands_pre =
Expand Down Expand Up @@ -85,12 +59,7 @@ pass_env =
CI
GITHUB_OUTPUT
SECRETS_FROM_GITHUB
allowlist_externals =
{[testenv:build-wrapper]allowlist_externals}
commands_pre =
poetry install --only integration
{[testenv:build-wrapper]commands_pre}
commands =
poetry run pytest -v --tb native --log-cli-level=INFO -s --ignore={[vars]tests_path}/unit/ {posargs}
commands_post =
{[testenv:build-wrapper]commands_post}

0 comments on commit 2f14032

Please sign in to comment.