Skip to content

Commit

Permalink
ci: dynamic matrix for interfaces test (#196)
Browse files Browse the repository at this point in the history
* ci: dynamic matrix for interfaces

* chore: update job name and use jq

---------

Signed-off-by: Tiexin Guo <[email protected]>
  • Loading branch information
IronCore864 authored Nov 14, 2024
1 parent 53defe5 commit 632a3e2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
23 changes: 19 additions & 4 deletions .github/workflows/matrix-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 }}
7 changes: 5 additions & 2 deletions run_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand All @@ -326,14 +327,15 @@ 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
)

if not collected:
logging.warning("No tests collected.")

return test_results
return test_results, failed


def test_failed(role_result: "_ResultsPerRole"):
Expand Down Expand Up @@ -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)

0 comments on commit 632a3e2

Please sign in to comment.