-
Notifications
You must be signed in to change notification settings - Fork 0
419 lines (374 loc) · 15.2 KB
/
pullrequest.yml
File metadata and controls
419 lines (374 loc) · 15.2 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
name: Monorepo pipeline - pull request
on:
pull_request: {}
workflow_dispatch: {}
defaults:
run:
shell: bash
concurrency:
# See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-using-a-fallback-value
group: pullrequest-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
COMPOSE_HTTP_TIMEOUT: 180
SKIP_GENERATED_CACHE: ${{ contains(github.event.pull_request.labels.*.name, 'skip-generated-cache') }}
NX_AFFECTED_ALL: ${{ contains(github.event.pull_request.labels.*.name, 'nx-affected-all') }}
NX_SKIP_NX_CACHE: ${{ contains(github.event.pull_request.labels.*.name, 'skip-nx-cache') }}
DISABLE_CHUNKS: 'true'
DISABLE_GROUPING: 'false'
DISABLE_PROBLEMATIC: 'false'
CHUNK_SIZE: '8'
MAX_JOBS: '3'
NX_PARALLEL: '2'
NX_MAX_PARALLEL: '4'
NX_TASKS_RUNNER: ci
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
S3_DOCKER_CACHE_BUCKET: ${{ secrets.S3_DOCKER_CACHE_BUCKET }}
RUNS_ON_S3_BUCKET_CACHE: ${{ secrets.S3_DOCKER_CACHE_BUCKET }}
AWS_REGION: eu-west-1
GENERATED_FILES: ${{ github.sha }}.tar.gz
AFFECTED_ALL: ${{ secrets.AFFECTED_ALL }}
SERVERSIDE_FEATURES_ON: ''
DOCKER_REGISTRY: 821090935708.dkr.ecr.eu-west-1.amazonaws.com
DOCKER_BASE_IMAGE_REGISTRY: 821090935708.dkr.ecr.eu-west-1.amazonaws.com/ecr-public
CI_DEBUG: ${{ contains(github.event.pull_request.labels.*.name, 'ci debug') }}
SKIP_TESTS: ${{ contains(github.event.pull_request.labels.*.name, 'test nothing') }}
DEPLOY_FEATURE: ${{ contains(github.event.pull_request.labels.*.name, 'deploy-feature') }}
CYPRESS_CACHE_FOLDER: ${{ github.workspace }}/.cypress-cache
YARN_ENABLE_HARDENED_MODE: '0'
jobs:
prepare:
uses: ./.github/workflows/install.yml
secrets: inherit
with:
main_branch: ${{ github.base_ref }}
tests:
needs:
- prepare
if: ${{ needs.prepare.outputs.TEST_CHUNKS && needs.prepare.outputs.DEPLOY_FEATURE == 'false' }}
runs-on: arc-shared
timeout-minutes: 45
env:
AFFECTED_PROJECTS: ${{ matrix.projects }}
NX_BASE: ${{ needs.prepare.outputs.NX_BASE }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.prepare.outputs.TEST_CHUNKS) }}
steps:
- name: checkout
uses: actions/checkout@v4
- name: Setup yarn
uses: ./.github/actions/setup-yarn
with:
RUNS_ON_S3_BUCKET_CACHE: ${{ secrets.S3_DOCKER_CACHE_BUCKET }}
- name: load-deps
uses: ./.github/actions/load-deps
- name: Run unit tests
uses: ./.github/actions/unit-test
with:
dd-api-key: '${{ secrets.DD_API_KEY }}'
codecov-token: ${{ secrets.CODECOV_TOKEN }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
docker-registry: 821090935708.dkr.ecr.eu-west-1.amazonaws.com/
unicorn-tests:
name: All projects have some tests
needs:
- prepare
if: ${{ needs.prepare.outputs.TEST_CHUNKS && needs.prepare.outputs.DEPLOY_FEATURE == 'false' && needs.prepare.outputs.is-unicorn == 'true' }}
runs-on: arc-shared
env:
CHUNKS: ${{ needs.prepare.outputs.TEST_CHUNKS }}
NX_BASE: ${{ needs.prepare.outputs.NX_BASE }}
NX_HEAD: ${{ needs.prepare.outputs.NX_HEAD }}
steps:
- name: checkout
uses: actions/checkout@v4
with:
# Need full repo for Nx to find the commits at NX_* below
fetch-depth: 0
- name: Setup yarn
uses: ./.github/actions/setup-yarn
with:
RUNS_ON_S3_BUCKET_CACHE: ${{ secrets.S3_DOCKER_CACHE_BUCKET }}
- name: load-deps
uses: ./.github/actions/load-deps
- name: Find unicorn projects
id: unicorn
run: |
unicorns=$(node scripts/ci/unicorn-utils.mjs show-unicorns --json)
jq -ncr --argjson chunks "$CHUNKS" --argjson unicorns "$unicorns" '
[
$chunks.projects
| .[]
| select( . | IN( $unicorns | .[] ) )
]
| "projects=\(. | join(","))"
' | tee -a "$GITHUB_OUTPUT"
- name: Verify that projects have some tests
env:
projects: ${{ steps.unicorn.outputs.projects }}
run: |
# Get list of tests, with `<project-name>: ` prefixed (stream style, without cache), grouping by unique prefixes (sorted)
yarn nx run-many -t test --skip-nx-cache --output-style=stream --projects="${projects}" --parallel --verbose -- --listTests |
grep -P "^(${projects//,/|}): " | cut -d':' -f1 | sort -u > /tmp/projects-with-tests
# Get affected projects sorted
echo -e "${projects}" | sed 's/,/\n/g' | sort -u > /tmp/projects-all
if ! d=$(diff /tmp/projects-with-tests /tmp/projects-all); then
echo "These projects don't have any tests:"
echo "${d}"
exit 1
fi
echo "All projects ($projects) have tests."
e2e:
needs:
- prepare
if: ${{ needs.prepare.outputs.E2E_CHUNKS && needs.prepare.outputs.DEPLOY_FEATURE == 'false' }}
runs-on: arc-shared
timeout-minutes: 45
env:
AFFECTED_PROJECT: ${{ matrix.projects }}
CYPRESS_PROJECT_ID: 4q7jz8
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
API_MOCKS: 'true'
NODE_OPTIONS: --max-old-space-size=4096
E2E_BUILD_ID: '${{ needs.prepare.outputs.E2E_BUILD_ID }}-${{ github.run_attempt }}'
NX_BASE: ${{ needs.prepare.outputs.NX_BASE }}
AFFECTED_PROJECTS: ${{ matrix.projects }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.prepare.outputs.E2E_CHUNKS) }}
steps:
- name: checkout
uses: actions/checkout@v4
- name: Setup yarn
uses: ./.github/actions/setup-yarn
with:
RUNS_ON_S3_BUCKET_CACHE: ${{ secrets.S3_DOCKER_CACHE_BUCKET }}
- name: load-deps
uses: ./.github/actions/load-deps
- name: Running e2e tests
run: yarn nx run-many --target=e2e --projects="${AFFECTED_PROJECTS}" --parallel 3
linting-workspace:
needs:
- prepare
runs-on: arc-shared
timeout-minutes: 15
steps:
- name: checkout
uses: actions/checkout@v4
- name: Setup yarn
uses: ./.github/actions/setup-yarn
with:
RUNS_ON_S3_BUCKET_CACHE: ${{ secrets.S3_DOCKER_CACHE_BUCKET }}
- name: load-deps
uses: ./.github/actions/load-deps
- name: Linting workspace
run: ./scripts/ci/20_lint-workspace.sh
run-shellcheck:
needs:
- prepare
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- uses: reviewdog/action-shellcheck@v1
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-review
fail_level: info
exclude: >-
*/node_modules/*
formatting:
needs:
- prepare
runs-on: arc-shared
timeout-minutes: 15
env:
NX_BASE: ${{ needs.prepare.outputs.NX_BASE }}
steps:
- uses: actions/checkout@v4
if: ${{ github.event_name == 'pull_request' }}
with:
token: ${{ secrets.DIRTY_FIX_BOT_TOKEN }}
ref: ${{ github.event.pull_request.head.ref }}
- name: Setup yarn
uses: ./.github/actions/setup-yarn
with:
RUNS_ON_S3_BUCKET_CACHE: ${{ secrets.S3_DOCKER_CACHE_BUCKET }}
- name: load-deps
uses: ./.github/actions/load-deps
- name: NX format:check
if: ${{ github.ref == 'ref/heads/main' }}
run: ./scripts/ci/20_check-formatting.sh "check"
# - name: NX format:write
# if: ${{ github.event_name == 'pull_request' }}
# run: |
# ./scripts/ci/20_check-formatting.sh "write"
# ./infra/scripts/ci/git-check-dirty.sh "/" "nx format:write" "dirtybot"
lintfix-changed-files:
name: Lintfix Changed Files
runs-on: arc-shared
if: ${{ !contains(github.event.pull_request.labels.*.name, 'dirty bypass') }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
# Need full repo for Nx to find the commits at NX_* below
fetch-depth: 0
token: ${{ secrets.DIRTY_FIX_BOT_TOKEN }}
# Need ref to know where to push to
# https://github.com/actions/checkout#push-a-commit-to-a-pr-using-the-built-in-token
ref: ${{ github.event.pull_request.head.ref }}
- name: Setup yarn
uses: ./.github/actions/setup-yarn
with:
RUNS_ON_S3_BUCKET_CACHE: ${{ secrets.S3_DOCKER_CACHE_BUCKET }}
- name: Run lintfix
id: lintfix
# NOTE: We want to use the PR base, not last good, since the lint is not part of "good" build
# and causes unintended lint changes when using a different commit
run: |
yarn nx affected -t lint --base="origin/$GITHUB_BASE_REF" --fix
if ! git diff "$GITHUB_BASE_REF" --exit-code; then
echo "FILES_CHANGED=true" | tee -a "$GITHUB_OUTPUT"
fi
- name: Commit changed files
if: ${{ steps.lintfix.outputs.FILES_CHANGED == 'true' }}
run: ./infra/scripts/ci/git-check-dirty.sh . lintfix dirtybot
linting:
needs:
- prepare
runs-on: arc-shared
timeout-minutes: 35
if: needs.prepare.outputs.LINT_CHUNKS
env:
AFFECTED_PROJECTS: ${{ matrix.projects }}
NODE_OPTIONS: --max-old-space-size=4096
NX_BASE: ${{ needs.prepare.outputs.NX_BASE }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.prepare.outputs.LINT_CHUNKS) }}
steps:
- name: checkout
uses: actions/checkout@v4
- name: Setup yarn
uses: ./.github/actions/setup-yarn
with:
RUNS_ON_S3_BUCKET_CACHE: ${{ secrets.S3_DOCKER_CACHE_BUCKET }}
- name: load-deps
uses: ./.github/actions/load-deps
- name: Lint head
id: lint-head
run: |
set -euo pipefail
lints=$(mktemp -t lint-head.XXXXXX)
echo "lints-file=$lints" | tee -a "$GITHUB_OUTPUT"
yarn nx run-many -t lint --output-style=static --projects "$AFFECTED_PROJECTS" |
tee -a "$lints" | # Show output when running, but preserve pipe-chaining
(grep -oP '(?<=✖ )(\d+)(?= problems)' || echo '0') | # Find number of problems
awk '{ SUM += $1} END { SUM /= 2; printf "lint-count=%d", SUM }' | # sum number of problems, divide by 2 because each problem summary occurs twice
tee -a "$GITHUB_OUTPUT" # Finally create output
# Checkout for linting base
- uses: actions/checkout@v4
if: ${{ !contains(github.event.pull_request.labels.*.name, 'dirty bypass') }}
with:
ref: ${{ github.event.pull_request.base.ref }}
clean: false
- name: Lint base
if: ${{ !contains(github.event.pull_request.labels.*.name, 'dirty bypass') }}
id: lint-base
run: |
set -euo pipefail
lints=$(mktemp -t lint-base.XXXXXX)
echo "lints-file=$lints" | tee -a "$GITHUB_OUTPUT"
yarn nx run-many -t lint --output-style=static --projects "$AFFECTED_PROJECTS" |
tee -a "$lints" | # Show output when running, but preserve pipe-chaining
(grep -oP '(?<=✖ )(\d+)(?= problems)' || echo '0') | # Find number of problems
awk '{ SUM += $1} END { SUM /= 2; printf "lint-count=%d", SUM }' | # sum number of problems, divide by 2 because each problem summary occurs twice
tee -a "$GITHUB_OUTPUT" # Finally create output
- name: No new lints
if: ${{ !contains(github.event.pull_request.labels.*.name, 'dirty bypass') }}
env:
HEAD_LINT_COUNT: ${{steps.lint-head.outputs.lint-count}}
BASE_LINT_COUNT: ${{steps.lint-base.outputs.lint-count}}
HEAD_LINT_FILE: ${{steps.lint-head.outputs.lints-file}}
BASE_LINT_FILE: ${{steps.lint-base.outputs.lints-file}}
run: |
# Get `<filename> #lints: <n>` lines for easy diff
for f in "${BASE_LINT_FILE}" "${HEAD_LINT_FILE}"; do
# Make "Remote cache..." and "Local cache" be the same
sed -i -E 's/\s*\[[^[]*cache[^]]*\]\s*//g' "${f}" || echo "No cached targets found in $f"
grep -oP "(?<=$PWD/).*" "${f}" | sort -n | uniq -c | awk '{print($2 " #lints: " $1)}' > "${f}_files.out" || { echo "No lints found in $f"; }
done
NEW_LINTS=$(comm -13 "${BASE_LINT_FILE}_files.out" "${HEAD_LINT_FILE}_files.out" | wc -l) || { echo "Failed comparing output files"; exit 1; }
COUNT_DIFF=$(( HEAD_LINT_COUNT - BASE_LINT_COUNT )) || :
if (( COUNT_DIFF <= 0 && NEW_LINTS == 0 )); then
echo "Lint count has not increased (𝚫=$COUNT_DIFF)"
exit 0
fi
echo "::error title=NEW_LINTS::Please fix your lints 🙏 (found $NEW_LINTS additional lints)"
echo "Files with changed lints:"
diff "${BASE_LINT_FILE}_files.out" "${HEAD_LINT_FILE}_files.out" || :
echo "::group::lintdiff"
diff "${BASE_LINT_FILE}" "${HEAD_LINT_FILE}" || : # Ignore diff exit code
echo "::endgroup::"
exit 1
build:
needs:
- prepare
runs-on: arc-shared
timeout-minutes: 35
env:
AFFECTED_PROJECTS: ${{ matrix.projects }}
NX_BASE: ${{ needs.prepare.outputs.NX_BASE }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.prepare.outputs.BUILD_CHUNKS) }}
if: ${{ needs.prepare.outputs.BUILD_CHUNKS && needs.prepare.outputs.DEPLOY_FEATURE == 'false' }}
steps:
- name: checkout
uses: actions/checkout@v4
- name: Setup yarn
uses: ./.github/actions/setup-yarn
with:
RUNS_ON_S3_BUCKET_CACHE: ${{ secrets.S3_DOCKER_CACHE_BUCKET }}
- name: load-deps
uses: ./.github/actions/load-deps
- name: Building
run: ./scripts/ci/run-in-parallel-native.sh build
success:
runs-on: arc-shared
if: ${{ !cancelled() }}
needs:
- prepare
- linting-workspace
- tests
- linting
- run-shellcheck
- formatting
- e2e
- build
- unicorn-tests
steps:
- name: Notify about deploy-feature label
if: ${{ github.event.pull_request.auto_merge && needs.prepare.outputs.DEPLOY_FEATURE == 'true' }}
run: |
echo "- 👉 Remove the \`deploy-feature\` label if you want this PR to be merged automatically" >> $GITHUB_STEP_SUMMARY
exit 1
- name: Collect
env:
NEEDS: ${{ toJSON(needs) }}
run: |
# "failed" here is everything that wasn't successful or skipped (e.g. "failuer", "cancelled")
failed_dependencies=$(jq -nr --argjson needs "$NEEDS" ' $needs | with_entries(select(.value.result != "success" and .value.result != "skipped")) ')
echo -n "Did any dependency fail? "
if jq -ne --argjson failures "$failed_dependencies" '$failures | length > 0'; then
failure_statuses=$(jq -nr --argjson failures "$failed_dependencies" '[ $failures | to_entries | .[] | "\(.key) (\(.value.result))" ] | join(", ")')
echo "::error title=NEEDS::Some dependencies failed: $failure_statuses"
exit 1
fi
echo "::info title=NEEDS::No failing dependencies 🎉"
exit 0
- name: Announce success
run: echo "Build is successful"