Skip to content

Commit 75fb444

Browse files
committed
Generate matrix (#31)
* feat: add generating of matrix
1 parent adb3d11 commit 75fb444

File tree

2 files changed

+143
-211
lines changed

2 files changed

+143
-211
lines changed

.github/workflows/build-docker-images.yaml

Lines changed: 20 additions & 211 deletions
Original file line numberDiff line numberDiff line change
@@ -83,222 +83,31 @@ jobs:
8383
docker push "${{ env.DOCKER_REPOSITORY }}-base:${{ matrix.php-version }}-${{ matrix.flavour }}"
8484
8585
86+
generate-matrix:
87+
runs-on: ubuntu-latest
88+
outputs:
89+
matrix: ${{ steps.generate-matrix.outputs.matrix }}
90+
steps:
91+
- name: Clone
92+
uses: actions/checkout@v3
93+
- uses: actions/setup-node@v3
94+
with:
95+
node-version: '18'
96+
- name: Generate matrix
97+
id: generate-matrix
98+
run: |
99+
matrix=$(node bin/generate-matrix.js)
100+
echo "matrix=${matrix}" >> $GITHUB_OUTPUT
101+
86102
build:
87-
needs: build-base
103+
needs:
104+
- build-base
105+
- generate-matrix
88106
runs-on: ubuntu-latest
89107

90108
strategy:
91109
fail-fast: false
92-
matrix:
93-
include:
94-
- shopware-version: v6.4.6.1
95-
php-version: "8.1"
96-
flavour: alpine
97-
template: https://github.com/shopware/production
98-
- shopware-version: v6.4.7.0
99-
php-version: "8.1"
100-
flavour: alpine
101-
template: https://github.com/shopware/production
102-
- shopware-version: v6.4.8.2
103-
php-version: "8.1"
104-
flavour: alpine
105-
template: https://github.com/shopware/production
106-
- shopware-version: v6.4.9.0
107-
php-version: "8.1"
108-
flavour: alpine
109-
template: https://github.com/shopware/production
110-
- shopware-version: v6.4.10.0
111-
php-version: "8.1"
112-
flavour: alpine
113-
template: https://github.com/shopware/production
114-
- shopware-version: v6.4.11.1
115-
php-version: "8.1"
116-
flavour: alpine
117-
template: https://github.com/shopware/production
118-
- shopware-version: v6.4.12.0
119-
php-version: "8.1"
120-
flavour: alpine
121-
template: https://github.com/shopware/production
122-
- shopware-version: v6.4.13.0
123-
php-version: "8.1"
124-
flavour: alpine
125-
template: https://github.com/shopware/production
126-
- shopware-version: v6.4.14.0
127-
php-version: "8.1"
128-
flavour: alpine
129-
template: https://github.com/shopware/production
130-
- shopware-version: v6.4.15.1
131-
php-version: "8.1"
132-
flavour: alpine
133-
template: https://github.com/shopware/production
134-
- shopware-version: v6.4.16.1
135-
php-version: "8.1"
136-
flavour: alpine
137-
template: https://github.com/shopware/production
138-
- shopware-version: v6.4.17.1
139-
php-version: "8.1"
140-
flavour: alpine
141-
template: https://github.com/shopware/production
142-
- shopware-version: v6.4.18.1
143-
php-version: "8.1"
144-
flavour: alpine
145-
template: https://github.com/shopware/production
146-
- shopware-version: v6.4.19.0
147-
php-version: "8.1"
148-
flavour: alpine
149-
template: https://github.com/shopware/production
150-
- shopware-version: v6.4.20.2
151-
php-version: "8.1"
152-
flavour: alpine
153-
template: https://github.com/shopware/production
154-
- shopware-version: v6.5.0.0
155-
php-version: "8.1"
156-
flavour: alpine
157-
template: https://github.com/shopware/shopware
158-
- shopware-version: v6.5.1.1
159-
php-version: "8.1"
160-
flavour: alpine
161-
template: https://github.com/shopware/shopware
162-
- shopware-version: v6.5.2.1
163-
php-version: "8.1"
164-
flavour: alpine
165-
template: https://github.com/shopware/shopware
166-
- shopware-version: v6.5.3.3
167-
php-version: "8.1"
168-
flavour: alpine
169-
template: https://github.com/shopware/shopware
170-
- shopware-version: v6.5.4.1
171-
php-version: "8.1"
172-
flavour: alpine
173-
template: https://github.com/shopware/shopware
174-
- shopware-version: v6.5.5.2
175-
php-version: "8.1"
176-
flavour: alpine
177-
template: https://github.com/shopware/shopware
178-
- shopware-version: v6.5.6.1
179-
php-version: "8.1"
180-
flavour: alpine
181-
template: https://github.com/shopware/shopware
182-
- shopware-version: v6.5.7.3
183-
php-version: "8.1"
184-
flavour: alpine
185-
template: https://github.com/shopware/shopware
186-
- shopware-version: 6.4
187-
php-version: "8.1"
188-
flavour: alpine
189-
template: https://github.com/shopware/shopware
190-
- shopware-version: 6.5.x
191-
php-version: "8.1"
192-
flavour: alpine
193-
template: https://github.com/shopware/shopware
194-
- shopware-version: trunk
195-
php-version: "8.2"
196-
flavour: alpine
197-
template: https://github.com/shopware/shopware
198-
- shopware-version: v6.4.6.1
199-
php-version: "8.1"
200-
flavour: bullseye
201-
template: https://github.com/shopware/production
202-
- shopware-version: v6.4.7.0
203-
php-version: "8.1"
204-
flavour: bullseye
205-
template: https://github.com/shopware/production
206-
- shopware-version: v6.4.8.2
207-
php-version: "8.1"
208-
flavour: bullseye
209-
template: https://github.com/shopware/production
210-
- shopware-version: v6.4.9.0
211-
php-version: "8.1"
212-
flavour: bullseye
213-
template: https://github.com/shopware/production
214-
- shopware-version: v6.4.10.0
215-
php-version: "8.1"
216-
flavour: bullseye
217-
template: https://github.com/shopware/production
218-
- shopware-version: v6.4.11.1
219-
php-version: "8.1"
220-
flavour: bullseye
221-
template: https://github.com/shopware/production
222-
- shopware-version: v6.4.12.0
223-
php-version: "8.1"
224-
flavour: bullseye
225-
template: https://github.com/shopware/production
226-
- shopware-version: v6.4.13.0
227-
php-version: "8.1"
228-
flavour: bullseye
229-
template: https://github.com/shopware/production
230-
- shopware-version: v6.4.14.0
231-
php-version: "8.1"
232-
flavour: bullseye
233-
template: https://github.com/shopware/production
234-
- shopware-version: v6.4.15.1
235-
php-version: "8.1"
236-
flavour: bullseye
237-
template: https://github.com/shopware/production
238-
- shopware-version: v6.4.16.1
239-
php-version: "8.1"
240-
flavour: bullseye
241-
template: https://github.com/shopware/production
242-
- shopware-version: v6.4.17.1
243-
php-version: "8.1"
244-
flavour: bullseye
245-
template: https://github.com/shopware/production
246-
- shopware-version: v6.4.18.1
247-
php-version: "8.1"
248-
flavour: bullseye
249-
template: https://github.com/shopware/production
250-
- shopware-version: v6.4.19.0
251-
php-version: "8.1"
252-
flavour: bullseye
253-
template: https://github.com/shopware/production
254-
- shopware-version: v6.4.20.2
255-
php-version: "8.1"
256-
flavour: bullseye
257-
template: https://github.com/shopware/production
258-
- shopware-version: v6.5.0.0
259-
php-version: "8.1"
260-
flavour: bullseye
261-
template: https://github.com/shopware/shopware
262-
- shopware-version: v6.5.1.1
263-
php-version: "8.1"
264-
flavour: bullseye
265-
template: https://github.com/shopware/shopware
266-
- shopware-version: v6.5.2.1
267-
php-version: "8.1"
268-
flavour: bullseye
269-
template: https://github.com/shopware/shopware
270-
- shopware-version: v6.5.3.3
271-
php-version: "8.1"
272-
flavour: bullseye
273-
template: https://github.com/shopware/shopware
274-
- shopware-version: v6.5.4.1
275-
php-version: "8.1"
276-
flavour: bullseye
277-
template: https://github.com/shopware/shopware
278-
- shopware-version: v6.5.5.2
279-
php-version: "8.1"
280-
flavour: bullseye
281-
template: https://github.com/shopware/shopware
282-
- shopware-version: v6.5.6.1
283-
php-version: "8.1"
284-
flavour: bullseye
285-
template: https://github.com/shopware/shopware
286-
- shopware-version: v6.5.7.3
287-
php-version: "8.1"
288-
flavour: bullseye
289-
template: https://github.com/shopware/shopware
290-
- shopware-version: 6.4
291-
php-version: "8.1"
292-
flavour: bullseye
293-
template: https://github.com/shopware/shopware
294-
- shopware-version: 6.5.x
295-
php-version: "8.1"
296-
flavour: bullseye
297-
template: https://github.com/shopware/shopware
298-
- shopware-version: trunk
299-
php-version: "8.2"
300-
flavour: bullseye
301-
template: https://github.com/shopware/shopware
110+
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
302111

303112
steps:
304113
- name: Clone

bin/generate-matrix.js

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#!/usr/bin/env node
2+
3+
const FLAVORS = [
4+
"alpine",
5+
"bullseye",
6+
];
7+
8+
/**
9+
* Hardcode some versions, because e.g. there are no tags for them.
10+
*/
11+
const HARDCODED_MATRIX = [
12+
{
13+
"shopware-version": "6.4",
14+
"php-version": "8.1",
15+
"template": "https://github.com/shopware/shopware",
16+
},
17+
{
18+
"shopware-version": "6.5.x",
19+
"php-version": "8.1",
20+
"template": "https://github.com/shopware/shopware",
21+
},
22+
{
23+
"shopware-version": "trunk",
24+
"php-version": "8.2",
25+
"template": "https://github.com/shopware/shopware",
26+
},
27+
];
28+
29+
const loadShopwarePHPVersions = async () => {
30+
const response = await fetch("https://github.com/raw/FriendsOfShopware/shopware-static-data/main/data/all-supported-php-versions-by-shopware-version.json")
31+
return await response.json();
32+
}
33+
34+
const loadMinPHPVersion = async () => {
35+
const response = await fetch("https://php.watch/api/v1/versions/secure")
36+
const result = await response.json();
37+
38+
const [firstVersion] = Object.values(result.data);
39+
40+
return firstVersion.name;
41+
}
42+
43+
const parseMinorVersion = (version) => {
44+
const parts = version.match(/[0.9]*.\.([0-9]*)\..*/);
45+
if (parts.length < 2) {
46+
throw new Error("Unexpected version format: " + version);
47+
}
48+
49+
return parseInt(parts[1], 10);
50+
}
51+
52+
const getTemplate = (version) => {
53+
const minor = parseMinorVersion(version);
54+
55+
// For everything below 6.5, we need the shopware/production template.
56+
if (minor <= 4) {
57+
return "https://github.com/shopware/production";
58+
}
59+
60+
return "https://github.com/shopware/shopware";
61+
}
62+
63+
async function main() {
64+
const minPHPVersion = await loadMinPHPVersion();
65+
66+
const shopwarePhpVersions = await loadShopwarePHPVersions();
67+
68+
const shopwareMinorVersions = [];
69+
70+
for (const [shopwareVersion, phpVersions] of Object.entries(shopwarePhpVersions)) {
71+
const [_, platform, major, minor, patch, prerelease, buildmetadata] = shopwareVersion.match(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/) ?? [];
72+
73+
if (prerelease !== undefined || buildmetadata !== undefined) {
74+
continue;
75+
}
76+
77+
const majorMinor = `${platform}.${major}.${minor}`;
78+
79+
if (shopwareMinorVersions[majorMinor] !== undefined && shopwareMinorVersions[majorMinor].shopwareVersion >= shopwareVersion) {
80+
continue;
81+
}
82+
83+
shopwareMinorVersions[majorMinor] = {shopwareVersion, phpVersions}
84+
85+
}
86+
87+
let matrix = [];
88+
89+
for (const [_, line] of Object.entries(shopwareMinorVersions)) {
90+
const minPhpVersions = line.phpVersions.filter((phpVersion) => phpVersion >= minPHPVersion);
91+
92+
if (minPhpVersions.length === 0) {
93+
continue;
94+
}
95+
96+
FLAVORS.forEach((flavor) => {
97+
matrix.push({
98+
"shopware-version": 'v' + line.shopwareVersion,
99+
"php-version": minPhpVersions[0],
100+
"flavour": flavor,
101+
"template": getTemplate(line.shopwareVersion),
102+
});
103+
});
104+
}
105+
106+
if (matrix.length === 0) {
107+
throw new Error("No matrix entries generated.");
108+
}
109+
110+
HARDCODED_MATRIX.forEach((entry) => {
111+
FLAVORS.forEach((flavor) => {
112+
entry.flavour = flavor;
113+
114+
matrix.push(entry);
115+
});
116+
});
117+
118+
console.log(JSON.stringify({
119+
include: matrix.flat(),
120+
}));
121+
}
122+
123+
main();

0 commit comments

Comments
 (0)