Skip to content

Commit b4c35f2

Browse files
committed
Refactor CI workflow to generate test matrix dynamically
Replaced static matrix definition in PHPUnit job with a dynamic matrix generated by a new `matrix-generator` job. This improves flexibility and scalability by dynamically including combinations of PHP versions, operating systems, and dependency configurations based on inputs.
1 parent 464b30c commit b4c35f2

File tree

1 file changed

+62
-24
lines changed

1 file changed

+62
-24
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 62 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,72 @@ env:
2828
COMPOSER_UPDATE_FLAGS: ""
2929

3030
jobs:
31+
# Generate matrix dynamically based on inputs
32+
matrix-generator:
33+
name: Generate Test Matrix
34+
runs-on: ubuntu-latest
35+
outputs:
36+
matrix: ${{ steps.generate.outputs.matrix }}
37+
steps:
38+
- name: Generate matrix
39+
id: generate
40+
uses: actions/github-script@v7
41+
with:
42+
script: |
43+
const oldStable = ${{ inputs.old_stable }};
44+
const currentStable = "${{ inputs.current_stable }}";
45+
46+
let matrix = {
47+
include: []
48+
};
49+
50+
// Add old stable versions if provided
51+
if (oldStable.length > 0) {
52+
for (const version of oldStable) {
53+
matrix.include.push({
54+
"php-version": version,
55+
"os": "ubuntu-latest",
56+
"dependencies": "highest",
57+
"experimental": false
58+
});
59+
matrix.include.push({
60+
"php-version": version,
61+
"os": "ubuntu-latest",
62+
"dependencies": "lowest",
63+
"experimental": false
64+
});
65+
}
66+
}
67+
68+
// Always add current stable tests
69+
matrix.include.push({
70+
"php-version": currentStable,
71+
"os": "windows-latest",
72+
"dependencies": "highest",
73+
"experimental": false
74+
});
75+
matrix.include.push({
76+
"php-version": currentStable,
77+
"os": "ubuntu-latest",
78+
"dependencies": "highest",
79+
"experimental": false
80+
});
81+
matrix.include.push({
82+
"php-version": currentStable,
83+
"os": "ubuntu-latest",
84+
"dependencies": "lowest",
85+
"experimental": false
86+
});
87+
88+
core.setOutput('matrix', JSON.stringify(matrix));
89+
3190
phpunit:
32-
name: PHPUnit
91+
name: PHPUnit - PHP ${{ matrix.php-version }} (${{ matrix.os }}, ${{ matrix.dependencies }})
92+
needs: matrix-generator
3393
runs-on: ${{ matrix.os }}
3494
strategy:
3595
fail-fast: false
36-
matrix:
37-
# Only include old_stable versions if they are provided
38-
php-version: ${{ fromJson(inputs.old_stable || '[]') }}
39-
dependencies: [highest, lowest]
40-
os: [ubuntu-latest]
41-
experimental: [false]
42-
# Exclude combinations when old_stable is empty
43-
exclude:
44-
- php-version: null
45-
include:
46-
# Always include current_stable tests
47-
- php-version: ${{ inputs.current_stable }}
48-
os: windows-latest
49-
dependencies: highest
50-
experimental: false
51-
- php-version: ${{ inputs.current_stable }}
52-
os: ubuntu-latest
53-
dependencies: highest
54-
experimental: false
55-
- php-version: ${{ inputs.current_stable }}
56-
os: ubuntu-latest
57-
dependencies: lowest
58-
experimental: false
96+
matrix: ${{ fromJson(needs.matrix-generator.outputs.matrix) }}
5997

6098
continue-on-error: ${{ matrix.experimental }}
6199

0 commit comments

Comments
 (0)