|
2 | 2 | name: Run tests
|
3 | 3 | on:
|
4 | 4 | pull_request:
|
| 5 | + types: [opened, synchronize, reopened, ready_for_review] |
5 | 6 | branches:
|
6 | 7 | - main
|
7 | 8 | paths-ignore:
|
|
14 | 15 | - main
|
15 | 16 |
|
16 | 17 | concurrency:
|
17 |
| - group: ${{ github.ref }} |
| 18 | + group: ${{ github.workflow }}-${{ github.ref }} |
18 | 19 | cancel-in-progress: true
|
19 | 20 |
|
20 | 21 | jobs:
|
| 22 | + set_matrix: |
| 23 | + name: Set test matrix |
| 24 | + runs-on: ubuntu-latest |
| 25 | + outputs: |
| 26 | + matrix: ${{ steps.set-matrix.outputs.matrix }} |
| 27 | + latest_matlab_version: ${{ steps.set-matrix.outputs.latest_matlab_version }} |
| 28 | + steps: |
| 29 | + - name: Check out repository |
| 30 | + uses: actions/checkout@v4 |
| 31 | + |
| 32 | + - name: Set matrix |
| 33 | + id: set-matrix |
| 34 | + run: | |
| 35 | + # Load the matrix configuration and extract latest version |
| 36 | + latest_matlab_version=$(yq '.[-1].matlab-version' .github/workflows/configurations/matlab_release_matrix_strategy.yml) |
| 37 | + |
| 38 | + # Conditionally define the MATLAB test matrix based on the PR type. |
| 39 | + # Draft pull requests are only tested against the latest MATLAB release, |
| 40 | + # while non-draft PRs and push events are tested against all configured releases. |
| 41 | + if [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.draft }}" == "true" ]]; then |
| 42 | + echo "Draft PR detected - using latest MATLAB version only" |
| 43 | + # Create matrix with only the latest entry |
| 44 | + matrix=$(yq -o=json '.[-1:] | {"include": .}' .github/workflows/configurations/matlab_release_matrix_strategy.yml | tr -d '\n') |
| 45 | + else |
| 46 | + echo "Non-draft PR or push event - using full matrix" |
| 47 | + # Create matrix with all entries |
| 48 | + matrix=$(yq -o=json '{"include": .}' .github/workflows/configurations/matlab_release_matrix_strategy.yml | tr -d '\n') |
| 49 | + fi |
| 50 | + |
| 51 | + # Assign `matrix` and `latest_matlab_version` as outputs of this job |
| 52 | + echo "matrix=$matrix" >> $GITHUB_OUTPUT |
| 53 | + echo "latest_matlab_version=$latest_matlab_version" >> $GITHUB_OUTPUT |
| 54 | +
|
21 | 55 | run_tests:
|
22 | 56 | name: Run MATLAB tests (${{ matrix.matlab-version }})
|
| 57 | + needs: set_matrix |
23 | 58 | runs-on: ubuntu-latest
|
| 59 | + env: |
| 60 | + USE_CACHE: ${{ github.event_name == 'pull_request' && github.event.pull_request.draft == true }} |
24 | 61 | strategy:
|
25 | 62 | fail-fast: false
|
26 |
| - matrix: |
27 |
| - include: |
28 |
| - - matlab-version: R2021a |
29 |
| - python-version: '3.9' |
30 |
| - skip-pynwb-compatibilty-test-for-tutorial: '1' |
31 |
| - - matlab-version: R2021b |
32 |
| - python-version: '3.9' |
33 |
| - skip-pynwb-compatibilty-test-for-tutorial: '1' |
34 |
| - - matlab-version: R2022a |
35 |
| - python-version: '3.9' |
36 |
| - skip-pynwb-compatibilty-test-for-tutorial: '0' |
37 |
| - - matlab-version: R2022b |
38 |
| - python-version: '3.9' |
39 |
| - skip-pynwb-compatibilty-test-for-tutorial: '0' |
40 |
| - - matlab-version: R2023a |
41 |
| - python-version: '3.10' |
42 |
| - skip-pynwb-compatibilty-test-for-tutorial: '0' |
43 |
| - - matlab-version: R2023b |
44 |
| - python-version: '3.10' |
45 |
| - skip-pynwb-compatibilty-test-for-tutorial: '0' |
46 |
| - - matlab-version: R2024a |
47 |
| - python-version: '3.11' |
48 |
| - skip-pynwb-compatibilty-test-for-tutorial: '0' |
49 |
| - - matlab-version: R2024b |
50 |
| - python-version: '3.11' |
51 |
| - skip-pynwb-compatibilty-test-for-tutorial: '0' |
| 63 | + matrix: ${{ fromJSON(needs.set_matrix.outputs.matrix) }} |
52 | 64 | steps:
|
53 | 65 | - name: Check out repository
|
54 | 66 | uses: actions/checkout@v4
|
|
70 | 82 | uses: matlab-actions/setup-matlab@v2
|
71 | 83 | with:
|
72 | 84 | release: ${{ matrix.matlab-version }}
|
| 85 | + cache: ${{ env.USE_CACHE }} |
73 | 86 |
|
74 | 87 | - name: Run tests
|
75 | 88 | uses: matlab-actions/run-command@v2
|
|
90 | 103 | retention-days: 1
|
91 | 104 |
|
92 | 105 | - name: Upload coverage results
|
93 |
| - if: always() |
| 106 | + if: always() && matrix.matlab-version == needs.set_matrix.outputs.latest_matlab_version |
94 | 107 | uses: actions/upload-artifact@v4
|
95 | 108 | with:
|
96 | 109 | name: test-coverage-${{ matrix.matlab-version }}
|
@@ -119,15 +132,15 @@ jobs:
|
119 | 132 | publish_coverage:
|
120 | 133 | name: Publish Cobertura test coverage
|
121 | 134 | runs-on: ubuntu-latest
|
122 |
| - needs: [run_tests] |
| 135 | + needs: [run_tests, set_matrix] |
123 | 136 | steps:
|
124 | 137 | - name: Check out repository
|
125 | 138 | uses: actions/checkout@v4
|
126 | 139 |
|
127 | 140 | - name: Retrieve code coverage files
|
128 | 141 | uses: actions/download-artifact@v4
|
129 | 142 | with:
|
130 |
| - name: test-coverage-R2024b |
| 143 | + name: test-coverage-${{ needs.set_matrix.outputs.latest_matlab_version }} |
131 | 144 |
|
132 | 145 | - name: Publish on coverage results on Codecov
|
133 | 146 | uses: codecov/codecov-action@v4
|
|
0 commit comments