diff --git a/.github/actions/charm-run-task/action.yaml b/.github/actions/charm-run-task/action.yaml new file mode 100644 index 0000000..a54602b --- /dev/null +++ b/.github/actions/charm-run-task/action.yaml @@ -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 \ No newline at end of file diff --git a/.github/workflows/_charm-linting.yaml b/.github/workflows/_charm-linting.yaml index 12b6da3..4b4612b 100644 --- a/.github/workflows/_charm-linting.yaml +++ b/.github/workflows/_charm-linting.yaml @@ -9,7 +9,7 @@ on: jobs: lint: - name: Lint + name: Lint tests runs-on: ubuntu-latest steps: - name: Checkout @@ -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 diff --git a/.github/workflows/_charm-static-analysis.yaml b/.github/workflows/_charm-static-analysis.yaml index 71adc33..949c277 100644 --- a/.github/workflows/_charm-static-analysis.yaml +++ b/.github/workflows/_charm-static-analysis.yaml @@ -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 diff --git a/.github/workflows/_charm-tests-integration.yaml b/.github/workflows/_charm-tests-integration.yaml index 4ee7b81..cf5292a 100644 --- a/.github/workflows/_charm-tests-integration.yaml +++ b/.github/workflows/_charm-tests-integration.yaml @@ -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 diff --git a/.github/workflows/_charm-tests-scenario.yaml b/.github/workflows/_charm-tests-scenario.yaml index f3eb387..a281547 100644 --- a/.github/workflows/_charm-tests-scenario.yaml +++ b/.github/workflows/_charm-tests-scenario.yaml @@ -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 diff --git a/.github/workflows/_charm-tests-unit.yaml b/.github/workflows/_charm-tests-unit.yaml index 863bfe9..856e593 100644 --- a/.github/workflows/_charm-tests-unit.yaml +++ b/.github/workflows/_charm-tests-unit.yaml @@ -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