Repository navigation
566 lines (464 loc) · 19.2 KB
/
Copy pathci.yml
File metadata and controls
566 lines (464 loc) · 19.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
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
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
name: CI
on:
workflow_dispatch:
push:
branches:
- main
- develop
pull_request:
release:
types: [published]
merge_group:
types: [checks_requested]
# Cancel superseded runs of a pull request. Other events get a unique group, so they are never cancelled or queued.
concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.run_id }}
cancel-in-progress: true
permissions:
contents: read
env:
REGISTRY: ghcr.io
IMAGE_NAME_RUNTIME: ${{ github.repository }}/runtime
jobs:
test:
name: "Test backpex"
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
matrix:
include:
- elixir: "1.16"
otp: "26.2"
- elixir: "1.17"
otp: "27.3"
- elixir: "1.18"
otp: "28.5"
- elixir: "1.19"
otp: "28.5"
- elixir: "1.20"
otp: "29.1"
# The integration tests run once, on the latest Elixir, in the test-integration job.
env:
INTEGRATION_TESTS: false
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set runner image
# Part of the cache keys, so caches don't carry over to a new Ubuntu version behind ubuntu-latest
run: echo "RUNNER_IMAGE=$ImageOS" >> "$GITHUB_ENV"
- uses: erlef/setup-beam@54075bcc5e249e4758d363f27d099f55d843f124 # v1.24.1
with:
otp-version: ${{ matrix.otp }}
elixir-version: ${{ matrix.elixir }}
- name: Setup bun
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version-file: .tool-versions
- name: Restore the deps and _build cache
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
id: restore-cache
env:
MIX_LOCK_HASH: ${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
with:
path: |
deps
_build
key: ${{ runner.os }}-${{ env.RUNNER_IMAGE }}-${{ matrix.elixir }}-${{ matrix.otp }}-build-deps-mixlockhash-${{ env.MIX_LOCK_HASH }}
restore-keys: ${{ runner.os }}-${{ env.RUNNER_IMAGE }}-${{ matrix.elixir }}-${{ matrix.otp }}-build-deps-
- name: Install dependencies
if: steps.restore-cache.outputs.cache-hit != 'true'
run: mix deps.get
- name: Compile dependencies
if: steps.restore-cache.outputs.cache-hit != 'true'
run: mix deps.compile
- name: Compile with warnings as errors
run: mix compile --warnings-as-errors --force
- name: Cache bun install cache
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.bun/install/cache
key: ${{ runner.os }}-bun-store-${{ hashFiles('bun.lock') }}
restore-keys: |
${{ runner.os }}-bun-store-
- name: Install node dependencies
run: bun install --frozen-lockfile
- name: Check formatting
run: mix format --check-formatted
- name: JavaScript Standard
run: bun run lint:standard
- name: Run JavaScript tests
run: bun run test:js
- name: Build docs with warnings as errors
run: mix docs --warnings-as-errors
- name: Credo
run: mix credo
- name: Sobelow
run: mix sobelow --config
- name: Run tests
run: mix test
- name: Run doc tests
run: mix test test/doc_test.exs
- name: Deps Audit
continue-on-error: true
run: mix deps.audit
- name: Gettext Check
run: mix gettext.extract --check-up-to-date
- name: Check assets up-to-date
run: mix assets.check
test-integration:
name: "Integration tests and coverage (backpex)"
runs-on: ubuntu-latest
timeout-minutes: 20
services:
postgres:
image: postgres:18.6@sha256:e3d24f6906d0760bf4da0dae872415391ededefad23fd471c47dc53b0ddf3c42
env:
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 5s
--health-timeout 5s
--health-retries 10
env:
DB_HOSTNAME: localhost
DB_PORT: 5432
DB_USERNAME: postgres
DB_PASSWORD: postgres
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set runner image
# Part of the cache keys, so caches don't carry over to a new Ubuntu version behind ubuntu-latest
run: echo "RUNNER_IMAGE=$ImageOS" >> "$GITHUB_ENV"
- name: Set Playwright version
# Keys the browser cache. The browsers only change with this version, not with every lockfile change.
run: echo "PLAYWRIGHT_VERSION=$(jq -r .devDependencies.playwright package.json)" >> "$GITHUB_ENV"
- uses: erlef/setup-beam@54075bcc5e249e4758d363f27d099f55d843f124 # v1.24.1
with:
version-file: .tool-versions
version-type: strict
- name: Setup bun
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version-file: .tool-versions
- name: Setup node
# Playwright runs its CLI with node
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 26
- name: Restore the deps and _build cache
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
id: restore-cache
env:
TOOL_VERSIONS_HASH: ${{ hashFiles('.tool-versions') }}
MIX_LOCK_HASH: ${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
with:
path: |
deps
_build
key: ${{ runner.os }}-${{ env.RUNNER_IMAGE }}-${{ env.TOOL_VERSIONS_HASH }}-build-deps-integration-mixlockhash-${{ env.MIX_LOCK_HASH }}
restore-keys: ${{ runner.os }}-${{ env.RUNNER_IMAGE }}-${{ env.TOOL_VERSIONS_HASH }}-build-deps-integration-
- name: Install dependencies
if: steps.restore-cache.outputs.cache-hit != 'true'
run: mix deps.get
- name: Compile dependencies
if: steps.restore-cache.outputs.cache-hit != 'true'
run: MIX_ENV=test mix deps.compile
- name: Cache bun install cache
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.bun/install/cache
key: ${{ runner.os }}-bun-store-${{ hashFiles('bun.lock') }}
restore-keys: |
${{ runner.os }}-bun-store-
- name: Cache Playwright browsers
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
id: playwright-cache
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-${{ env.RUNNER_IMAGE }}-playwright-${{ env.PLAYWRIGHT_VERSION }}
restore-keys: |
${{ runner.os }}-${{ env.RUNNER_IMAGE }}-playwright-
- name: Deps Unused
# Only the latest Elixir loads the dependencies of the integration tests, see mix.exs.
run: mix deps.unlock --check-unused
- name: Install node dependencies
run: bun install --frozen-lockfile
- name: Install Playwright
if: steps.playwright-cache.outputs.cache-hit != 'true'
# With a cache miss, `--with-deps` needs apt, which fails when the runner can't resolve the Ubuntu mirrors.
# The runner image already has the system libraries (a cache hit skips this step), so retry without apt.
run: bun run e2e:install || bun x playwright install chromium --only-shell
- name: Build the assets of the browser tests
run: bun run e2e:assets
- name: Compile the test app with warnings as errors
run: MIX_ENV=test mix compile --warnings-as-errors
- name: Run unit and integration tests with coverage
run: mix test --cover --export-coverage default
- name: Run browser tests with coverage
# A failed test runs again with traces for the artifact, but the step fails anyway, so a flaky test shows up
# and the coverage check never merges the export of a failed run.
run: |
mix test --only e2e --cover --export-coverage e2e || {
status=$?
if [[ $status = 2 ]]; then PW_TRACE=true mix test --only e2e --max-cases 1 --failed || true; fi
exit $status
}
- name: Convert the merged coverage to LCOV
run: MIX_ENV=test mix run --no-start scripts/coverage_lcov.exs
- name: Upload the coverage to Codecov
uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
with:
# Pull requests from forks get no secrets and upload without a token, which Codecov may rate limit.
token: ${{ secrets.CODECOV_TOKEN }}
files: cover/lcov.info
disable_search: true
fail_ci_if_error: ${{ github.event.pull_request.head.repo.fork != true }}
- name: Check the merged coverage
run: MIX_ENV=test mix test.coverage
- name: Upload the coverage report
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: coverage
path: cover/
retention-days: 7
- name: Upload Playwright traces
if: failure()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: playwright-traces-backpex
path: tmp/e2e/traces/
retention-days: 7
publish:
needs: [test, test-integration, test-demo]
if: github.event_name == 'release'
name: "Publish package on hex.pm"
runs-on: ubuntu-latest
timeout-minutes: 10
environment: hex
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: erlef/setup-beam@54075bcc5e249e4758d363f27d099f55d843f124 # v1.24.1
id: beam
with:
version-file: .tool-versions
version-type: strict
- name: Install dependencies
run: |
mix local.hex --force --if-missing
mix local.rebar --force --if-missing
mix deps.get
- name: Publish package on hex.pm
env:
HEX_API_KEY: ${{ secrets.HEX_API_KEY }}
run: mix hex.publish --yes
test-demo:
name: "Test (Demo)"
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Start Postgres
id: postgres
background: true
# The step ends once the database accepts TCP connections, so `wait: postgres` blocks until it is ready.
# The image's init server only listens on the socket, so checking 127.0.0.1 skips it.
run: |
docker run -d --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=postgres \
postgres:16.15@sha256:ca0bd484cb98bf4b24eb1010e73fb3fcbd6714d240fbc1a10eea5b7dbecb641d
timeout 60 bash -c 'until docker exec postgres pg_isready -h 127.0.0.1 -U postgres; do sleep 1; done'
- name: Set runner image
# Part of the cache keys, so caches don't carry over to a new Ubuntu version behind ubuntu-latest
run: echo "RUNNER_IMAGE=$ImageOS" >> "$GITHUB_ENV"
- name: Set Playwright version
# Keys the browser cache. The browsers only change with this version, not with every lockfile change.
run: echo "PLAYWRIGHT_VERSION=$(jq -r .devDependencies.playwright demo/package.json)" >> "$GITHUB_ENV"
- parallel:
- name: Setup beam
uses: erlef/setup-beam@54075bcc5e249e4758d363f27d099f55d843f124 # v1.24.1
with:
version-file: .tool-versions
version-type: strict
- name: Setup node
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 26
- name: Setup bun
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version-file: .tool-versions
- name: Restore the deps and _build cache
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
id: restore-cache
env:
# setup-beam's outputs aren't available inside the group. With `version-type: strict` the versions are
# exactly the ones in .tool-versions.
TOOL_VERSIONS_HASH: ${{ hashFiles('.tool-versions') }}
MIX_LOCK_HASH: ${{ hashFiles(format('{0}{1}', github.workspace, '/demo/mix.lock')) }}
with:
path: |
demo/deps
demo/_build
key: ${{ runner.os }}-${{ env.RUNNER_IMAGE }}-${{ env.TOOL_VERSIONS_HASH }}-build-deps-demo-mixlockhash-${{ env.MIX_LOCK_HASH }}
restore-keys: ${{ runner.os }}-${{ env.RUNNER_IMAGE }}-${{ env.TOOL_VERSIONS_HASH }}-build-deps-demo-
- name: Cache bun install cache
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.bun/install/cache
key: ${{ runner.os }}-bun-store-${{ hashFiles('demo/bun.lock', 'bun.lock') }}
restore-keys: |
${{ runner.os }}-bun-store-
- name: Cache Playwright browsers
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
id: playwright-cache
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-${{ env.RUNNER_IMAGE }}-playwright-${{ env.PLAYWRIGHT_VERSION }}
restore-keys: |
${{ runner.os }}-${{ env.RUNNER_IMAGE }}-playwright-
- name: Install dependencies
if: steps.restore-cache.outputs.cache-hit != 'true'
working-directory: demo
run: mix deps.get
- name: Compile dependencies
if: steps.restore-cache.outputs.cache-hit != 'true'
working-directory: demo
run: mix deps.compile
- name: Compile with warnings as errors
working-directory: demo
run: mix compile --warnings-as-errors --force
- name: Install node dependencies
working-directory: demo
run: bun install --frozen-lockfile
- name: Install Backpex node dependencies
run: bun install --frozen-lockfile
- name: Setup assets
working-directory: demo
run: mix assets.setup
- name: Build assets
working-directory: demo
run: mix assets.build
# The lints run in the background while the tests run. They use MIX_ENV=dev, the tests MIX_ENV=test, so they
# don't share a _build directory.
- name: lint:mix
working-directory: demo
background: true
run: bun run lint:mix
- name: lint:credo
working-directory: demo
background: true
run: bun run lint:credo
- name: lint:sobelow
working-directory: demo
background: true
run: bun run lint:sobelow
- name: lint:style
working-directory: demo
background: true
run: bun run lint:style
- name: lint:standard
working-directory: demo
background: true
run: bun run lint:standard
- name: lint:deps-unused
working-directory: demo
background: true
run: bun run lint:deps-unused
- name: lint:gettext
working-directory: demo
background: true
run: bun run lint:gettext
- name: Deps audit
working-directory: demo
background: true
continue-on-error: true
run: mix deps.audit
- name: Wait for Postgres
wait: postgres
- name: Run test
working-directory: demo
env:
DB_HOSTNAME: localhost
DB_USERNAME: postgres
DB_PASSWORD: postgres
DB_DATABASE: test
run: bun run test
- name: Install playwright
if: steps.playwright-cache.outputs.cache-hit != 'true'
working-directory: demo
# With a cache miss, `--with-deps` needs apt, which fails when the runner can't resolve the Ubuntu mirrors.
# The runner image already has the system libraries (a cache hit skips this step), so retry without apt.
run: bun x playwright install chromium --with-deps --only-shell || bun x playwright install chromium --only-shell
- name: Run playwright test
working-directory: demo
env:
DB_HOSTNAME: localhost
DB_USERNAME: postgres
DB_PASSWORD: postgres
DB_DATABASE: test
run: bun run test:playwright || if [[ $? = 2 ]]; then PW_TRACE=true bun run test:playwright --max-cases 1 --failed; else false; fi
- name: Upload Playwright traces
if: failure()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: playwright-traces
path: demo/tmp/
retention-days: 7
- name: Wait for the lints
wait-all:
lint-dockerfile:
name: "Lint Dockerfile"
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Hadolint
uses: hadolint/hadolint-action@06be81baf89a55ffd0e24b8f04a4185738dd3387 # v3.5.0
with:
config: .hadolint.yaml
build-runtime:
name: "Build and push image (Demo)"
runs-on: ubuntu-latest
timeout-minutes: 20
env:
PUSH_IMAGE: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop') }}
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
with:
# The runner is ephemeral, so skip the post step that removes the builder
cleanup: false
- name: Log in to the container registry
if: env.PUSH_IMAGE == 'true'
uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4.7.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_RUNTIME }}
- name: Build container
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
push: ${{ env.PUSH_IMAGE }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME_RUNTIME }}:buildcache
cache-to: ${{ env.PUSH_IMAGE == 'true' && format('type=registry,ref={0}/{1}:buildcache,mode=max', env.REGISTRY, env.IMAGE_NAME_RUNTIME) || '' }}
target: runtime
build-args: |
MIX_ENV=prod