diff --git a/.github/scripts/test-matrix.py b/.github/scripts/test-matrix.py new file mode 100644 index 00000000..c43204ec --- /dev/null +++ b/.github/scripts/test-matrix.py @@ -0,0 +1,33 @@ +import os +import json + +TEST_DIR = "bin/icp-cli/tests" + +MACOS_TESTS = ["hello_tests"] + +def test_names(): + all_files = os.listdir(TEST_DIR) + rust_files = filter(lambda f: f.endswith(".rs"), all_files) + return [f"{filename[:-3]}" for filename in rust_files] + +include = [] +for test in test_names(): + # Ubuntu: run everything + include.append({ + "test": test, + "os": "ubuntu-22.04" + }) + + # macOS: only run selected tests + if test in MACOS_TESTS: + include.append({ + "test": test, + "os": "macos-13" + }) + + +matrix = { + "include": include, +} + +print(json.dumps(matrix)) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index aa9c5b5f..a4cf6093 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,15 +7,22 @@ on: pull_request: jobs: + discover: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - uses: actions/checkout@v4 + - id: set-matrix + run: echo "matrix=$(python3 .github/scripts/test-matrix.py)" >> $GITHUB_OUTPUT + test: name: ${{ matrix.test }} on ${{ matrix.os }} + needs: discover runs-on: ${{ matrix.os }} strategy: fail-fast: false - matrix: - os: [ubuntu-latest, macos-latest] - test: - - hello_tests + matrix: ${{fromJson(needs.discover.outputs.matrix)}} steps: - uses: actions/checkout@v4