-
-
Notifications
You must be signed in to change notification settings - Fork 0
443 lines (442 loc) · 14.4 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
# Continuous Integration
#
# References:
#
# - https://docs.github.com/actions/learn-github-actions/contexts
# - https://docs.github.com/actions/learn-github-actions/expressions
# - https://docs.github.com/actions/using-jobs/using-a-matrix-for-your-jobs
# - https://docs.github.com/actions/using-workflows/events-that-trigger-workflows#pull_request
# - https://docs.github.com/actions/using-workflows/events-that-trigger-workflows#push
# - https://docs.github.com/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch
# - https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions
# - https://docs.github.com/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request
# - https://docs.github.com/webhooks-and-events/webhooks/webhook-events-and-payloads#push
# - https://docs.github.com/webhooks-and-events/webhooks/webhook-events-and-payloads#workflow_dispatch
# - https://github.com/GitGuardian/ggshield-action
# - https://github.com/actions/cache
# - https://github.com/actions/cache/discussions/650
# - https://github.com/actions/checkout
# - https://github.com/actions/setup-node
# - https://github.com/actions/setup-node/blob/main/docs/advanced-usage.md#yarn2-configuration
# - https://github.com/actions/upload-artifact
# - https://github.com/andstor/file-existence-action
# - https://github.com/codecov/codecov-action
# - https://github.com/flex-development/grease
# - https://github.com/hmarr/debug-action
# - https://yarnpkg.com/cli/pack
---
name: ci
on:
pull_request:
push:
branches:
- feat/**
- hotfix/**
- main
workflow_dispatch:
permissions:
contents: read
packages: read
env:
CACHE_PATH: node_modules
GITHUB_TOKEN: ${{ secrets.GH_REGISTRY_TOKEN }}
HUSKY: 0
REF: ${{ github.head_ref || github.ref }}
REF_NAME: ${{ github.head_ref || github.ref_name }}
SHA: ${{ github.event.pull_request.head.sha || github.sha }}
concurrency:
cancel-in-progress: true
group: ${{ github.workflow }}-${{ github.ref }}
jobs:
preflight:
if: |
github.event.head_commit.author.name != 'dependabot[bot]'
&& github.event.head_commit.author.username != 'flexdevelopment[bot]'
&& !startsWith(github.event.head_commit.message, 'release:')
&& !startsWith(github.event.head_commit.message, 'release(chore):')
runs-on: ubuntu-latest
outputs:
cache-key: ${{ steps.cache-key.outputs.result }}
version: ${{ steps.version.outputs.result }}
version-typescript: ${{ steps.version-typescript.outputs.result }}
steps:
- id: debug
name: Print environment variables and event payload
uses: hmarr/debug-action@v3.0.0
- id: checkout
name: Checkout ${{ env.REF_NAME }}
uses: actions/checkout@v4.1.7
with:
persist-credentials: false
ref: ${{ env.REF }}
- id: node
name: Setup Node.js
uses: actions/setup-node@v4.0.3
with:
cache: yarn
cache-dependency-path: yarn.lock
node-version-file: .nvmrc
- id: yarn
name: Install dependencies
env:
YARN_ENABLE_IMMUTABLE_INSTALLS: ${{ github.actor != 'dependabot[bot]' }}
run: yarn
- id: cache-key
name: Get cache key
run: echo "result=${{ runner.os }}-${{ github.run_id }}" >>$GITHUB_OUTPUT
- id: cache
name: Cache dependencies
uses: actions/cache@v4.0.2
with:
key: ${{ steps.cache-key.outputs.result }}
path: ${{ env.CACHE_PATH }}
- id: version
name: Get manifest version
run: echo "result=$(jq .version package.json -r)" >>$GITHUB_OUTPUT
- id: version-typescript
name: Get TypeScript version
run: echo "result=$(jq .devDependencies.typescript package.json -r)" >>$GITHUB_OUTPUT
commitlint:
needs: preflight
runs-on: ubuntu-latest
steps:
- id: checkout
name: Checkout ${{ env.REF_NAME }}
uses: actions/checkout@v4.1.7
with:
fetch-depth: 0
persist-credentials: false
ref: ${{ env.REF }}
- id: node
name: Setup Node.js
uses: actions/setup-node@v4.0.3
with:
cache: yarn
cache-dependency-path: yarn.lock
node-version-file: .nvmrc
- id: cache
name: Restore dependencies cache
uses: actions/cache@v4.0.2
with:
key: ${{ needs.preflight.outputs.cache-key }}
path: ${{ env.CACHE_PATH }}
- id: lint
name: Check commitlint status
if: github.run_number != '1'
run: yarn commitlint --from $SHA~${{ github.event.pull_request.commits || 1 }} --to $SHA
gitguardian:
needs: commitlint
runs-on: ubuntu-latest
steps:
- id: checkout
name: Checkout ${{ env.REF_NAME }}
uses: actions/checkout@v4.1.7
with:
fetch-depth: 0
persist-credentials: false
ref: ${{ env.REF }}
- id: scan
name: Scan commits for secrets and policy breaches
uses: GitGuardian/ggshield-action@master
env:
GITGUARDIAN_API_KEY: ${{ secrets.GITGUARDIAN_API_KEY }}
GITHUB_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
GITHUB_PULL_BASE_SHA: ${{ github.event.pull_request.base.sha }}
GITHUB_PUSH_BASE_SHA: ${{ github.event.base }}
GITHUB_PUSH_BEFORE_SHA: ${{ github.event.before }}
with:
args: --all-policies --show-secrets --verbose
format:
needs:
- commitlint
- gitguardian
- preflight
runs-on: ubuntu-latest
steps:
- id: checkout
name: Checkout ${{ env.REF_NAME }}
uses: actions/checkout@v4.1.7
with:
persist-credentials: false
ref: ${{ env.REF }}
- id: node
name: Setup Node.js
uses: actions/setup-node@v4.0.3
with:
cache: yarn
cache-dependency-path: yarn.lock
node-version-file: .nvmrc
- id: cache
name: Restore dependencies cache
uses: actions/cache@v4.0.2
with:
key: ${{ needs.preflight.outputs.cache-key }}
path: ${{ env.CACHE_PATH }}
- id: format
name: Check code formatting
run: yarn check:format
lint:
needs:
- commitlint
- gitguardian
- preflight
runs-on: ubuntu-latest
steps:
- id: checkout
name: Checkout ${{ env.REF_NAME }}
uses: actions/checkout@v4.1.7
with:
persist-credentials: false
ref: ${{ env.REF }}
- id: node
name: Setup Node.js
uses: actions/setup-node@v4.0.3
with:
cache: yarn
cache-dependency-path: yarn.lock
node-version-file: .nvmrc
- id: cache
name: Restore dependencies cache
uses: actions/cache@v4.0.2
with:
key: ${{ needs.preflight.outputs.cache-key }}
path: ${{ env.CACHE_PATH }}
- id: lint
name: Check lint status
run: yarn check:lint
spelling:
needs:
- commitlint
- gitguardian
- preflight
runs-on: ubuntu-latest
steps:
- id: checkout
name: Checkout ${{ env.REF_NAME }}
uses: actions/checkout@v4.1.7
with:
persist-credentials: false
ref: ${{ env.REF }}
- id: node
name: Setup Node.js
uses: actions/setup-node@v4.0.3
with:
cache: yarn
cache-dependency-path: yarn.lock
node-version-file: .nvmrc
- id: cache
name: Restore dependencies cache
uses: actions/cache@v4.0.2
with:
key: ${{ needs.preflight.outputs.cache-key }}
path: ${{ env.CACHE_PATH }}
- id: spelling
name: Check spelling
run: yarn check:spelling
typescript:
needs:
- commitlint
- gitguardian
- preflight
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
typescript-version:
- ${{ needs.preflight.outputs.version-typescript }}
- 5.4.5
- 5.3.3
- latest
steps:
- id: checkout
name: Checkout ${{ env.REF_NAME }}
uses: actions/checkout@v4.1.7
with:
persist-credentials: false
ref: ${{ env.REF }}
- id: test-files-check
name: Check for typecheck files
uses: andstor/file-existence-action@v3.0.0
with:
files: '**/__tests__/*.spec-d.ts'
- id: node
if: steps.test-files-check.outputs.files_exists == 'true'
name: Setup Node.js
uses: actions/setup-node@v4.0.3
with:
cache: yarn
cache-dependency-path: yarn.lock
node-version-file: .nvmrc
- id: cache
if: steps.test-files-check.outputs.files_exists == 'true'
name: Restore dependencies cache
uses: actions/cache@v4.0.2
with:
key: ${{ needs.preflight.outputs.cache-key }}
path: ${{ env.CACHE_PATH }}
- id: typescript
if: steps.test-files-check.outputs.files_exists == 'true'
name: Install typescript@${{ matrix.typescript-version }}
run: yarn add -D typescript@${{ matrix.typescript-version }}
- id: print-typescript-version
if: steps.test-files-check.outputs.files_exists == 'true'
name: Print TypeScript version
run: jq .devDependencies.typescript package.json -r
- id: typecheck
if: steps.test-files-check.outputs.files_exists == 'true'
name: Run typecheck
run: yarn typecheck
test:
needs:
- commitlint
- gitguardian
- preflight
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version:
- 20
- 19
- 18
steps:
- id: checkout
name: Checkout ${{ env.REF_NAME }}
uses: actions/checkout@v4.1.7
with:
persist-credentials: false
ref: ${{ env.REF }}
- id: test-files-check
name: Check for test files
uses: andstor/file-existence-action@v3.0.0
with:
files: '**/__tests__/*.spec.+(ts|tsx)'
- id: node
if: steps.test-files-check.outputs.files_exists == 'true'
name: Setup Node.js v${{ matrix.node-version }}
uses: actions/setup-node@v4.0.3
with:
cache: yarn
cache-dependency-path: yarn.lock
check-latest: true
node-version: ${{ matrix.node-version }}
- id: cache
if: steps.test-files-check.outputs.files_exists == 'true'
name: Restore dependencies cache
uses: actions/cache@v4.0.2
with:
key: ${{ needs.preflight.outputs.cache-key }}
path: ${{ env.CACHE_PATH }}
- id: test
if: steps.test-files-check.outputs.files_exists == 'true'
name: Run tests
run: yarn test:cov
- id: codecov
name: Upload coverage report to Codecov
if: steps.test-files-check.outputs.files_exists == 'true'
uses: codecov/codecov-action@v4.5.0
env:
GITHUB_JOB: ${{ github.job }}
GITHUB_REF: ${{ github.ref }}
GITHUB_REF_TYPE: ${{ github.ref_type }}
GITHUB_RUN_ID: ${{ github.run_id }}
GITHUB_SHA: ${{ env.SHA }}
GITHUB_WORKSPACE: ${{ github.workspace }}
with:
env_vars: GITHUB_JOB,GITHUB_REF,GITHUB_REF_TYPE,GITHUB_RUN_ID,GITHUB_SHA,GITHUB_WORKSPACE
fail_ci_if_error: true
file: ./coverage/lcov.info
flags: ${{ format('node{0}', matrix.node-version) }}
override_branch: ${{ env.REF }}
override_build: ${{ github.run_id }}
override_commit: ${{ env.SHA }}
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
build:
needs:
- commitlint
- gitguardian
- preflight
runs-on: ubuntu-latest
env:
TARFILE: |
${{ startsWith(github.head_ref || github.ref_name, 'release/') && format('@{0}-{1}-{2}.tgz', github.repository_owner, github.event.repository.name, needs.preflight.outputs.version) || format('@{0}-{1}-{2}+{3}.tgz', github.repository_owner, github.event.repository.name, needs.preflight.outputs.version, github.event.pull_request.head.sha || github.sha) }}
steps:
- id: checkout
name: Checkout ${{ env.REF_NAME }}
uses: actions/checkout@v4.1.7
with:
persist-credentials: false
ref: ${{ env.REF }}
- id: node
name: Setup Node.js
uses: actions/setup-node@v4.0.3
with:
cache: yarn
cache-dependency-path: yarn.lock
node-version-file: .nvmrc
- id: cache
name: Restore dependencies cache
uses: actions/cache@v4.0.2
with:
key: ${{ needs.preflight.outputs.cache-key }}
path: ${{ env.CACHE_PATH }}
- id: local-binaries
name: Add local binaries to $PATH
run: echo "$GITHUB_WORKSPACE/$CACHE_PATH/.bin" >> $GITHUB_PATH
- id: pack
name: Pack project
run: yarn pack -o ${{ env.TARFILE }}
- id: typecheck
name: Run typecheck
run: yarn check:types:build
- id: attw
name: Analyze types distribution
run: attw ${{ env.TARFILE }}
- id: archive
name: Archive production artifacts
uses: actions/upload-artifact@v4.3.6
with:
name: ${{ env.TARFILE }}
path: ${{ env.TARFILE }}
changelog:
needs:
- build
- commitlint
- format
- gitguardian
- lint
- preflight
- spelling
- test
- typescript
runs-on: ubuntu-latest
steps:
- id: checkout
name: Checkout ${{ env.REF_NAME }}
uses: actions/checkout@v4.1.7
with:
fetch-depth: 0
persist-credentials: false
ref: ${{ env.REF }}
- id: node
name: Setup Node.js
uses: actions/setup-node@v4.0.3
with:
cache: yarn
cache-dependency-path: yarn.lock
node-version-file: .nvmrc
- id: cache
name: Restore dependencies cache
uses: actions/cache@v4.0.2
with:
key: ${{ needs.preflight.outputs.cache-key }}
path: ${{ env.CACHE_PATH }}
- id: local-binaries
name: Add local binaries to $PATH
run: echo "$GITHUB_WORKSPACE/$CACHE_PATH/.bin" >>$GITHUB_PATH
- id: summary
name: Get changelog preview
env:
TZ: ${{ vars.TZ }}
run: echo "$(grease changelog)" >>$GITHUB_STEP_SUMMARY