-
Notifications
You must be signed in to change notification settings - Fork 0
448 lines (448 loc) · 19.8 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
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
name: "CI/CD Pipeline"
on:
push:
branches-ignore:
- l10n_develop
- gh-pages
paths-ignore:
- '*.md'
- 'LICENSE'
- 'monitoring/grafana-dashboard.json'
- 'screenshots/**'
tags-ignore:
- '*'
pull_request:
paths-ignore:
- '*.md'
- 'LICENSE'
- 'data/static/i18n/*.json'
- 'frontend/src/assets/i18n/*.json'
env:
ANGULAR_CLI_VERSION: 13
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: "Check out Git repository"
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f #v2: v2.3.4 available
- name: "Use Node.js 16"
uses: actions/setup-node@f1f314fca9dfce2769ece7d933488f076716723e #v1: v2.x available
with:
node-version: 16
- name: "Install CLI tools"
run: npm install -g @angular/cli@$ANGULAR_CLI_VERSION
- name: "Install application minimalistically"
run: |
npm install --ignore-scripts
cd frontend
npm install --ignore-scripts --legacy-peer-deps
- name: "Lint source code"
run: npm run lint
- name: "Lint customization configs"
run: >
npm run lint:config -- -f ./config/7ms.yml &&
npm run lint:config -- -f ./config/addo.yml &&
npm run lint:config -- -f ./config/bodgeit.yml &&
npm run lint:config -- -f ./config/ctf.yml &&
npm run lint:config -- -f ./config/default.yml &&
npm run lint:config -- -f ./config/fbctf.yml &&
npm run lint:config -- -f ./config/juicebox.yml &&
npm run lint:config -- -f ./config/mozilla.yml &&
npm run lint:config -- -f ./config/oss.yml &&
npm run lint:config -- -f ./config/quiet.yml &&
npm run lint:config -- -f ./config/tutorial.yml &&
npm run lint:config -- -f ./config/unsafe.yml
coding-challenge-rsn:
runs-on: windows-latest
steps:
- name: "Check out Git repository"
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f #v2: v2.3.4 available
- name: "Use Node.js 16"
uses: actions/setup-node@f1f314fca9dfce2769ece7d933488f076716723e #v1: v2.x available
with:
node-version: 16
- name: "Install CLI tools"
run: npm install -g @angular/cli@$ANGULAR_CLI_VERSION
- name: "Install application"
run: npm install
- name: "Check coding challenges for accidental code discrepancies"
run: npm run rsn
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [14, 16, 18]
steps:
- name: "Check out Git repository"
if: github.repository == 'juice-shop/juice-shop' || github.repository != 'juice-shop/juice-shop' && matrix.os == 'ubuntu-latest' && matrix.node-version == '16'
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f #v2: v2.3.4 available
- name: "Use Node.js ${{ matrix.node-version }}"
if: github.repository == 'juice-shop/juice-shop' || github.repository != 'juice-shop/juice-shop' && matrix.os == 'ubuntu-latest' && matrix.node-version == '16'
uses: actions/setup-node@f1f314fca9dfce2769ece7d933488f076716723e #v1: v2.x available
with:
node-version: ${{ matrix.node-version }}
- name: "Install CLI tools"
if: github.repository == 'juice-shop/juice-shop' || github.repository != 'juice-shop/juice-shop' && matrix.os == 'ubuntu-latest' && matrix.node-version == '16'
run: npm install -g @angular/cli@$ANGULAR_CLI_VERSION
- name: "Install application"
if: github.repository == 'juice-shop/juice-shop' || github.repository != 'juice-shop/juice-shop' && matrix.os == 'ubuntu-latest' && matrix.node-version == '16'
run: npm install
- name: "Execute unit tests"
if: github.repository == 'juice-shop/juice-shop' || github.repository != 'juice-shop/juice-shop' && matrix.os == 'ubuntu-latest' && matrix.node-version == '16'
uses: nick-invision/retry@45ba062d357edb3b29c4a94b456b188716f61020 #v2: 2.4.1 available
with:
timeout_minutes: 15
max_attempts: 3
command: npm test
- name: "Copy unit test coverage data"
run: |
cp build/reports/coverage/frontend-tests/lcov.info frontend-lcov.info
cp build/reports/coverage/server-tests/lcov.info server-lcov.info
- name: "Upload unit test coverage data"
if: github.repository == 'juice-shop/juice-shop' && github.event_name == 'push' && matrix.os == 'ubuntu-latest' && matrix.node-version == '16'
uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535 #v3: v3.0.0 available
with:
name: unit-test-lcov
path: |
frontend-lcov.info
server-lcov.info
api-test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [14, 16, 18]
steps:
- name: "Check out Git repository"
if: github.repository == 'juice-shop/juice-shop' || github.repository != 'juice-shop/juice-shop' && matrix.os == 'ubuntu-latest' && matrix.node-version == '16'
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f #v2: v2.3.4 available
- name: "Use Node.js ${{ matrix.node-version }}"
if: github.repository == 'juice-shop/juice-shop' || github.repository != 'juice-shop/juice-shop' && matrix.os == 'ubuntu-latest' && matrix.node-version == '16'
uses: actions/setup-node@f1f314fca9dfce2769ece7d933488f076716723e #v1: v2.x available
with:
node-version: ${{ matrix.node-version }}
- name: "Install CLI tools"
if: github.repository == 'juice-shop/juice-shop' || github.repository != 'juice-shop/juice-shop' && matrix.os == 'ubuntu-latest' && matrix.node-version == '16'
run: npm install -g @angular/cli@$ANGULAR_CLI_VERSION
- name: "Install application"
if: github.repository == 'juice-shop/juice-shop' || github.repository != 'juice-shop/juice-shop' && matrix.os == 'ubuntu-latest' && matrix.node-version == '16'
run: npm install
- name: "Execute integration tests"
if: github.repository == 'juice-shop/juice-shop' || github.repository != 'juice-shop/juice-shop' && matrix.os == 'ubuntu-latest' && matrix.node-version == '16'
uses: nick-invision/retry@45ba062d357edb3b29c4a94b456b188716f61020 #v2: 2.4.1 available
with:
timeout_minutes: 5
max_attempts: 3
command: |
if [ "$RUNNER_OS" == "Windows" ]; then
set NODE_ENV=test
else
export NODE_ENV=test
fi
npm run frisby
shell: bash
- name: "Copy API test coverage data"
run: cp build/reports/coverage/api-tests/lcov.info api-lcov.info
- name: "Upload API test coverage data"
if: github.repository == 'juice-shop/juice-shop' && github.event_name == 'push' && matrix.os == 'ubuntu-latest' && matrix.node-version == '16'
uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535 #v3: v3.0.0 available
with:
name: api-test-lcov
path: |
api-lcov.info
coverage-report:
needs: [test, api-test]
runs-on: ubuntu-latest
if: github.repository == 'juice-shop/juice-shop' && github.event_name == 'push'
steps:
- name: "Check out Git repository"
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f #v2: v2.3.4 available
- name: "Download unit test coverage data"
uses: actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741 #v3: v3.0.0 available
with:
name: unit-test-lcov
- name: "Download API test coverage data"
uses: actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741 #v3: v3.0.0 available
with:
name: api-test-lcov
- name: "Publish coverage to Codeclimate"
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
run: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
sed -i s/SF:/SF:frontend\\//g frontend-lcov.info
./cc-test-reporter format-coverage -t lcov -o codeclimate.frontend.json frontend-lcov.info
./cc-test-reporter format-coverage -t lcov -o codeclimate.server.json server-lcov.info
./cc-test-reporter format-coverage -t lcov -o codeclimate.api.json api-lcov.info
./cc-test-reporter sum-coverage codeclimate.*.json -p 3
./cc-test-reporter upload-coverage
shell: bash
custom-config-test:
runs-on: ubuntu-latest
steps:
- name: "Check out Git repository"
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f #v2: v2.3.4 available
- name: "Use Node.js 16"
uses: actions/setup-node@f1f314fca9dfce2769ece7d933488f076716723e #v1: v2.x available
with:
node-version: 16
- name: "Install CLI tools"
run: npm install -g @angular/cli@$ANGULAR_CLI_VERSION
- name: "Install application"
if: github.repository == 'juice-shop/juice-shop' || github.repository != 'juice-shop/juice-shop' && matrix.os == 'ubuntu-latest' && matrix.node-version == '16'
run: npm install
- name: "Execute server tests for each custom configuration"
uses: nick-invision/retry@45ba062d357edb3b29c4a94b456b188716f61020 #v2: 2.4.1 available
with:
timeout_minutes: 10
max_attempts: 3
command: >
NODE_ENV=7ms npm run test:server &&
NODE_ENV=addo npm run test:server &&
NODE_ENV=bodgeit npm run test:server &&
NODE_ENV=ctf npm run test:server &&
NODE_ENV=fbctf npm run test:server &&
NODE_ENV=juicebox npm run test:server &&
NODE_ENV=mozilla npm run test:server &&
NODE_ENV=oss npm run test:server &&
NODE_ENV=quiet npm run test:server &&
NODE_ENV=tutorial npm run test:server &&
NODE_ENV=unsafe npm run test:server
e2e:
runs-on: windows-latest
if: github.repository == 'juice-shop/juice-shop'
steps:
- name: "Check out Git repository"
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f #v2: v2.3.4 available
- name: "Use Node.js 16"
uses: actions/setup-node@f1f314fca9dfce2769ece7d933488f076716723e #v1: v2.x available
with:
node-version: 16
- name: "Install CLI tools"
run: npm install -g @angular/cli@$ANGULAR_CLI_VERSION
- name: "Install application"
if: github.repository == 'juice-shop/juice-shop' || github.repository != 'juice-shop/juice-shop' && matrix.os == 'ubuntu-latest' && matrix.node-version == '16'
run: npm install
- name: "Execute end-to-end tests"
env:
SOLUTIONS_WEBHOOK: ${{ secrets.E2E_SOLUTIONS_WEBHOOK }}
uses: nick-invision/retry@45ba062d357edb3b29c4a94b456b188716f61020 #v2: 2.4.1 available
with:
timeout_minutes: 20
max_attempts: 2
command: |
set NODE_ENV=test
set SOLUTIONS_WEBHOOK="$env:SOLUTIONS_WEBHOOK"
npm run preprotractor:github
npm run e2e
e2e-with-cypress:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
browser: [chrome] # FIXME Switch back to [chrome, firefox] after debugging extreme flakiness of Firefox on CI/CD
fail-fast: false
steps:
- name: "Check out Git repository"
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f #v2: v2.3.4 available
- name: "Use Node.js 16"
uses: actions/setup-node@f1f314fca9dfce2769ece7d933488f076716723e #v1: v2.x available
with:
node-version: 16
- name: "Install CLI tools"
run: npm install -g @angular/cli
- name: "Install application"
run: npm install
- name: "Execute end-to-end tests on Ubuntu"
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: cypress-io/github-action@c662a784116e1a26360c4e1fc0a90feedb4b5ed3 #v3.1.0
with:
install: false
browser: ${{ matrix.browser }}
start: npm start
wait-on: http://localhost:3000
record: true
group: ${{ matrix.browser }} @ ${{ matrix.os }}
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "Execute end-to-end tests on Mac"
if: ${{ matrix.os == 'macos-latest' }}
uses: cypress-io/github-action@c662a784116e1a26360c4e1fc0a90feedb4b5ed3 #v3.1.0
with:
install: false
browser: ${{ matrix.browser }}
start: npm start
wait-on: http://localhost:3000
record: true
group: ${{ matrix.browser }} @ ${{ matrix.os }}
env:
CYPRESS_CACHE_FOLDER: /Users/runner/Library/Caches/Cypress
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/upload-artifact@v2
if: failure()
with:
name: cypress-screenshots
path: cypress/screenshots
- uses: actions/upload-artifact@v2
if: always()
with:
name: cypress-videos
path: cypress/videos
e2e-in-subfolder:
runs-on: windows-latest
if: github.repository == 'juice-shop/juice-shop'
continue-on-error: true
steps:
- name: "Check out Git repository"
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f #v2: v2.3.4 available
- name: "Use Node.js 16"
uses: actions/setup-node@f1f314fca9dfce2769ece7d933488f076716723e #v1: v2.x available
with:
node-version: 16
- name: "Install CLI tools"
run: npm install -g @angular/cli@$ANGULAR_CLI_VERSION
- name: "Install application"
if: github.repository == 'juice-shop/juice-shop' || github.repository != 'juice-shop/juice-shop' && matrix.os == 'ubuntu-latest' && matrix.node-version == '16'
run: npm install
- name: "Execute end-to-end tests with application hosted in subfolder"
uses: nick-invision/retry@45ba062d357edb3b29c4a94b456b188716f61020 #v2: 2.4.1 available
with:
timeout_minutes: 20
max_attempts: 1
command: |
set NODE_ENV=test
npm run preprotractor:github
npm run e2e -- subfolder
smoke-test:
runs-on: ubuntu-latest
steps:
- name: "Check out Git repository"
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f #v2: v2.3.4 available
- name: "Use Node.js 16"
uses: actions/setup-node@f1f314fca9dfce2769ece7d933488f076716723e #v1: v2.x available
with:
node-version: 16
- name: "Install CLI tools"
run: |
npm install -g @angular/cli@$ANGULAR_CLI_VERSION
npm install -g grunt-cli
- name: "Set packaging options for Grunt"
run: |
echo "PCKG_OS_NAME=linux" >> $GITHUB_ENV
echo "PCKG_NODE_VERSION=14" >> $GITHUB_ENV
echo "PCKG_CPU_ARCH=x64" >> $GITHUB_ENV
- name: "Package application"
run: |
npm install --production
npm install -g grunt-cli
npm run package:ci
- name: "Unpack application archive"
run: |
cd dist
tar -zxf juice-shop-*.tgz
- name: "Execute smoke test"
run: |
cd dist/juice-shop_*
npm start &
cd ../..
chmod +x test/smoke/smoke-test.sh
test/smoke/smoke-test.sh http://localhost:3000
docker-test:
runs-on: ubuntu-latest
steps:
- name: "Check out Git repository"
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f #v2: v2.3.4 available
- name: "Execute smoke test on Docker"
run: docker-compose -f docker-compose.test.yml up --exit-code-from sut
docker:
if: github.repository == 'juice-shop/juice-shop' && github.event_name == 'push' && (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master')
needs: [test, api-test, e2e, e2e-with-cypress, e2e-in-subfolder, custom-config-test, docker-test]
runs-on: ubuntu-latest
steps:
- name: "Check out Git repository"
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f #v2: v2.3.4 available
- name: "Set up QEMU"
uses: docker/setup-qemu-action@27d0a4f181a40b142cce983c5393082c365d1480 #v1: V1.2.0 available
- name: "Set up Docker Buildx"
uses: docker/setup-buildx-action@94ab11c41e45d028884a99163086648e898eed25 #v1
- name: "Login to DockerHub"
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 #v1.10
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: "Set tag & labels for ${{ github.ref }}"
run: |
if [ "$GITHUB_REF" == "refs/heads/master" ]; then
echo "DOCKER_TAG=latest" >> $GITHUB_ENV
else
echo "DOCKER_TAG=snapshot" >> $GITHUB_ENV
fi
echo "VCS_REF=`git rev-parse --short HEAD`" >> $GITHUB_ENV
echo "BUILD_DATE=`date -u +”%Y-%m-%dT%H:%M:%SZ”`" >> $GITHUB_ENV
- name: "Build and push for AMD processors"
uses: docker/build-push-action@a66e35b9cbcf4ad0ea91ffcaf7bbad63ad9e0229 #note: newer is available
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
bkimminich/juice-shop:${{ env.DOCKER_TAG }}
build-args: |
VCS_REF=${{ env.VCS_REF }}
BUILD_DATE=${{ env.BUILD_DATE }}
- name: "Build and push for ARM processors"
uses: docker/build-push-action@a66e35b9cbcf4ad0ea91ffcaf7bbad63ad9e0229 #note: newer is available
with:
context: .
file: ./Dockerfile.arm
platforms: linux/arm/v7
push: true
tags: |
bkimminich/juice-shop:${{ env.DOCKER_TAG }}-arm
build-args: |
VCS_REF=${{ env.VCS_REF }}
BUILD_DATE=${{ env.BUILD_DATE }}
heroku:
if: github.repository == 'juice-shop/juice-shop' && github.event_name == 'push' && (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master')
needs: [test, api-test, e2e, e2e-with-cypress, e2e-in-subfolder, custom-config-test]
runs-on: ubuntu-latest
steps:
- name: "Check out Git repository"
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f #v2: v2.3.4 available
- name: "Set Heroku app & branch for ${{ github.ref }}"
run: |
if [ "$GITHUB_REF" == "refs/heads/master" ]; then
echo "HEROKU_APP=juice-shop" >> $GITHUB_ENV
echo "HEROKU_BRANCH=master" >> $GITHUB_ENV
else
echo "HEROKU_APP=juice-shop-staging" >> $GITHUB_ENV
echo "HEROKU_BRANCH=develop" >> $GITHUB_ENV
fi
- name: "Deploy ${{ github.ref }} to Heroku"
uses: akhileshns/heroku-deploy@79ef2ae4ff9b897010907016b268fd0f88561820 #v3.12.12
with:
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
heroku_app_name: ${{ env.HEROKU_APP }}
heroku_email: [email protected]
branch: ${{ env.HEROKU_BRANCH }}
notify-slack:
if: github.repository == 'juice-shop/juice-shop' && github.event_name == 'push' && (success() || failure())
needs:
- docker
- heroku
- lint
- coding-challenge-rsn
- smoke-test
- coverage-report
runs-on: ubuntu-latest
steps:
- name: "Slack workflow notification"
uses: Gamesight/slack-workflow-status@master
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
slack_webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}