-
Notifications
You must be signed in to change notification settings - Fork 21
/
config.yml
343 lines (333 loc) · 11 KB
/
config.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
version: 2.1
parameters:
workflow_to_run:
type: enum
enum:
- build-deploy
- integration-tests-staging
- integration-tests-alpha
default: build-deploy
orbs:
slack: circleci/slack@3.4.2
sonarcloud: sonarsource/sonarcloud@1.0.3
executors:
node:
working_directory: /mnt/ramdisk
docker:
- image: cimg/node:18.10
puppeteer:
working_directory: /mnt/ramdisk
docker:
- image: cimg/node:18.10-browsers
gcloud:
working_directory: /mnt/ramdisk
docker:
- image: google/cloud-sdk:alpine
anchors:
filter-pr-branch: &filter-pr-branch
filters:
branches:
ignore: dev
filter-dev-branch: &filter-dev-branch
filters:
branches:
only: dev
commands:
notify-github: # borrows from https://circleci.com/developer/orbs/orb/mmnfst/github-deployments#orb-source
parameters:
env:
type: string
pr:
type: boolean
existing:
type: boolean
default: false
steps:
- unless:
condition: << parameters.existing >>
steps:
- run:
name: Notify Github of deployment
unless: << parameters.existing >>
command: |
set +e -x # don't allow a failure here to fail the job, print steps when running them
apk add github-cli jq --no-progress --repository=https://dl-cdn.alpinelinux.org/alpine/latest-stable/community/
<<# parameters.pr >>
VERSION="pr-$(expr "${CIRCLE_PR_NUMBER:-${CIRCLE_PULL_REQUEST##*/}}" % $NUM_PR_SITES)"
<</ parameters.pr >><<^ parameters.pr >>
VERSION="<< parameters.env >>"
<</ parameters.pr >>
# until https://github.com/cli/cli/issues/1484 is resolved, pass json input:
echo "{\"ref\": \"$CIRCLE_BRANCH\", \"environment\": \"$VERSION\", \"auto_merge\": false, \"required_contexts\": []}" > /tmp/request.json
# echo the complete response while saving it
RESPONSE=$(gh api repos/databiosphere/terra-ui/deployments -H "Authorization: token $GITHUB_TOKEN" --input /tmp/request.json | tee >(jq . > /dev/tty))
# parse the part we want for later
echo $RESPONSE | jq .id | tee /tmp/build_num
- when:
condition: << parameters.existing >>
steps:
- run:
name: Update Github deployment status
command: |
set +e -x # don't allow a failure here to fail the job, print steps when running them
<<# parameters.pr >>
PR_SLUG="pr-$(expr "${CIRCLE_PR_NUMBER:-${CIRCLE_PULL_REQUEST##*/}}" % $NUM_PR_SITES)-dot-"
<</ parameters.pr >>
RESPONSE=$(gh api "repos/databiosphere/terra-ui/deployments/$(cat /tmp/build_num)/statuses" -H "Authorization: token $GITHUB_TOKEN" \
-F state=success -F environment_url="https://${PR_SLUG}bvdp-saturn-<< parameters.env >>.appspot.com" -F log_url="$CIRCLE_BUILD_URL")
echo $RESPONSE
- run:
name: Update Github deployment status
when: on_fail
command: |
gh api "repos/databiosphere/terra-ui/deployments/$(cat /tmp/build_num)/statuses" -H "Authorization: token $GITHUB_TOKEN" -F state=failure
deploy-env:
description: "Deploy to a specific environment"
parameters:
sa_key_var:
type: env_var_name
default: "SA_KEY_JSON"
env:
type: enum
enum: [dev, staging, alpha]
default: dev
pr:
type: boolean
default: false
steps:
- when:
condition: << parameters.pr >>
steps:
- run:
name: Check for PR number
command: |
if [[ -z "${CIRCLE_PR_NUMBER:-${CIRCLE_PULL_REQUEST##*/}}" ]]; then
echo "No PR number, not deploying"
circleci-agent step halt
fi
- attach_workspace:
at: .
- run: cp config/<< parameters.env >>.json build/config.json
- run: echo "$<< parameters.sa_key_var >>" > /tmp/sa.json
- run: gcloud auth activate-service-account --key-file=/tmp/sa.json
- notify-github:
env: << parameters.env >>
pr: << parameters.pr >>
- when:
condition: << parameters.pr >>
steps:
- run:
name: Deploy PR
command: |
CIRCLE_PR_NUMBER="${CIRCLE_PR_NUMBER:-${CIRCLE_PULL_REQUEST##*/}}"
if [[ ! -z "$CIRCLE_PR_NUMBER" ]]; then
gcloud app deploy \
--project=bvdp-saturn-<< parameters.env >> \
--version="pr-$(expr "$CIRCLE_PR_NUMBER" % $NUM_PR_SITES)" \
--no-promote --quiet
fi
- unless:
condition: << parameters.pr >>
steps:
- run:
name: Deploy << parameters.env >>
command: gcloud app deploy --project=bvdp-saturn-<< parameters.env >> --promote --quiet
- notify-github:
existing: true
env: << parameters.env >>
pr: << parameters.pr >>
integration-tests:
parameters:
local:
type: boolean
default: false
env:
type: enum
enum: [ staging, alpha ]
default: staging
log_dir:
type: string
default: "/tmp"
steps:
- checkout
- attach_workspace:
at: .
- restore_cache:
keys:
- deps-{{ .Branch }}-{{ checksum ".pnp.cjs" }}
- run:
working_directory: integration-tests
command: yarn install --immutable-cache
- when:
condition: << parameters.local >>
steps:
- run: cp config/<< parameters.env >>.json build/config.json
- run:
command: npx serve build -l 3000
background: true
- run: timeout 120 bash -c "until nc -z localhost 3000; do sleep 3; done"
- run:
working_directory: integration-tests
name: Running UI integration tests
environment:
LOG_DIR: "<< parameters.log_dir >>/<< parameters.env >>/test-results"
JEST_JUNIT_OUTPUT_DIR: "<< parameters.log_dir >>/<< parameters.env >>/test-results/junit"
SCREENSHOT_DIR: "<< parameters.log_dir >>/<< parameters.env >>/test-results/failure-screenshots"
ENVIRONMENT: << parameters.env >>
no_output_timeout: 16m
command: |
mkdir -p ${SCREENSHOT_DIR}
TESTS_TO_RUN=$(yarn run jest --listTests | sed "s|$(pwd)/||" | circleci tests split --split-by=timings)
<<# parameters.local >>
export TEST_URL=http://localhost:3000
<</ parameters.local >>
yarn test $TESTS_TO_RUN --maxWorkers=2
- store_test_results:
path: << parameters.log_dir >>/<< parameters.env >>/test-results/junit
- store_artifacts:
path: << parameters.log_dir >>/<< parameters.env >>/test-results
destination: results
- run:
working_directory: integration-tests
name: Slack notification on dev branch only
command: |
if [ "$CIRCLE_NODE_INDEX" -eq 0 ] && [ "$CIRCLE_BRANCH" = "dev" ]; then
bash ../.circleci/wait-for-job-finish.sh
node --require ../.pnp.cjs ./slack/notify-circleci-test-results.js
fi
when: always
notify-qa:
parameters:
channel:
type: string
default: ""
steps:
- slack/status:
channel: << parameters.channel >>
include_job_number_field: false
include_project_field: false
failure_message: ":sadpanda: $CIRCLE_JOB failed."
success_message: ":circleci-pass: $CIRCLE_JOB ran successfully."
jobs:
build:
executor: node
resource_class: large
steps:
- checkout
- restore_cache:
keys:
- deps-{{ .Branch }}-{{ checksum ".pnp.cjs" }}
- run: yarn install --immutable-cache
- run: yarn eslint --max-warnings=0 .
- run: yarn test --coverage --maxWorkers=2
- run: yarn check-types
- run: DISABLE_ESLINT_PLUGIN=true yarn build # already linted above
- save_cache:
key: deps-{{ .Branch }}-{{ checksum ".pnp.cjs" }}
paths:
- .yarn/unplugged
- node_modules/.cache
- run: tar -czf build.tgz .gcloudignore app.yaml build config
- store_artifacts:
path: build.tgz
- persist_to_workspace:
root: .
paths:
- .gcloudignore
- app.yaml
- build
- config
- sonarcloud/scan
deploy-pr:
executor: gcloud
steps:
- deploy-env:
pr: true
deploy-dev:
executor: gcloud
steps:
- deploy-env
deploy-alpha:
executor: gcloud
steps:
- deploy-env:
sa_key_var: "ALPHA_SA_KEY_JSON"
env: "alpha"
- notify-qa:
channel: "C7H40L71D" # dsde-qa-notify
deploy-staging:
executor: gcloud
steps:
- deploy-env:
sa_key_var: "STAGING_SA_KEY_JSON"
env: "staging"
- notify-qa:
channel: "C7H40L71D" # dsde-qa-notify
integration-tests-pr-staging:
executor: puppeteer
parallelism: 4
steps:
- integration-tests:
local: true
env: staging
integration-tests-alpha:
executor: puppeteer
parallelism: 4
steps:
- integration-tests:
env: alpha
integration-tests-staging:
executor: puppeteer
parallelism: 4
steps:
- integration-tests:
env: staging
workflows:
version: 2
build-deploy:
when:
equal: [build-deploy, << pipeline.parameters.workflow_to_run >>]
jobs:
- build
- integration-tests-pr-staging:
<<: *filter-pr-branch
requires:
- build
- deploy-pr:
<<: *filter-pr-branch
requires:
- build
- deploy-dev:
<<: *filter-dev-branch
requires:
- build
- deploy-alpha:
<<: *filter-dev-branch
requires:
- build
- deploy-staging:
<<: *filter-dev-branch
requires:
- build
- integration-tests-staging:
<<: *filter-dev-branch
requires:
- deploy-staging
integration-tests-staging:
when:
equal: [integration-tests-staging, << pipeline.parameters.workflow_to_run >>]
jobs:
- integration-tests-staging
integration-tests-alpha:
when:
equal: [integration-tests-alpha, << pipeline.parameters.workflow_to_run >>]
jobs:
- integration-tests-alpha
nightly-integration-tests:
triggers:
- schedule:
<<: *filter-dev-branch
cron: "0 13 * * *"
jobs:
- integration-tests-alpha
- integration-tests-staging