From 632a3e2539ea934812a01cf97ec212c5d8dd7a44 Mon Sep 17 00:00:00 2001 From: Tiexin Guo Date: Thu, 14 Nov 2024 09:14:19 +0800 Subject: [PATCH] ci: dynamic matrix for interfaces test (#196) * ci: dynamic matrix for interfaces * chore: update job name and use jq --------- Signed-off-by: Tiexin Guo --- .github/workflows/matrix-tests.yaml | 23 +++++++++++++++++++---- run_matrix.py | 7 +++++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/.github/workflows/matrix-tests.yaml b/.github/workflows/matrix-tests.yaml index b594d8e9..82128a27 100644 --- a/.github/workflows/matrix-tests.yaml +++ b/.github/workflows/matrix-tests.yaml @@ -6,14 +6,29 @@ on: workflow_dispatch: jobs: - main: + set-matrix: runs-on: ubuntu-latest - name: Run the interface tests on all registered charms + outputs: + matrix_values: ${{ steps.set-matrix.outputs.matrix_values }} steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 1 + - name: Set matrix values + id: set-matrix + run: | + interfaces=$(find interfaces -mindepth 1 -maxdepth 1 -type d -not -name "__template__" -printf '%f\n' | jq --raw-input . | jq -c --slurp .) + echo "matrix_values=${interfaces}" >> $GITHUB_OUTPUT + + main: + name: ${{ matrix.interface }} + needs: set-matrix + runs-on: ubuntu-latest + strategy: + matrix: + interface: ${{ fromJSON(needs.set-matrix.outputs.matrix_values) }} + steps: - name: Set up python uses: actions/setup-python@v4 with: @@ -23,4 +38,4 @@ jobs: - name: Run tests env: GITHUB_TOKEN: ${{ secrets.GH_TOKEN_WITH_TEAM }} - run: tox -e run-interface-test-matrix + run: tox -e run-interface-test-matrix -- --include ${{ matrix.interface }} diff --git a/run_matrix.py b/run_matrix.py index f1716101..2e039739 100644 --- a/run_matrix.py +++ b/run_matrix.py @@ -311,6 +311,7 @@ def run_interface_tests( keep_cache: bool = False, ) -> "_ResultsPerInterface": """Run the tests for the specified interfaces, defaulting to all.""" + failed = False if not keep_cache: _clean() test_results = {} @@ -326,6 +327,7 @@ def run_interface_tests( for version, tests_per_role in version_to_roles.items(): maintainer = tests_per_role.get("maintainer") if maintainer and test_failed(results_per_version[version]): + failed = True create_issue( interface, version, results_per_version[version], maintainer ) @@ -333,7 +335,7 @@ def run_interface_tests( if not collected: logging.warning("No tests collected.") - return test_results + return test_results, failed def test_failed(role_result: "_ResultsPerRole"): @@ -452,7 +454,8 @@ def pprint_interface_test_results(test_results: dict): ) args = parser.parse_args() - result = run_interface_tests( + result, failed = run_interface_tests( Path("."), args.repo, args.branch, args.include, args.keep_cache ) pprint_interface_test_results(result) + exit(1) if failed else exit(0)