-
-
Notifications
You must be signed in to change notification settings - Fork 3
269 lines (269 loc) · 9.23 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
name: "CI/CD Pipeline"
on:
push:
branches-ignore:
- l10n_develop
- gh-pages
paths-ignore:
- '*.md'
- 'LICENSE'
tags-ignore:
- '*'
pull_request:
paths-ignore:
- '*.md'
- 'LICENSE'
- 'data/static/i18n/*.json'
- 'frontend/src/assets/i18n/*.json'
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: "Check out Git repository"
uses: actions/checkout@v2
- name: "Use Node.js 14"
uses: actions/setup-node@v1
with:
node-version: 14
- name: "Install CLI tools"
run: npm install -g @angular/cli
- name: "Install application"
run: |
npm install --ignore-scripts
cd frontend
npm install --ignore-scripts
- 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
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [12, 14, 15]
steps:
- name: "Check out Git repository"
uses: actions/checkout@v2
- name: "Use Node.js ${{ matrix.node-version }}"
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: "Cache Node.js modules"
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- name: "Install CLI tools"
run: npm install -g @angular/cli
- name: "Install application"
run: npm install
- name: "Execute unit tests"
uses: nick-invision/retry@v2
with:
timeout_minutes: 10
max_attempts: 3
command: npm test
- name: "Execute integration tests"
uses: nick-invision/retry@v2
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: "Publish coverage to Codeclimate"
if: github.event_name == 'push' && matrix.os == 'ubuntu-latest' && matrix.node-version == '14'
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
run: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-0.7.0-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
sed -i s/SF:/SF:frontend\\//g build/reports/coverage/frontend-tests/lcov.info
./cc-test-reporter format-coverage -t lcov -o build/reports/coverage/codeclimate.frontend.json build/reports/coverage/frontend-tests/lcov.info
./cc-test-reporter format-coverage -t lcov -o build/reports/coverage/codeclimate.server.json build/reports/coverage/server-tests/lcov.info
./cc-test-reporter format-coverage -t lcov -o build/reports/coverage/codeclimate.api.json build/reports/coverage/api-tests/lcov.info
./cc-test-reporter sum-coverage build/reports/coverage/codeclimate.*.json -p 3
./cc-test-reporter upload-coverage
shell: bash
e2e:
runs-on: windows-latest
steps:
- name: "Check out Git repository"
uses: actions/checkout@v2
- name: "Use Node.js 14"
uses: actions/setup-node@v1
with:
node-version: 14
- name: "Install CLI tools"
run: npm install -g @angular/cli
- name: "Install application"
run: npm install
- name: "Execute end-to-end tests"
uses: nick-invision/retry@v2
continue-on-error: true
with:
timeout_minutes: 20
max_attempts: 2
command: |
set NODE_ENV=test
npm run protractor
e2e-in-subfolder:
runs-on: windows-latest
steps:
- name: "Check out Git repository"
uses: actions/checkout@v2
- name: "Use Node.js 14"
uses: actions/setup-node@v1
with:
node-version: 14
- name: "Install CLI tools"
run: npm install -g @angular/cli
- name: "Install application"
run: npm install
- name: "Execute end-to-end tests with application hosted in subfolder"
uses: nick-invision/retry@v2
continue-on-error: true
with:
timeout_minutes: 20
max_attempts: 2
command: |
set NODE_ENV=test
npm run preprotractor
npm run e2e -- subfolder
smoke:
runs-on: ubuntu-latest
steps:
- name: "Check out Git repository"
uses: actions/checkout@v2
- name: "Use Node.js 14"
uses: actions/setup-node@v1
with:
node-version: 14
- name: "Install CLI tools"
run: |
npm install -g @angular/cli
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@v2
- name: "Execute smoke test on Docker"
run: docker-compose -f docker-compose.test.yml up --exit-code-from sut
docker:
if: github.event_name == 'push' && (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master')
needs: [test, e2e, docker-test]
runs-on: ubuntu-latest
steps:
- name: "Check out Git repository"
uses: actions/checkout@v2
- name: "Set up QEMU"
uses: docker/setup-qemu-action@v1
- name: "Set up Docker Buildx"
uses: docker/setup-buildx-action@v1
- name: "Login to DockerHub"
uses: docker/login-action@v1
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"
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64
push: true
tags: |
bkimminich/juice-shop:${{ env.DOCKER_TAG }}
build-args: |
VCS_REF=${{ env.VCS_REF }}
BUILD_DATE=${{ env.BUILD_DATE }}
heroku:
if: github.event_name == 'push' && (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master')
needs: [test, e2e]
runs-on: ubuntu-latest
steps:
- name: "Check out Git repository"
uses: actions/checkout@v2
- 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@v3.7.8
with:
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
heroku_app_name: ${{ env.HEROKU_APP }}
heroku_email: bjoern.kimminich@owasp.org
branch: ${{ env.HEROKU_BRANCH }}
notify-slack:
if: github.event_name == 'push' && (success() || failure())
needs:
- docker
- heroku
- lint
- e2e-in-subfolder
- smoke
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 }}