-
Notifications
You must be signed in to change notification settings - Fork 387
309 lines (306 loc) · 11.2 KB
/
ci.yml
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
on:
push:
branches:
- develop
- develop-*
- release/**
workflow_dispatch:
# empty as it is used only to manually trigger the workflow
env:
CYPRESS_KEY: ${{ secrets.CYPRESS_KEY }}
NODE_VERSION: '16'
concurrency:
group: ci-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
name: Spartacus build pipeline
jobs:
no_retries:
name: Verify re-run of all jobs
runs-on: ubuntu-latest
steps:
- name: Forcefully fail build if jobs are all retried
uses: actions/github-script@v5
with:
script: |
core.setFailed('Please push a commit to trigger the build. To push an empty commit you can use `git commit --allow-empty -m "Trigger Build"`')
if: ${{ github.run_attempt > 1 }}
validate_e2e_execution:
name: Validate pull_request files
runs-on: ubuntu-latest
outputs:
SHOULD_RUN_E2E: ${{ steps.save-e2e-output-result.outputs.SHOULD_RUN_E2E }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Determine whether to run e2es
id: save-e2e-output-result
run: |
source ci-scripts/validate-e2e-execution.sh
echo "::set-output name=SHOULD_RUN_E2E::$(echo $RUN_E2E)"
unit_tests:
needs: no_retries
name: Unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v2
with:
path: |
node_modules
projects/storefrontapp-e2e-cypress/node_modules
~/.cache/Cypress
key: nodemodules-${{ github.event.pull_request.base.sha }}
restore-keys: nodemodules-${{ github.event.pull_request.base.sha }}
- name: Package installation
run: npm ci
- 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@v3
with:
fetch-depth: 0
- name: SonarQube Scan
uses: sonarsource/sonarqube-scan-action@master
with:
args: >
-Dsonar.qualitygate.wait=true
-Dsonar.projectKey=composable-storefront
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@v2
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v2
with:
path: |
node_modules
projects/storefrontapp-e2e-cypress/node_modules
~/.cache/Cypress
key: nodemodules-${{ github.event.pull_request.base.sha }}
restore-keys: nodemodules-${{ github.event.pull_request.base.sha }}
- name: Package installation
run: npm ci
- name: Run linting validation
run: |
ci-scripts/validate-lint.sh
b2c_e2e_tests:
needs: [no_retries, validate_e2e_execution]
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:
- name: Forcefully fail build if e2e job is retried
uses: actions/github-script@v5
with:
script: |
core.setFailed('Please push a commit to trigger the build. To push an empty commit you can use `git commit --allow-empty -m "Trigger Build"`')
if: ${{ github.run_attempt > 1 }}
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v2
with:
path: |
node_modules
projects/storefrontapp-e2e-cypress/node_modules
~/.cache/Cypress
key: nodemodules-${{ github.event.pull_request.base.sha }}
restore-keys: nodemodules-${{ github.event.pull_request.base.sha }}
- 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
b2c_ssr_e2e_tests:
needs: [no_retries, validate_e2e_execution]
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:
- name: Forcefully fail build if e2e job is retried
uses: actions/github-script@v5
with:
script: |
core.setFailed('Please push a commit to trigger the build. To push an empty commit you can use `git commit --allow-empty -m "Trigger Build"`')
if: ${{ github.run_attempt > 1 }}
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v2
with:
path: |
node_modules
projects/storefrontapp-e2e-cypress/node_modules
~/.cache/Cypress
key: nodemodules-${{ github.event.pull_request.base.sha }}
restore-keys: nodemodules-${{ github.event.pull_request.base.sha }}
- 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 --ssr
b2b_e2e_tests:
needs: [no_retries, validate_e2e_execution]
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:
- name: Forcefully fail build if e2e job is retried
uses: actions/github-script@v5
with:
script: |
core.setFailed('Please push a commit to trigger the build. To push an empty commit you can use `git commit --allow-empty -m "Trigger Build"`')
if: ${{ github.run_attempt > 1 }}
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v2
with:
path: |
node_modules
projects/storefrontapp-e2e-cypress/node_modules
~/.cache/Cypress
key: nodemodules-${{ github.event.pull_request.base.sha }}
restore-keys: nodemodules-${{ github.event.pull_request.base.sha }}
- 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
build_conclusion:
needs: [no_retries, unit_tests, linting, b2c_e2e_tests, b2c_ssr_e2e_tests, b2b_e2e_tests, sonarqube_scan]
name: Build Conclusion
runs-on: ubuntu-latest
if: ${{ always() }}
steps:
- name: Required build failed
uses: actions/github-script@v5
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.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'
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
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_TOKEN }}
uses: slackapi/[email protected]
with:
channel-id: ${{ secrets.SLACK_NOTIFICATION_CHANNEL }}
payload: |
{
"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