-
Notifications
You must be signed in to change notification settings - Fork 17
329 lines (313 loc) · 12.6 KB
/
dispatch_metapackage.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
name: Manual trigger
# yamllint disable-line rule:truthy
on:
workflow_dispatch:
inputs:
version:
type: choice
options:
- '7.0'
- '7.1'
- '7.2'
- '8.0'
- 'custom'
default: '8.0'
description: 'Version of the metapackage'
scenario:
type: choice
options:
- 'full'
- 'slim'
default: 'slim'
description: 'Scenario'
limit:
type: choice
options:
- 'no'
- 'PHP8.0/MySQL5.7'
- 'PHP8.0/MySQL8.0'
- 'PHP8.1/MySQL5.7'
- 'PHP8.1/MySQL8.0'
- 'PHP8.2/MySQL5.7'
- 'PHP8.2/MySQL8.0'
- 'PHP8.3/MySQL5.7'
- 'PHP8.3/MySQL8.0'
default: 'PHP8.1/MySQL5.7'
description: 'Limit to one PHP/MySQL combination'
custom_testplan:
type: string
required: true
description: 'Custom testplan'
default: '~/defaults/php8.2_mysql5.7_only.yaml,~/metapackage-8.0-full.yaml'
runs_on:
type: string
description: 'JSON string/array describing the runner'
required: true
default: '["ubuntu-latest"]'
use_dev_version:
type: choice
options: ['no', 'v0']
description: 'Use the dev version of github actions'
default: 'no'
jobs:
build_testplan:
runs-on: ${{ fromJson(inputs.runs_on) }}
outputs:
testplan: '${{ steps.build.outputs.testplan }}'
steps:
- name: 'Build matrix'
id: build
run: |
# Build matrix
# shellcheck disable=SC2088
case "${{ inputs.limit }}" in
"no") LIMIT='';;
"PHP8.0/MySQL5.7") LIMIT='~/defaults/php8.0_mysql5.7_only.yaml,' ;;
"PHP8.0/MySQL8.0") LIMIT='~/defaults/php8.0_mysql8.0_only.yaml,' ;;
"PHP8.1/MySQL5.7") LIMIT='~/defaults/php8.1_mysql5.7_only.yaml,' ;;
"PHP8.1/MySQL8.0") LIMIT='~/defaults/php8.1_mysql8.0_only.yaml,' ;;
"PHP8.2/MySQL5.7") LIMIT='~/defaults/php8.2_mysql5.7_only.yaml,' ;;
"PHP8.2/MySQL8.0") LIMIT='~/defaults/php8.2_mysql8.0_only.yaml,' ;;
"PHP8.3/MySQL5.7") LIMIT='~/defaults/php8.3_mysql5.7_only.yaml,' ;;
"PHP8.3/MySQL8.0") LIMIT='~/defaults/php8.3_mysql8.0_only.yaml,' ;;
*) echo "Illegal choice, fix the workflow"
exit 1
;;
esac
# shellcheck disable=SC2088
case '${{ inputs.version}}' in
"7.0") PRE="~/defaults/7.0.x.yaml," ;;
"7.1") PRE="~/defaults/7.1.x.yaml," ;;
"7.2") PRE="~/defaults/7.2.x.yaml," ;;
"8.0") PRE="~/defaults/8.0.x.yaml," ;;
custom) TESTPLAN="${{ inputs.custom_testplan }}" ;;
*)
echo "Illegal choice, fix the workflow"
exit 1
;;
esac
if [ -z "${TESTPLAN}" ]; then
# shellcheck disable=SC2088
TESTPLAN="${PRE}${LIMIT}~/metapackage-${{inputs.version}}-${{inputs.scenario}}.yaml"
fi
echo "testplan=${TESTPLAN}" | tee -a "${GITHUB_OUTPUT}"
stable:
needs: build_testplan
if: ${{ inputs.use_dev_version == 'no' }}
uses: oxid-eSales/github-actions/.github/workflows/universal_workflow_light.yaml@v4
with:
testplan: ${{ needs.build_testplan.outputs.testplan }}
runs_on: ${{ inputs.runs_on }}
defaults: 'v4'
plan_folder: '.github/oxid-esales'
secrets:
DOCKER_HUB_USER: ${{ secrets.DOCKER_HUB_USER }}
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
CACHE_ENDPOINT: ${{ secrets.CACHE_ENDPOINT }}
CACHE_ACCESS_KEY: ${{ secrets.CACHE_ACCESS_KEY }}
CACHE_SECRET_KEY: ${{ secrets.CACHE_SECRET_KEY }}
enterprise_github_token: ${{ secrets.enterprise_github_token }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
dev:
needs: build_testplan
if: ${{ inputs.use_dev_version == 'v0' }}
uses: oxid-eSales/github-actions/.github/workflows/universal_workflow_light.yaml@v0
with:
testplan: ${{ needs.build_testplan.outputs.testplan }}
runs_on: ${{ inputs.runs_on }}
defaults: 'v0'
plan_folder: '.github/oxid-esales'
secrets:
DOCKER_HUB_USER: ${{ secrets.DOCKER_HUB_USER }}
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
CACHE_ENDPOINT: ${{ secrets.CACHE_ENDPOINT }}
CACHE_ACCESS_KEY: ${{ secrets.CACHE_ACCESS_KEY }}
CACHE_SECRET_KEY: ${{ secrets.CACHE_SECRET_KEY }}
enterprise_github_token: ${{ secrets.enterprise_github_token }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
gather_data:
needs: ['build_testplan', 'stable', 'dev']
if: always()
runs-on: ${{ fromJson(inputs.runs_on) }}
outputs:
mysql: ${{ steps.mysql.outputs.result }}
php: ${{ steps.php.outputs.result }}
steps:
- name: 'Checkout testplan defaults'
uses: actions/checkout@v4
with:
repository: 'OXID-eSales/github-actions'
ref: 'v4'
path: 'defaults'
sparse-checkout: '.github/oxid-esales'
- name: 'Checkout testplans'
uses: actions/checkout@v4
with:
sparse-checkout: |
'.github/oxid-esales'
composer.json
path: workflow
- name: 'Consolidate plans'
id: consolidate_plans
run: |
mkdir -p '.github/oxid-esales/defaults'
if [ -d workflow/.github/oxid-esales ]; then
mv workflow/.github/oxid-esales/* '.github/oxid-esales/'
/bin/rm -r 'workflow/.github/oxid-esales'
fi
if [ -f workflow/composer.json ]; then
mv workflow/composer.json '.github/oxid-esales/'
fi
mv defaults/.github/oxid-esales/* '.github/oxid-esales/defaults/'
# ToDo: The next line can be removed in v5 when the transition to yaml is finished
cp '.github/oxid-esales/_custom.yaml' '.github/oxid-esales/_custom.yml'
if [ '${{ github.event_name }}' == 'pull_request' ]; then
REF=$(echo '${{ github.ref_name }}'|sed -e 's|/refs/heads/||')
# This is the git ref name
sed -e "s|safe_ref_name:.*|safe_ref_name: ${REF}|" -i.backup '.github/oxid-esales/defaults/defaults_light.yaml'
# This is the same for composer but with an added dev- prefix
sed -e "s|ref_name: dev-.*|ref_name: dev-${REF}|" -i.backup '.github/oxid-esales/defaults/defaults_light.yaml'
fi
TESTPLAN=$(echo "${{ needs.build_testplan.outputs.testplan }}"|sed -e 's|~|.github/oxid-esales|g')
# ToDo: Remove the ,.github/oxid-esales/defaults/_rename.yaml when releasing v5
DEFAULTS=".github/oxid-esales/defaults/defaults_light.yaml"
echo "testplan=${DEFAULTS},${TESTPLAN},.github/oxid-esales/defaults/_rename.yaml" >>"${GITHUB_OUTPUT}"
- name: 'Load Testplan'
id: ltp
uses: 'joernott/load_testplan@v1'
with:
files: '${{ steps.consolidate_plans.outputs.testplan }}'
set_output: true
set_env: true
set_print: true
loglevel: info
logfile: load_testplan_init.log
yaml: generated_testplan.yaml
- name: Get First MySQL
uses: actions/github-script@v7
id: mysql
with:
script: |
m = JSON.parse('${{ steps.ltp.outputs.install_matrix_mysql}}');
if (typeof m === 'string' || m instanceof String)
return m;
if (m.constructor !== Array)
core.setFailed('Could not get mysql matrix');
return m[0];
result-encoding: string
- name: Get PHP array
uses: actions/github-script@v7
id: php
with:
script: |
p = JSON.parse('${{ steps.ltp.outputs.install_matrix_php}}');
if (typeof p === 'string' || p instanceof String)
return [p];
if (p.constructor !== Array)
core.setFailed('Could not get php matrix');
return p;
consolidate:
needs: 'gather_data'
if: always()
runs-on: ${{ fromJson(inputs.runs_on) }}
strategy:
matrix:
php: ${{ fromJSON(needs.gather_data.outputs.php) }}
branch: ['b-7.0', 'b-7.1', 'b-7.2', 'b-8.0']
steps:
- name: 'Download artifacts'
uses: actions/download-artifact@v4
with:
pattern: 'install-*.${{matrix.branch}}.x-PHP${{matrix.php}}-MYSQL${{needs.gather_data.outputs.mysql}}'
path: data
- name: 'Rename files'
run: |
mv data/source/composer.lock ${{matrix.branch}}-${{matrix.php}}-composer.lock
mv data/source/composer.json.bak ${{matrix.branch}}-${{matrix.php}}-composer.json
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: 'composer-${{matrix.branch}}-${{matrix.php}}'
path: ${{matrix.branch}}-{{matrix.php}}-composer.*
retention-days: 4
overwrite: true
process_data:
needs: ['gather_data', 'consolidate']
if: always()
runs-on: ${{ fromJson(inputs.runs_on) }}
steps:
- name: 'Download artifacts'
uses: actions/download-artifact@v4
with:
pattern: '*-composer.*'
path: files
- name: Process files
uses: actions/github-script@v7
id: mysql
with:
script: |
var fs = require('fs');
var branches = ['b-7.0', 'b-7.1', 'b-7.2', 'b-8.0'];
var php_versions = JSON.parse('${{ fromJSON(needs.gather_data.outputs.php) }}');
if (php_versions.constructor !== Array)
console.log(`Could not get PHP matrix from ${php_versions}`);
core.setFailed(`Could not get PHP matrix from ${php_versions}`);
for (var b = 0; b < branches.length; b++) {
var branch = branches[b];
composer_file=`./${branch}-${php_versions[0]}-composer.json`;
console.log(`Load ${composer_file}`);
var composer_json = JSON.parse(fs.readFileSync(composer_file, 'utf8'));
var all = {};
var require = {};
for (r in composer_json["require"]) {
require[r]=''
console.log(`Add ${r} to mandatory list`);
}
for (var p = 0; p < php_versions.length; p++) {
lock_file=`./${branch}-${php_versions[p]}-composer.lock`
console.log(`Load ${lock_file}`);
var composer_lock = JSON.parse(fs.readFileSync(lock_file, 'utf8'));
for (l = 0; l < composer_lock.packages.length; l++) {
package=composer_lock.packages[l].name
version=composer_lock.packages[l].version
console.log(`Process ${package}:${version} from composer.lock ...`);
if (! (package in all)) {
all[package]=version
console.log("... added to all");
} else {
a=all[package];
i=a.indexOf(version);
console.log(`... already exists with value ${a} (${i})`);
if (a.indexOf(version) === -1) {
all[package] = `${all[package]} || ${version}`;
console.log("... extended previous definition in all");
}
}
if (package in require) {
if (require[package] == '') {
console.log("... set value in mandatory list");
require[package] = version;
} else {
if (require[package].indexOf(version) === -1) {
require[package] = `${require[package]} || ${version}`;
console.log("... extended previous definition in mandatory list");
}
}
} else {
console.log("... ignore for mandatory list");
}
}
}
core.summary.addSeparator()
core.summary.addHeading(`Pinned versions for ${branch}`, '1')
core.summary.addCodeBlock(JSON.stringify(all), 'json')
console.log(`Mandatory list for ${branch}`);
console.log("========================");
console.log(require);
console.log("========================");
console.log(`Full list for ${branch}`);
console.log("========================");
console.log(all);
}