-
Notifications
You must be signed in to change notification settings - Fork 45
528 lines (509 loc) · 18.6 KB
/
pre-merge.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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
name: Pre merge
concurrency:
# This stops any build on a branch if a new commit is pushed on that branch
# the second check is here to run each build when pushing on the branch `q/*`
# in order for bert-e to merge any branch that passes the queue before waiting
# for the entire queue to passe the build.
# if the branch is 'q/*' then we append the commit sha to the concurrency group to make it unique.
# this works because the '||' or condition will only evaluate the right side if the left side is false ;-)
group: "tests-${{ github.ref_name }}-${{ ( !startsWith(github.ref_name, 'q/') || github.sha) }}"
cancel-in-progress: true
on:
push:
branches:
- "release/**"
- "feature/**"
- "improvement/**"
- "hotfix/**"
- "bugfix/**"
- "documentation/**"
- "user/**"
- "dependabot/**"
- "w/**"
- "q/*/**"
jobs:
changed-files:
runs-on: ubuntu-24.04
outputs:
docs: ${{ steps.diff.outputs.docs_any_modified == 'true' }}
shell-ui: ${{ steps.diff.outputs.shell-ui_any_modified == 'true' }}
unit-tests-ui: ${{ steps.diff.outputs.unit-tests-ui_any_modified == 'true' }}
unit-tests-shell-ui: ${{ steps.diff.outputs.unit-tests-shell-ui_any_modified == 'true' }}
unit-tests-crd-client-generator: ${{ steps.diff.outputs.unit-tests-crd-client-generator_any_modified == 'true' }}
unit-tests-metalk8s-operator: ${{ steps.diff.outputs.unit-tests-metalk8s-operator_any_modified == 'true' }}
unit-tests-storage-operator: ${{ steps.diff.outputs.unit-tests-storage-operator_any_modified == 'true' }}
unit-tests-salt: ${{ steps.diff.outputs.unit-tests-salt_any_modified == 'true' }}
unit-tests-lib-alert-tree: ${{ steps.diff.outputs.unit-tests-lib-alert-tree_any_modified == 'true' }}
integration-tests-ui: ${{ steps.diff.outputs.integration-tests-ui_any_modified == 'true' }}
# If the workflow is triggered on a development branch let's always build
build: ${{ startsWith(github.ref_name, 'development/') || steps.diff.outputs.build_any_modified == 'true' }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get base sha
run: |
source VERSION
branch=development/${VERSION_MAJOR}.${VERSION_MINOR}
if [[ ! $(git ls-remote --heads origin $branch) ]]; then
branch=development/${VERSION_MAJOR}
fi
echo "BASE_SHA=$(git merge-base HEAD origin/$branch)" >> $GITHUB_ENV
- name: Get changed files
id: diff
uses: tj-actions/changed-files@v45
with:
base_sha: ${{ env.BASE_SHA }}
files_yaml_from_source_file: .github/changed-files.yaml
- name: List all changed files
env:
ALL_DOCS_CHANGED_FILES: ${{ steps.diff.outputs.docs_all_changed_files }}
ALL_SHELL_UI_CHANGED_FILES: ${{ steps.diff.outputs.shell-ui_all_changed_files }}
ALL_UNIT_TESTS_UI_CHANGED_FILES: ${{ steps.diff.outputs.unit-tests-ui_all_changed_files }}
ALL_UNIT_TESTS_SHELL_UI_CHANGED_FILES: ${{ steps.diff.outputs.unit-tests-shell-ui_all_changed_files }}
ALL_UNIT_TESTS_CRD_CLIENT_GENERATOR_CHANGED_FILES: ${{ steps.diff.outputs.unit-tests-crd-client-generator_all_changed_files }}
ALL_UNIT_TESTS_METALK8S_OPERATOR_CHANGED_FILES: ${{ steps.diff.outputs.unit-tests-metalk8s-operator_all_changed_files }}
ALL_UNIT_TESTS_STORAGE_OPERATOR_CHANGED_FILES: ${{ steps.diff.outputs.unit-tests-storage-operator_all_changed_files }}
ALL_UNIT_TESTS_SALT_CHANGED_FILES: ${{ steps.diff.outputs.unit-tests-salt_all_changed_files }}
ALL_UNIT_TESTS_LIB_ALERT_TREE_CHANGED_FILES: ${{ steps.diff.outputs.unit-tests-lib-alert-tree_all_changed_files }}
ALL_INTEGRATION_TESTS_UI_CHANGED_FILES: ${{ steps.diff.outputs.integration-tests-ui_all_changed_files }}
ALL_BUILD_CHANGED_FILES: ${{ steps.diff.outputs.build_all_changed_files }}
run: |
for type in docs shell-ui unit-tests-ui unit-tests-shell-ui unit-tests-crd-client-generator unit-tests-metalk8s-operator unit-tests-storage-operator unit-tests-salt unit-tests-lib-alert-tree integration-tests-ui build; do
echo "All $type changed files:"
changed_files_var=$(echo "ALL_${type^^}_CHANGED_FILES" | tr '-' '_')
echo "${!changed_files_var}"
done
build:
needs: changed-files
if: needs.changed-files.outputs.build == 'true'
uses: ./.github/workflows/build.yaml
secrets: inherit
build-docs:
needs: changed-files
# Build of docs is triggered by "build" so do not re-trigger it
if: needs.changed-files.outputs.docs == 'true' && needs.changed-files.outputs.build != 'true'
uses: ./.github/workflows/build-docs.yaml
secrets: inherit
build-shell-ui:
needs: changed-files
# Build of shell-ui is triggered by "build" so do not re-trigger it
if: needs.changed-files.outputs.shell-ui == 'true' && needs.changed-files.outputs.build != 'true'
uses: ./.github/workflows/build-shell-ui.yaml
secrets: inherit
e2e-tests:
needs:
- build
- changed-files
if: needs.changed-files.outputs.build == 'true'
uses: ./.github/workflows/e2e-tests.yaml
secrets: inherit
with:
artifacts-url: ${{ needs.build.outputs.artifact-link }}
lint:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Python 3
uses: actions/setup-python@v5
with:
python-version: "3.10"
# NOTE: Today python3.6 is needed by some lint steps
- name: Install Python 3.6
uses: actions/setup-python@v5
with:
python-version: "3.6"
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: "1.20.14"
- name: Install deps
run: |
export DEBIAN_FRONTEND=noninteractive
sudo apt-get update
sudo apt-get install --no-install-recommends -y shellcheck python2.7-minimal
python3.10 -m pip install tox~=4.0.11
- name: Install Helm
env:
HELM_VERSION: "3.10.0"
run: |
sudo curl -O https://get.helm.sh/helm-v${HELM_VERSION}-linux-amd64.tar.gz \
&& sudo tar -zxvf helm-v${HELM_VERSION}-linux-amd64.tar.gz \
&& sudo mv linux-amd64/helm /usr/local/bin/helm
- name: Run all linting targets
run: ./doit.sh lint
unit_tests_ui:
needs: changed-files
if: needs.changed-files.outputs.unit-tests-ui == 'true'
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install node
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Cache node modules
id: cache-npm
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install UI dependencies
run: |
cd ui
npm ci --prefer-offline --no-audit --legacy-peer-deps --unsafe-perm --no-optional
- name: Run all UI unit tests
run: |
cd ui
npm run test:nowatch --no-update-notifier
- name: Prepare artifacts
run: mkdir -p "artifacts/ui" && mv ui/junit artifacts/ui/
- name: Upload artifacts
uses: scality/action-artifacts@v4
with:
method: upload
url: https://artifacts.scality.net
user: ${{ secrets.ARTIFACTS_USER }}
password: ${{ secrets.ARTIFACTS_PASSWORD }}
source: artifacts
unit_tests_shell_ui:
needs: changed-files
if: needs.changed-files.outputs.unit-tests-shell-ui == 'true'
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install node
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Cache node modules
id: cache-npm
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install UI dependencies
run: |
cd shell-ui
npm ci --prefer-offline --no-audit --legacy-peer-deps -d
- name: Run all Shell UI unit tests
run: |
cd shell-ui
npm run test --no-update-notifier
unit_tests_crd_client_generator:
needs: changed-files
if: needs.changed-files.outputs.unit-tests-crd-client-generator == 'true'
runs-on: ubuntu-20.04
defaults:
run:
working-directory: "tools/crd-client-generator-js"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install node
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Cache node modules
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install CRD client generator dependencies
run: npm ci --prefer-offline --no-audit
- name: Run all CRD client generator unit tests
run: npm run test --no-update-notifier
unit_tests_metalk8s_operator:
needs: changed-files
if: needs.changed-files.outputs.unit-tests-metalk8s-operator == 'true'
runs-on: ubuntu-20.04
defaults:
run:
working-directory: "operator"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: "1.20.14"
- name: Cache Go modules
uses: actions/cache@v4
env:
cache-name: cache-go-modules
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('go.sum') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Run all MetalK8s operator unit and integration tests
run: make test
unit_tests_storage_operator:
needs: changed-files
if: needs.changed-files.outputs.unit-tests-storage-operator == 'true'
runs-on: ubuntu-20.04
defaults:
run:
working-directory: "storage-operator"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: "1.20.14"
- name: Cache Go modules
uses: actions/cache@v4
env:
cache-name: cache-go-modules
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('go.sum') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Run all storage-operator unit and integration tests
run: make test
unit_tests_salt:
needs: changed-files
if: needs.changed-files.outputs.unit-tests-salt == 'true'
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Python 3.6
uses: actions/setup-python@v5
with:
python-version: "3.6"
- name: Install deps
run: |
pip install tox
- name: Run all salt unit tests
run: tox -e unit-tests
unit_tests_lib_alert_tree:
needs: changed-files
if: needs.changed-files.outputs.unit-tests-lib-alert-tree == 'true'
runs-on: ubuntu-20.04
defaults:
run:
working-directory: "tools/lib-alert-tree"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Python 3
uses: actions/setup-python@v5
with:
python-version: "3.6"
- name: Install deps
run: python3.6 -m pip install poetry~=1.1.9
- name: Install lib_alert_tree
run: poetry install -E cli
- name: Run all lib_alert_tree unit tests
run: poetry run pytest -vv
build_integration_container_nginx:
needs: changed-files
if: needs.changed-files.outputs.integration-tests-ui == 'true'
runs-on: ubuntu-20.04
permissions: write-all
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Install node
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Cache node modules
id: cache-npm
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install Shell UI dependencies
run: |
cd shell-ui
npm ci --legacy-peer-deps
- name: Build Shell UI
run: |
cd shell-ui
npm run rsbuild
- name: Install UI dependencies
run: |
cd ui
npm ci --legacy-peer-deps
- name: Build UI
run: |
cd ui
npm run build
- name: Prepare Services Volumes
run: |
mkdir -p service
mkdir -p service/shell
cp -r ui/build/* service/
cp -r ui/build/.well-known service/.well-known
cp -r shell-ui/build/* service/shell/
- name: Build container with nginx configuration for integration tests
run: |
cat > Dockerfile <<EOF
FROM nginx:alpine
COPY ui/standalone-nginx.conf /etc/nginx/conf.d/default.conf
ADD service /usr/share/nginx/html
EOF
- name: Login to Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v6
with:
push: true
file: Dockerfile
context: .
tags: ghcr.io/${{ github.repository_owner }}/metalk8s-nginx-integration-tests:${{ github.sha }}
integration_tests_ui:
runs-on: ubuntu-20.04
needs:
- build_integration_container_nginx
- changed-files
if: needs.changed-files.outputs.integration-tests-ui == 'true'
services:
app:
image: ghcr.io/${{ github.repository_owner }}/metalk8s-nginx-integration-tests:${{ github.sha }}
credentials:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
ports:
- 80:80
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install node
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Cache node modules
id: cache-npm
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install Cypress and its dependencies
run: |
cd ui
PKGS="har-validator cypress cypress-cucumber-preprocessor cypress-wait-until @testing-library/cypress"
for pkg in $PKGS; do
npm install --no-save --no-package-lock --legacy-peer-deps $pkg@$(node -p \
-e "require('./package-lock.json').dependencies['$pkg'].version" \
) || exit 1
done
- name: Wait for application to be available
run: |
bash -c '
attempts=0
until curl -Isfo /dev/null http://localhost/; do
(( attempts++ ))
if [ $attempts -gt 100 ]; then
>&2 echo "Failed to reach application after 5 minutes"
exit 1
fi
sleep 3
done
'
- name: Run all UI integration tests
env:
CYPRESS_BASE_URL: http://localhost
run: |
cd ui
rm -rf babel.config.js
npm run test:integration --no-update-notifier
- name: Prepare upload folder
if: always()
run: |
mkdir -p upload/ui/cypress
mv ui/cypress/screenshots upload/ui/cypress/screenshots || true
mv ui/cypress/videos upload/ui/cypress/videos || true
mv junit upload/ui || true
- name: Upload artifacts
if: always()
uses: scality/action-artifacts@v4
with:
method: upload
url: https://artifacts.scality.net
user: ${{ secrets.ARTIFACTS_USER }}
password: ${{ secrets.ARTIFACTS_PASSWORD }}
source: upload
write-final-status:
runs-on: ubuntu-20.04
needs:
- changed-files
- build-docs
- build-shell-ui
- e2e-tests
- lint
- unit_tests_ui
- unit_tests_shell_ui
- unit_tests_crd_client_generator
- unit_tests_metalk8s_operator
- unit_tests_storage_operator
- unit_tests_salt
- unit_tests_lib_alert_tree
- integration_tests_ui
if: always()
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Upload final status
if: always()
uses: scality/actions/[email protected]
with:
ARTIFACTS_USER: ${{ secrets.ARTIFACTS_USER }}
ARTIFACTS_PASSWORD: ${{ secrets.ARTIFACTS_PASSWORD }}
JOBS_RESULTS: ${{ join(needs.*.result) }}