-
Notifications
You must be signed in to change notification settings - Fork 412
471 lines (464 loc) · 18.8 KB
/
Copy pathci.yml
File metadata and controls
471 lines (464 loc) · 18.8 KB
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
on:
push:
branches:
- develop
- develop-*
- release/*
workflow_dispatch:
# empty as it is used only to manually trigger the workflow.
permissions:
contents: read
actions: write
pull-requests: write
env:
CYPRESS_KEY: ${{ secrets.CYPRESS_KEY }}
NODE_VERSION: "20"
CONTINUUM_REGISTRY_TOKEN: ${{ secrets.CONTINUUM_REGISTRY_TOKEN }}
SAP_COMMON_NPM_TOKEN: ${{ secrets.SAP_COMMON_NPM_TOKEN }}
concurrency:
group: ci-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
name: Spartacus build pipeline
jobs:
detect_changes:
name: CI - Detect changes
runs-on: ubuntu-latest
outputs:
RUN_CHECKS: ${{ steps.detect_code_changes.outputs.RUN_CHECKS }}
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Detect code changes
id: detect_code_changes
uses: ./.github/actions/detect-changes
no_retries:
needs: [detect_changes]
name: Verify re-run of all jobs
runs-on: ubuntu-latest
if: ${{ needs.detect_changes.outputs.RUN_CHECKS == 'true' }}
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Prevent retries
uses: ./.github/actions/prevent-retries
validate_e2e_execution:
needs: [detect_changes]
name: Validate pull_request files
runs-on: ubuntu-latest
if: ${{ needs.detect_changes.outputs.RUN_CHECKS == 'true' }}
outputs:
SHOULD_RUN_E2E: ${{ steps.save-e2e-output-result.outputs.SHOULD_RUN_E2E }}
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
fetch-depth: 0
- name: Determine whether to run e2es
id: save-e2e-output-result
run: |
source ci-scripts/validate-e2e-execution.sh
echo "SHOULD_RUN_E2E=$RUN_E2E" >> "$GITHUB_OUTPUT"
unit_tests:
needs: no_retries
name: Unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
fetch-depth: 0
- name: Setup Node and Cache
uses: ./.github/actions/setup-node-and-cache
with:
node-version: ${{ env.NODE_VERSION }}
cache-key: ${{ github.event.pull_request.base.sha || github.sha }}
- name: Run unit tests
run: ci-scripts/unit-tests.sh
sonarqube_scan:
needs: no_retries
name: SonarQube Scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
fetch-depth: 0
- name: SonarQube Scan
uses: sonarsource/sonarqube-scan-action@a31c9398be7ace6bbfaf30c0bd5d415f843d45e9 #v7.0.0
with:
args: >
-Dsonar.qualitygate.wait=true
-Dsonar.projectKey=composable-storefront
-Dsonar.typescript.exclusions=**/.github/**
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: https://sonar.tools.sap
if: github.event_name == 'pull_request'
linting:
needs: no_retries
name: Validations and static code checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Setup Node and Cache
uses: ./.github/actions/setup-node-and-cache
with:
node-version: ${{ env.NODE_VERSION }}
cache-key: ${{ github.event.pull_request.base.sha || github.sha }}
- name: Run linting validation
run: ci-scripts/validate-lint.sh
check_new_feature_toggles:
needs: no_retries
name: Check for new feature toggles
runs-on: ubuntu-latest
if: github.ref_name == 'develop' || startsWith(github.ref_name, 'release/')
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
fetch-depth: 0
- name: Check for new feature toggles
id: toggle-check
run: |
set +e
ci-scripts/check-new-feature-toggles.sh
exit_code=$?
echo "exit_code=$exit_code" >> $GITHUB_OUTPUT
exit $exit_code
- name: Prepare Slack User ID
if: always() && steps.toggle-check.outputs.new_toggles_found == 'true'
id: slack-user
run: |
USER_ID=$(echo '${{ vars.SLACK_TOGGLE_REVIEWER_ID }}' | tr -d '[:space:]')
echo "user_id=$USER_ID" >> $GITHUB_OUTPUT
echo "Cleaned user ID prepared for Slack mention"
- name: Send Slack notification for new toggles
if: always() && steps.toggle-check.outputs.new_toggles_found == 'true'
uses: slackapi/slack-github-action@91efab103c0de0a537f72a35f6b8cda0ee76bf0a #v2.1.1
with:
method: chat.postMessage
token: ${{ secrets.SLACK_TOKEN }}
payload: |
channel: ${{ vars.FEATURE_TOGGLE_SLACK_NOTIFICATION_CHANNEL }}
text: "New Feature Toggles Added"
blocks:
- type: "section"
text:
type: "mrkdwn"
text: ":new: *New Feature Toggles Added :new:*\n\n<@${{ steps.slack-user.outputs.user_id }}> ${{ steps.toggle-check.outputs.new_toggle_count }} new feature toggle(s) have been added to the codebase:\n\n${{ steps.toggle-check.outputs.new_toggles_list }}\n\n*Please ensure these toggles are properly documented for customers*"
- type: "divider"
- type: "actions"
elements:
- type: "button"
text:
type: "plain_text"
text: "View Changes"
emoji: true
value: "view_changes"
url: "${{ github.event.head_commit.url || github.event.pull_request.html_url }}"
build_libs:
needs: [no_retries, validate_e2e_execution]
name: Build Spartacus libraries
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || needs.validate_e2e_execution.outputs.SHOULD_RUN_E2E == 'true' }}
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Setup Node and Cache
uses: ./.github/actions/setup-node-and-cache
with:
node-version: ${{ env.NODE_VERSION }}
cache-key: ${{ github.event.pull_request.base.sha || github.sha }}
- name: Install Cypress packages
run: (cd projects/storefrontapp-e2e-cypress && npm ci)
- name: Snapshot source files before build
uses: ./.github/actions/build-integrity-check
with:
phase: snapshot
- name: Build Spartacus libraries
run: |
source ci-scripts/npm-commands.sh
export NODE_OPTIONS=--dns-result-order=ipv4first
build_libs 2>&1 | tee build.log
results=$(grep "Warning: Can't resolve all parameters for" build.log || true)
if [[ -z "${results}" ]]; then
echo "Success: Spartacus production build was successful."
rm build.log
else
echo "ERROR: Spartacus production build failed."
echo "Check for 'Warning: Can't resolve all parameters for ...' in the build log."
rm build.log
exit 1
fi
- name: Verify source file integrity after build
uses: ./.github/actions/build-integrity-check
with:
phase: verify
- name: Cache built libraries
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 #v4.3.0
with:
path: |
dist
key: spartacus-libs-${{ github.event.pull_request.head.sha || github.run_id }}
build_apps:
needs: [build_libs]
name: Build Spartacus apps - ${{ matrix.name }}
runs-on: ubuntu-latest
strategy:
matrix:
include:
- spa_env: ci,b2c
build_type: csr
cache_key: ci-b2c
name: B2C CSR
- spa_env: ci,b2b
build_type: csr
cache_key: ci-b2b
name: B2B CSR
- spa_env: ci,b2c
build_type: ssr
cache_key: ci-b2c
name: B2C SSR
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Setup Node and Cache
uses: ./.github/actions/setup-node-and-cache
with:
node-version: ${{ env.NODE_VERSION }}
cache-key: ${{ github.event.pull_request.base.sha || github.sha }}
- name: Restore built libraries
uses: ./.github/actions/restore-built-libraries
with:
cache-key: ${{ github.event.pull_request.head.sha || github.run_id }}
fail-on-cache-miss: true
- name: Build Spartacus app for ${{ matrix.spa_env }} (${{ matrix.build_type }})
env:
SPA_ENV: ${{ matrix.spa_env }}
NODE_OPTIONS: --dns-result-order=ipv4first
run: |
source ci-scripts/npm-commands.sh
echo "Building ${{ matrix.build_type }} app for SPA_ENV: ${{ matrix.spa_env }}"
if [ "${{ matrix.build_type }}" == "ssr" ]; then
build_ssr
else
build_csr
fi
- name: Cache built app (${{ matrix.spa_env }}-${{ matrix.build_type }})
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 #v4.3.0
with:
path: |
dist/storefrontapp
key: spartacus-app-${{ matrix.cache_key }}-${{ matrix.build_type }}-${{ github.event.pull_request.head.sha || github.run_id }}
b2c_e2e_tests:
needs: [no_retries, validate_e2e_execution, build_apps]
name: E2E tests for B2C
runs-on: ubuntu-latest
strategy:
matrix:
containers: [1, 2, 3, 4, 5]
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || needs.validate_e2e_execution.outputs.SHOULD_RUN_E2E == 'true' }}
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: E2E Test Setup
uses: ./.github/actions/e2e-setup
with:
node-version: ${{ env.NODE_VERSION }}
cache-key-base: ${{ github.event.pull_request.base.sha || github.sha }}
libs-cache-key: ${{ github.event.pull_request.head.sha || github.run_id }}
app-cache-key: ci-b2c-csr-${{ github.event.pull_request.head.sha || github.run_id }}
- name: Run e2es
env:
SPA_ENV: ci,b2c
BUILD_NUMBER: ci-build-number-${{ github.event.pull_request.head.sha || github.run_id }}
run: ci-scripts/e2e-cypress.sh --skip-build
b2c_ssr_e2e_tests:
needs: [no_retries, validate_e2e_execution, build_apps]
name: E2E tests for SSR B2C
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || needs.validate_e2e_execution.outputs.SHOULD_RUN_E2E == 'true' }}
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: E2E Test Setup
uses: ./.github/actions/e2e-setup
with:
node-version: ${{ env.NODE_VERSION }}
cache-key-base: ${{ github.event.pull_request.base.sha || github.sha }}
libs-cache-key: ${{ github.event.pull_request.head.sha || github.run_id }}
app-cache-key: ci-b2c-ssr-${{ github.event.pull_request.head.sha || github.run_id }}
- name: Run e2es
env:
SPA_ENV: ci,b2c
BUILD_NUMBER: ci-build-number-${{ github.event.pull_request.head.sha || github.run_id }}
run: ci-scripts/e2e-cypress.sh --skip-build --ssr
b2b_e2e_tests:
needs: [no_retries, validate_e2e_execution, build_apps]
name: E2E tests for B2B
runs-on: ubuntu-latest
strategy:
matrix:
containers: [1, 2, 3, 4]
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || needs.validate_e2e_execution.outputs.SHOULD_RUN_E2E == 'true' }}
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: E2E Test Setup
uses: ./.github/actions/e2e-setup
with:
node-version: ${{ env.NODE_VERSION }}
cache-key-base: ${{ github.event.pull_request.base.sha || github.sha }}
libs-cache-key: ${{ github.event.pull_request.head.sha || github.run_id }}
app-cache-key: ci-b2b-csr-${{ github.event.pull_request.head.sha || github.run_id }}
- name: Run e2es
env:
SPA_ENV: ci,b2b
BUILD_NUMBER: ci-build-number-${{ github.event.pull_request.head.sha || github.run_id }}
run: ci-scripts/e2e-cypress.sh -s b2b --skip-build
a11y_e2e_tests:
needs: [no_retries, validate_e2e_execution, build_apps]
name: E2E tests for A11Y
runs-on: ubuntu-latest
strategy:
matrix:
containers: [1, 2, 3]
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || needs.validate_e2e_execution.outputs.SHOULD_RUN_E2E == 'true' }}
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: E2E Test Setup
uses: ./.github/actions/e2e-setup
with:
node-version: ${{ env.NODE_VERSION }}
cache-key-base: ${{ github.event.pull_request.base.sha || github.sha }}
libs-cache-key: ${{ github.event.pull_request.head.sha || github.run_id }}
app-cache-key: ci-b2c-csr-${{ github.event.pull_request.head.sha || github.run_id }}
- name: Run e2es
env:
SPA_ENV: ci
BUILD_NUMBER: ci-build-number-${{ github.event.pull_request.head.sha || github.run_id }}
GITHUB_MATRIX_CONTAINER: ${{ matrix.containers }}
GITHUB_MATRIX_TOTAL: ${{ strategy.job-total }}
ENABLE_A11Y_RECORDING: true
run: ci-scripts/e2e-cypress.sh -s a11y --skip-build
ssr_tests:
needs: [no_retries, validate_e2e_execution, build_libs]
name: SSR Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Setup Node and Cache
uses: ./.github/actions/setup-node-and-cache
with:
node-version: ${{ env.NODE_VERSION }}
cache-key: ${{ github.event.pull_request.base.sha || github.sha }}
- name: Restore built libraries
uses: ./.github/actions/restore-built-libraries
with:
cache-key: ${{ github.event.pull_request.head.sha || github.run_id }}
fail-on-cache-miss: true
- name: Build SSR Server
run: |
source ci-scripts/npm-commands.sh
build_ssr_local_http
- name: Run SSR tests
run: |
source ci-scripts/npm-commands.sh
test_ssr
build_conclusion:
needs:
[
no_retries,
unit_tests,
linting,
build_libs,
build_apps,
b2c_e2e_tests,
b2c_ssr_e2e_tests,
b2b_e2e_tests,
a11y_e2e_tests,
ssr_tests,
sonarqube_scan,
]
name: Build Conclusion
runs-on: ubuntu-latest
if: ${{ always() }}
steps:
- name: Required build failed
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b #v7.1.0
with:
script: |
core.setFailed('Build failed')
if: |
needs.no_retries.result == 'failure' || needs.no_retries.result == 'cancelled' ||
needs.unit_tests.result == 'failure' || needs.unit_tests.result == 'cancelled' ||
needs.sonarqube_scan.result == 'failure' || needs.sonarqube_scan.result == 'cancelled' ||
needs.linting.result == 'failure' || needs.linting.result == 'cancelled' ||
needs.build_libs.result == 'failure' || needs.build_libs.result == 'cancelled' ||
needs.build_apps.result == 'failure' || needs.build_apps.result == 'cancelled' ||
needs.b2c_e2e_tests.result == 'failure' || needs.b2c_e2e_tests.result == 'cancelled' ||
needs.b2c_ssr_e2e_tests.result == 'failure' || needs.b2c_ssr_e2e_tests.result == 'cancelled' ||
needs.b2b_e2e_tests.result == 'failure' || needs.b2b_e2e_tests.result == 'cancelled' ||
needs.a11y_e2e_tests.result == 'failure' || needs.a11y_e2e_tests.result == 'cancelled' ||
needs.ssr_tests.result == 'failure' || needs.ssr_tests.result == 'cancelled'
send_slack_message:
needs: build_conclusion
name: Slack message for failed CI build in Spartacus
runs-on: ubuntu-latest
if: ${{ always() }}
steps:
- run: |
echo "Context Info:"
echo " Event = ${{ github.event_name }}"
echo " Build Result = ${{ needs.build_conclusion.result }}"
echo " Branch = ${{ github.ref_name }}"
echo " Default branch = ${{ github.event.repository.default_branch }}"
- name: Notify the slack channel of when build conclusion failed
uses: slackapi/slack-github-action@91efab103c0de0a537f72a35f6b8cda0ee76bf0a #v2.1.1
with:
method: chat.postMessage
token: ${{ secrets.SLACK_TOKEN }}
payload: |
{
"channel": "${{ vars.SLACK_NOTIFICATION_CHANNEL }}",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":nuclear-bomb: :fireduck: *Broken build on ${{ github.ref_name }}*"
}
},
{
"type": "divider"
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Failed build",
"emoji": true
},
"value": "failed_build",
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "What was committed?",
"emoji": true
},
"value": "recent_merged_commit",
"url": "${{ github.event.head_commit.url }}"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Build history",
"emoji": true
},
"value": "buid_history",
"url": "https://github.com/SAP/spartacus/actions/workflows/ci.yml?query=branch%3Adevelop"
}
]
}
]
}
if: |
needs.build_conclusion.result == 'failure' &&
github.event_name == 'push' &&
github.ref_name == github.event.repository.default_branch