Skip to content

Commit

Permalink
Add conditional logic to allow Tox and Make (#252)
Browse files Browse the repository at this point in the history
* Conditional logic to allow Tox and Make
* New run-task custom action for charm PR workflows

---------

Signed-off-by: Michael Thamm <[email protected]>
  • Loading branch information
MichaelThamm authored Dec 19, 2024
1 parent c902fd4 commit fa49daf
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 31 deletions.
42 changes: 42 additions & 0 deletions .github/actions/charm-run-task/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: 'Task Runner'
description: 'Run tests for a charm'
inputs:
charm-path:
type: string
description: 'Path to the charm'
required: true
test-type:
type: choice
description: 'Test type for the task runner to execute'
required: true
options:
- lint
- static
- unit
- scenario
- integration

runs:
using: 'composite'
steps:
- name: Run test
shell: bash
run: |
cd ${{ inputs.charm-path }}
if [ -f tox.ini ]; then # Run Tox
if [ "${{ inputs.test-type }}" == "static" ]; then
tox -vve "static-lib"
tox -vve "static-charm"
else
tox -vve "${{ inputs.test-type }}"
fi
elif [ -f Makefile ]; then # Run Make
if grep -q -E "^\s*${{ inputs.test-type }}:" Makefile; then
make "${{ inputs.test-type }}"
else
echo "Warning: Make target does not exist -> ${{ inputs.test-type }}."
fi
else
echo "Error: Taskrunner file not found."
exit 1
fi
13 changes: 9 additions & 4 deletions .github/workflows/_charm-linting.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

jobs:
lint:
name: Lint
name: Lint tests
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -21,6 +21,11 @@ jobs:
with:
python-version: 3.8
- name: Install dependencies
run: python3 -m pip install tox
- name: Run linters
run: cd ${{ inputs.charm-path }} && tox -vve lint
run: |
python3 -m pip install tox
sudo snap install --classic astral-uv
- name: Run tests
uses: canonical/observability/.github/actions/charm-run-task@main
with:
charm-path: ${{ inputs.charm-path }}
test-type: lint
31 changes: 10 additions & 21 deletions .github/workflows/_charm-static-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,24 @@ on:
required: false

jobs:
static-lib:
name: Static Analysis of Libs
static:
name: Static analysis (lib and charm)
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Set up Python 3.8
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.8
- name: Install dependencies
run: python3 -m pip install tox
- name: Run static analysis for /lib for 3.8
run: cd ${{ inputs.charm-path }} && tox -vve static-lib
static-charm:
name: Static Analysis of Charm
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Set up Python 3.8
uses: actions/setup-python@v4
run: |
python3 -m pip install tox
sudo snap install --classic astral-uv
- name: Run tests
uses: canonical/observability/.github/actions/charm-run-task@main
with:
python-version: 3.8
- name: Install dependencies
run: python3 -m pip install tox
- name: Run static analysis (charm)
run: cd ${{ inputs.charm-path }} && tox -vve static-charm
charm-path: ${{ inputs.charm-path }}
test-type: static
10 changes: 8 additions & 2 deletions .github/workflows/_charm-tests-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,14 @@ jobs:
microk8s-group: snap_microk8s
microk8s-addons: "hostpath-storage dns metallb:${{ inputs.ip-range || steps.ip_range.outputs.ip_range }}"
charmcraft-channel: "${{ inputs.charmcraft-channel }}"
- name: Run integration tests
run: cd ${{ inputs.charm-path }} && tox -vve integration
- name: Install dependencies
run: |
sudo snap install --classic astral-uv
- name: Run tests
uses: canonical/observability/.github/actions/charm-run-task@main
with:
charm-path: ${{ inputs.charm-path }}
test-type: integration
- name: Dump logs
if: failure()
uses: canonical/charming-actions/dump-logs@main
9 changes: 7 additions & 2 deletions .github/workflows/_charm-tests-scenario.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ jobs:
with:
python-version: 3.8
- name: Install dependencies
run: python -m pip install tox
run: |
python -m pip install tox
sudo snap install --classic astral-uv
- name: Run tests
run: cd ${{ inputs.charm-path }} && tox -e scenario
uses: canonical/observability/.github/actions/charm-run-task@main
with:
charm-path: ${{ inputs.charm-path }}
test-type: scenario
9 changes: 7 additions & 2 deletions .github/workflows/_charm-tests-unit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ jobs:
with:
python-version: 3.8
- name: Install dependencies
run: python -m pip install tox
run: |
python -m pip install tox
sudo snap install --classic astral-uv
- name: Run tests
run: cd ${{ inputs.charm-path }} && tox -e unit
uses: canonical/observability/.github/actions/charm-run-task@main
with:
charm-path: ${{ inputs.charm-path }}
test-type: unit

0 comments on commit fa49daf

Please sign in to comment.