Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/_build-wheels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build Operator Wheels

on:
workflow_call:
outputs:
artifact-name:
description: "Name of the artifact containing the wheels"
value: ${{ jobs.build-wheels.outputs.artifact-name }}

permissions: {}

jobs:
build-wheels:
runs-on: ubuntu-latest
outputs:
artifact-name: ${{ steps.artifact-name.outputs.name }}
steps:
- name: Checkout the operator repository
uses: actions/checkout@v6
with:
persist-credentials: false

- name: Set up uv
uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7.1.4

- name: Build wheels
run: uv build --all

- name: Set artifact name
id: artifact-name
run: echo "name=operator-wheels-${{ github.sha }}" >> "$GITHUB_OUTPUT"

- name: Upload wheels as artifact
uses: actions/upload-artifact@v5
with:
name: ${{ steps.artifact-name.outputs.name }}
path: dist/*.whl
retention-days: 1
29 changes: 28 additions & 1 deletion .github/workflows/db-charm-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ on:
permissions: {}

jobs:
build-wheels:
uses: ./.github/workflows/_build-wheels.yaml

db-charm-tests:
runs-on: ubuntu-latest
needs: build-wheels
strategy:
fail-fast: false
matrix:
Expand All @@ -32,6 +36,12 @@ jobs:
persist-credentials: false
ref: ${{ matrix.commit }}

- name: Download operator wheels
uses: actions/download-artifact@v5
with:
name: ${{ needs.build-wheels.outputs.artifact-name }}
path: operator-wheels

- name: Checkout the operator repository
uses: actions/checkout@v6
with:
Expand All @@ -43,16 +53,33 @@ jobs:

- name: Update 'ops' dependency in test charm to latest
run: |
ops_wheel="$(ls operator-wheels/ops-[0-9]*.whl)"
if [ -e "requirements.txt" ]; then
sed -i -e "/^ops[ ><=]/d" -e "/canonical\/operator/d" -e "/#egg=ops/d" requirements.txt
echo -e "\ngit+$GITHUB_SERVER_URL/$GITHUB_REPOSITORY@$GITHUB_SHA#egg=ops" >> requirements.txt
echo -e "\n${ops_wheel}" >> requirements.txt
else
sed -i -e "s/^ops[ ><=].*/ops = {path = \"myops\"}/" pyproject.toml
poetry lock
fi

- name: Show installed ops package versions
run: |
echo "=== Wheel files downloaded ==="
ls -lh operator-wheels/*.whl || echo "No wheel files found"
echo ""
echo "=== Updated requirements.txt ==="
cat requirements.txt | tail -n 10 || echo "No requirements.txt"
echo ""
echo "=== Installed ops package version (after tox install) will be checked during test run ==="

- name: Install dependencies
run: pip install tox~=4.2

- name: Run the charm's unit tests
run: tox -vve unit

- name: Show all installed dependencies in test environment
if: ${{ !cancelled() }}
run: |
echo "=== All installed packages in unit test environment ==="
uv pip freeze || .tox/unit/bin/pip list || echo "Could not list packages from test environment"
29 changes: 28 additions & 1 deletion .github/workflows/hello-charm-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ on:
permissions: {}

jobs:
build-wheels:
uses: ./.github/workflows/_build-wheels.yaml

hello-charm-tests:
runs-on: ubuntu-latest
needs: build-wheels

strategy:
matrix:
Expand All @@ -33,15 +37,38 @@ jobs:
persist-credentials: false
ref: ${{ matrix.commit }}

- name: Download operator wheels
uses: actions/download-artifact@v5
with:
name: ${{ needs.build-wheels.outputs.artifact-name }}
path: operator-wheels

- name: Remove 'ops' from charm requirements.txt
run: |
sed -i -e "/^ops[ ><=]/d" -e "/canonical\/operator/d" -e "/#egg=ops/d" requirements.txt
TEST_OPS="git+$GITHUB_SERVER_URL/$GITHUB_REPOSITORY@$GITHUB_SHA#egg=ops"
# Find the ops wheel (not ops_scenario or ops_tracing)
TEST_OPS="$(ls operator-wheels/ops-[0-9]*.whl)"
echo -e "\n${TEST_OPS}" >> requirements.txt

- name: Show installed ops package versions
run: |
echo "=== Wheel files downloaded ==="
ls -lh operator-wheels/*.whl || echo "No wheel files found"
echo ""
echo "=== Updated requirements.txt ==="
cat requirements.txt | tail -n 10 || echo "No requirements.txt"

- name: Install dependencies
run: pip install -r requirements-dev.txt

- name: Show installed package versions after install
run: |
echo "=== Installed ops package version ==="
pip list | grep -E "(ops|scenario|tracing)" || echo "No ops packages found"
echo ""
echo "=== All installed packages ==="
pip list

- name: Run the charm tests
run: |
export PYTHONPATH="lib:src:$PYTHONPATH"
Expand Down
47 changes: 44 additions & 3 deletions .github/workflows/observability-charm-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ on:
permissions: {}

jobs:
build-wheels:
uses: ./.github/workflows/_build-wheels.yaml

o11y-charm-tests:
runs-on: ubuntu-latest
needs: build-wheels

strategy:
fail-fast: false
Expand All @@ -32,6 +36,12 @@ jobs:
persist-credentials: false
ref: ${{ matrix.commit }}

- name: Download operator wheels
uses: actions/download-artifact@v5
with:
name: ${{ needs.build-wheels.outputs.artifact-name }}
path: operator-wheels

- name: Install dependencies
run: pip install tox~=4.2 uv~=0.6

Expand All @@ -44,18 +54,49 @@ jobs:
uv remove ops --frozen
sed -i 's/requires-python = "~=3.8"/requires-python = "~=3.10"/g' pyproject.toml
sed -i 's/pythonVersion = "3\.[89]"/pythonVersion = "3.10"/g' pyproject.toml
uv add git+$GITHUB_SERVER_URL/$GITHUB_REPOSITORY@$GITHUB_SHA#subdirectory=testing --optional dev --raw-sources --prerelease=if-necessary-or-explicit
uv add git+$GITHUB_SERVER_URL/$GITHUB_REPOSITORY@$GITHUB_SHA#subdirectory=tracing --raw-sources --prerelease=if-necessary-or-explicit
uv add git+$GITHUB_SERVER_URL/$GITHUB_REPOSITORY@$GITHUB_SHA --raw-sources --prerelease=if-necessary-or-explicit
# Get absolute paths to the wheels
ops_wheel="$(ls operator-wheels/ops-[0-9]*.whl)"
ops_scenario_wheel="$(ls operator-wheels/ops_scenario-*.whl)"
ops_tracing_wheel="$(ls operator-wheels/ops_tracing-*.whl)"
# Add ops first, then ops-scenario (for testing), then ops-tracing
uv add "${ops_wheel}" --raw-sources --prerelease=if-necessary-or-explicit
uv add "${ops_scenario_wheel}" --optional dev --raw-sources --prerelease=if-necessary-or-explicit
uv add "${ops_tracing_wheel}" --raw-sources --prerelease=if-necessary-or-explicit
else
echo "Error: no uv.lock file found"
exit 1
fi

- name: Force upgrade pytest-interface-tester to fix compatibility
if: ${{ !(matrix.disabled) }}
run: |
if [ -e "uv.lock" ]; then
echo "Upgrading pytest-interface-tester to >=3.4 to ensure compatibility"
uv add "pytest-interface-tester>=3.4" --optional dev --upgrade || echo "Could not upgrade pytest-interface-tester"
fi

- name: Show installed ops package versions
if: ${{ !(matrix.disabled) }}
run: |
echo "=== Installed ops-related packages ==="
uv pip list | grep -E "(ops|scenario|tracing)" || echo "No ops packages found"
echo ""
echo "=== Wheel files downloaded ==="
ls -lh operator-wheels/*.whl || echo "No wheel files found"
echo ""
echo "=== Package versions from pyproject.toml ==="
grep -A 5 "dependencies =" pyproject.toml || echo "No dependencies section found"

- name: Run the charm's unit tests
if: ${{ !(matrix.disabled) }}
run: tox -vve unit

- name: Show all installed dependencies in test environment
if: ${{ !(matrix.disabled) && !cancelled() }}
run: |
echo "=== All installed packages in unit test environment ==="
uv pip freeze || .tox/unit/bin/pip list || echo "Could not list packages from test environment"

- name: Check if 'scenario' tox environment exists
id: check-tox-env-scenario
run: |
Expand Down
70 changes: 56 additions & 14 deletions .github/workflows/published-charms-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ on:
permissions: {}

jobs:
build-wheels:
uses: ./.github/workflows/_build-wheels.yaml

charm-tests:
runs-on: ubuntu-latest
needs: build-wheels
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -192,42 +196,63 @@ jobs:
repository: ${{ matrix.charm-repo }}
persist-credentials: false

- name: Download operator wheels
uses: actions/download-artifact@v5
with:
name: ${{ needs.build-wheels.outputs.artifact-name }}
path: operator-wheels

- name: Install patch dependencies
run: pip install poetry~=2.0 uv~=0.6 tox-uv~=1.2

- name: Update 'ops' and 'ops-scenario' dependencies in test charm to latest
working-directory: ${{ matrix.charm-root }}
run: |
set -xueo pipefail
# Get the absolute paths to the wheels
ops_wheel="$(cd .. && ls $(pwd)/operator-wheels/ops-[0-9]*.whl)"
ops_scenario_wheel="$(cd .. && ls $(pwd)/operator-wheels/ops_scenario-*.whl)"
if [ -e "test-requirements.txt" ]; then
sed -i -e "/^ops[ ><=]/d" -e "/canonical\/operator/d" -e "/#egg=ops/d" test-requirements.txt
echo -e "\ngit+$GITHUB_SERVER_URL/$GITHUB_REPOSITORY@$GITHUB_SHA#egg=ops" >> test-requirements.txt
echo -e "\n${ops_wheel}" >> test-requirements.txt
sed -i -e "/^ops-scenario[ ><=]/d" -e "/^ops\[testing\][ ><=]/d" test-requirements.txt
echo -e "\ngit+$GITHUB_SERVER_URL/$GITHUB_REPOSITORY@$GITHUB_SHA#egg=ops-scenario&subdirectory=testing" >> test-requirements.txt
echo -e "\n${ops_scenario_wheel}" >> test-requirements.txt
fi
if [ -e "requirements-charmcraft.txt" ]; then
sed -i -e "/^ops[ ><=]/d" -e "/canonical\/operator/d" -e "/#egg=ops/d" requirements-charmcraft.txt
echo -e "\ngit+$GITHUB_SERVER_URL/$GITHUB_REPOSITORY@$GITHUB_SHA#egg=ops" >> requirements-charmcraft.txt
echo -e "\n${ops_wheel}" >> requirements-charmcraft.txt
sed -i -e "/^ops-scenario[ ><=]/d" -e "/^ops\[testing\][ ><=]/d" requirements-charmcraft.txt
echo -e "\ngit+$GITHUB_SERVER_URL/$GITHUB_REPOSITORY@$GITHUB_SHA#egg=ops-scenario&subdirectory=testing" >> requirements-charmcraft.txt
echo -e "\n${ops_scenario_wheel}" >> requirements-charmcraft.txt
fi
if [ -e "requirements.txt" ]; then
sed -i -e "/^ops[ ><=]/d" -e "/canonical\/operator/d" -e "/#egg=ops/d" requirements.txt
echo -e "\ngit+$GITHUB_SERVER_URL/$GITHUB_REPOSITORY@$GITHUB_SHA#egg=ops" >> requirements.txt
echo -e "\n${ops_wheel}" >> requirements.txt
sed -i -e "/^ops-scenario[ ><=]/d" -e "/^ops\[testing\][ ><=]/d" requirements.txt
echo -e "\ngit+$GITHUB_SERVER_URL/$GITHUB_REPOSITORY@$GITHUB_SHA#egg=ops-scenario&subdirectory=testing" >> requirements.txt
echo -e "\n${ops_scenario_wheel}" >> requirements.txt
elif [ -e "poetry.lock" ]; then
poetry add git+$GITHUB_SERVER_URL/$GITHUB_REPOSITORY@$GITHUB_SHA --lock
poetry add git+$GITHUB_SERVER_URL/$GITHUB_REPOSITORY@$GITHUB_SHA#subdirectory=testing --lock
poetry add "${ops_wheel}" --lock
poetry add "${ops_scenario_wheel}" --lock
elif [ -e "uv.lock" ]; then
uv add --frozen --raw-sources git+$GITHUB_SERVER_URL/$GITHUB_REPOSITORY@$GITHUB_SHA#subdirectory=testing
uv add --frozen --raw-sources git+$GITHUB_SERVER_URL/$GITHUB_REPOSITORY@$GITHUB_SHA
uv add --frozen --raw-sources "${ops_wheel}"
uv add --frozen --raw-sources "${ops_scenario_wheel}"
uv lock
else
echo "Error: No requirements.txt or poetry.lock or uv.lock file found"
exit 1
fi

- name: Show installed ops package versions
working-directory: ${{ matrix.charm-root }}
run: |
echo "=== Wheel files downloaded ==="
ls -lh ../operator-wheels/*.whl || echo "No wheel files found"
echo ""
echo "=== Updated requirements files ==="
[ -f requirements.txt ] && (echo "requirements.txt:" && tail -n 10 requirements.txt) || echo "No requirements.txt"
[ -f test-requirements.txt ] && (echo "test-requirements.txt:" && tail -n 10 test-requirements.txt) || echo "No test-requirements.txt"
echo ""
echo "=== Installed ops package version (after tox install) will be checked during test run ==="

- name: Install dependencies
id: deps
run: pip install tox~=4.2
Expand All @@ -239,6 +264,13 @@ jobs:
working-directory: ${{ matrix.charm-root }}
run: tox -vve unit

- name: Show all installed dependencies in test environment
if: ${{ !cancelled() && steps.deps.outcome == 'success' }}
working-directory: ${{ matrix.charm-root }}
run: |
echo "=== All installed packages in unit test environment ==="
uv pip freeze || .tox/unit/bin/pip list || echo "Could not list packages from test environment"

- name: Check for tox static environment
id: has-static
if: ${{ !cancelled() && steps.deps.outcome == 'success' }}
Expand All @@ -259,6 +291,7 @@ jobs:

charmcraft-profile-tests:
runs-on: ubuntu-latest
needs: build-wheels
strategy:
fail-fast: false
matrix:
Expand All @@ -274,22 +307,31 @@ jobs:
- name: Charmcraft init
run: charmcraft init --profile=${{ matrix.profile }} --author=charm-tech

- name: Download operator wheels
uses: actions/download-artifact@v5
with:
name: ${{ needs.build-wheels.outputs.artifact-name }}
path: operator-wheels

- name: Install dependencies
run: pip install tox~=4.2 uv~=0.9 tox-uv~=1.29

- name: Update 'ops' and 'ops-scenario' dependencies in test charm to latest
run: |
set -xueo pipefail
# Get the absolute paths to the wheels
ops_wheel="$(ls operator-wheels/ops-[0-9]*.whl)"
ops_scenario_wheel="$(ls operator-wheels/ops_scenario-*.whl)"
if [ -e "requirements.txt" ]; then
sed -i -e "/^ops[ ><=]/d" -e "/canonical\/operator/d" -e "/#egg=ops/d" requirements.txt
sed -i -e "/^ops-scenario[ ><=]/d" -e "/^ops\[testing\][ ><=]/d" requirements.txt
echo -e "\ngit+$GITHUB_SERVER_URL/$GITHUB_REPOSITORY@$GITHUB_SHA#egg=ops" >> requirements.txt
echo -e "\ngit+$GITHUB_SERVER_URL/$GITHUB_REPOSITORY@$GITHUB_SHA#egg=ops-scenario&subdirectory=testing" >> requirements.txt
echo -e "\n${ops_wheel}" >> requirements.txt
echo -e "\n${ops_scenario_wheel}" >> requirements.txt
elif [ -e "uv.lock" ]; then
uv remove ops[testing] --group unit --frozen
uv remove ops --frozen
uv add git+$GITHUB_SERVER_URL/$GITHUB_REPOSITORY@$GITHUB_SHA#subdirectory=testing --group unit --raw-sources --prerelease=if-necessary-or-explicit
uv add git+$GITHUB_SERVER_URL/$GITHUB_REPOSITORY@$GITHUB_SHA --raw-sources --prerelease=if-necessary-or-explicit
uv add "${ops_wheel}" --raw-sources --prerelease=if-necessary-or-explicit
uv add "${ops_scenario_wheel}" --group unit --raw-sources --prerelease=if-necessary-or-explicit
else
echo "Error: no uv.lock file found"
exit 1
Expand Down
Loading