Repository navigation
500 lines (483 loc) · 21.6 KB
/
Copy pathci.yml
File metadata and controls
500 lines (483 loc) · 21.6 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
# Continuous integration for SourceOrigin. Every job runs the same `just` recipes
# as local validation:
#
# checks -> Rust formatting, unused Rust dependencies and the Rust dependency
# audit, which compile nothing
# web -> Prettier, tsc, ESLint and knip, the passkey script included, the
# TypeScript SDK's package checks, tests with coverage and runtime
# smoke in Node, Bun and workerd, and the web dependency audit
# rust -> unit and database tests against PostgreSQL with coverage, and
# the SQLx query cache checked to match the migrated schema exactly
# rust-lint -> Clippy, rustdoc with warnings denied, and the doc tests
# package -> the SDKs packaged as `just publish` publishes them, each crate
# built from its package, without uploading anything
# msrv -> the published crates built with their oldest supported Rust, with
# all their features, none, and each one alone
# e2e -> the browser suite over HTTPS against the real binary and PostgreSQL,
# with the admin dashboard on its own listener and host, sourceorigin.dev's
# web server on its own host, Mailpit receiving auth's email, and
# the binary's CLI granting administrators and recovering accounts
# docker -> the deployment images: auth, sourceorigin.dev's web server and the docs,
# the Rust ones with their layers cached
# infra -> the piqueld manifests, by piquelctl, and the telemetry configs,
# each by the image that runs it
# docs -> the documentation book, built with warnings denied, with every
# link and heading anchor in it and in the repository's Markdown
# checked offline
#
# Pull requests run only the jobs their changes can affect (see `changes`),
# except `docs`: a change anywhere can break a link to it.
# The merge queue and manual runs run everything: the queue tests each pull
# request on top of the latest main before it merges, so two pull requests that
# pass alone cannot break main together. `ci` is the single status to require,
# and the queue waits for it: it fails if any job failed and passes when the
# rest succeeded or were skipped. audit.yml audits new advisories weekly.
#
# Rust caches, and the Rust images' layers, are saved from main only: GitHub
# scopes a cache to the branch that saved it, and every other branch, the
# queue's included, can read main's. So a branch never evicts main's caches
# with copies no other branch can read. pnpm's small store cache is saved
# whenever its lockfile hash is new.
#
# Main receives the very commit the queue tested, so pushes to main test
# nothing again: they only refresh the caches. They skip the jobs whose cache
# another job saves too, or that save none, and every step marked
# `if: *tests`. rust-cache saves only when no cache is saved under its current
# key, as after a dependency or toolchain change or an eviction, so a step
# marked `if: *builds` runs on main only then. The images' layers are saved on
# every push.
name: CI
on:
pull_request:
merge_group:
push:
branches: [main]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
# Incremental artifacts only bloat CI caches; restored dependency builds
# make up for the lost reuse.
CARGO_INCREMENTAL: '0'
RUST_BACKTRACE: short
jobs:
# Decides which jobs a pull request needs from the paths it changes. A file
# matches a filter only when it matches every pattern. `web` covers every
# file Prettier, ESLint or tsc can see, so it excludes file types rather than
# directories. `app` covers everything the running service and its images
# are built from, and the TypeScript SDK the browser suite also runs. Rust
# also reads files outside the crates: the committed audit verifier keys,
# which auth compiles in, and the generated reference pages its tests compare
# with the code, which `reference` matches since `rust` skips Markdown.
changes:
name: changes
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
pull-requests: read
outputs:
rust: ${{ github.event_name != 'pull_request' || steps.filter.outputs.rust == 'true' || steps.filter.outputs.reference == 'true' }}
web: ${{ github.event_name != 'pull_request' || steps.filter.outputs.web == 'true' }}
deps: ${{ github.event_name != 'pull_request' || steps.filter.outputs.deps == 'true' }}
app: ${{ github.event_name != 'pull_request' || steps.filter.outputs.app == 'true' }}
infra: ${{ github.event_name != 'pull_request' || steps.filter.outputs.infra == 'true' }}
steps:
- if: github.event_name == 'pull_request'
id: filter
uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3
with:
predicate-quantifier: every
filters: |
rust:
- '{Cargo.toml,Cargo.lock,rust-toolchain.toml,rustfmt.toml,clippy.toml,.cargo/**,.config/**,justfile,just/**,apps/**,crates/**,tools/**,tests/sdk-vectors/**,packages/auth/src/protocol.ts,docs/dev/security/audit-key.pub,.github/workflows/ci.yml}'
- '!**/*.md'
reference:
- 'docs/dev/operations/{cli-commands,variables/*}.md'
web:
- '**'
- '!**/*.{rs,sql,toml,md}'
- '!Cargo.lock'
- '!infra/*.{Dockerfile,conf,sh}'
- '!.dockerignore'
deps:
- '{Cargo.toml,**/Cargo.toml,Cargo.lock,deny.toml,package.json,**/package.json,pnpm-lock.yaml,pnpm-workspace.yaml,.github/workflows/ci.yml}'
app:
- '{Cargo.toml,Cargo.lock,rust-toolchain.toml,.cargo/**,justfile,just/**,package.json,pnpm-lock.yaml,playwright.config.ts,apps/**,crates/**,packages/auth/**,tests/browser/**,infra/**,docs/dev/security/audit-key.pub,.dockerignore,.github/workflows/ci.yml}'
- '!**/*.md'
- '!infra/piqueld.toml'
infra:
- '{infra/piqueld.toml,infra/telemetry.toml,infra/telemetry/*.yaml,justfile,just/infra.just,.github/workflows/ci.yml}'
checks:
name: checks
needs: changes
if: github.event_name != 'push' && (needs.changes.outputs.rust == 'true' || needs.changes.outputs.deps == 'true')
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: taiki-e/install-action@3f74d7c16a4242f1c95561e98edc25d36adb4375 # v2
with:
tool: just,cargo-deny,cargo-machete@0.9.2
- run: just rust fmt-check
- run: just rust unused
- if: needs.changes.outputs.deps == 'true'
run: just rust audit
# Skipped on main, whose pnpm store cache `package` and `e2e` save.
web:
name: web
needs: changes
if: github.event_name != 'push' && (needs.changes.outputs.web == 'true' || needs.changes.outputs.deps == 'true')
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- &install-just
uses: taiki-e/install-action@3f74d7c16a4242f1c95561e98edc25d36adb4375 # v2
with:
tool: just
# pnpm's version comes from package.json's packageManager.
- &setup-pnpm
uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
- &setup-node
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: '24'
cache: pnpm
- run: just install
- run: just web fmt-check
- run: just web check
- run: just web lint
- run: just web unused
- run: just web test
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version: 1.x
- run: just web smoke
- if: needs.changes.outputs.deps == 'true'
run: just web audit
# Clippy, rustdoc and the doc tests, beside `rust`: its coverage builds an
# instrumented copy of everything, in target/llvm-cov-target, which they cannot
# reuse. The doc tests reuse the dependencies Clippy compiled for build scripts
# and proc macros. Each of the three compiles dependencies the others don't,
# so main runs all three when it saves a new cache.
rust-lint:
name: rust-lint
needs: changes
if: needs.changes.outputs.rust == 'true'
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- *install-just
- &rust-cache
id: rust-cache
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
with:
# rust-cache's key ignores this workflow, but includes the job's ID.
# Bump the prefix when a job needs a new cache, as when rust began
# installing sqlx-cli.
prefix-key: v1-rust
save-if: ${{ github.ref == 'refs/heads/main' }}
# Builds that main runs only when rust-cache restored no exact match, so
# that it saves a new cache. Every other run runs them.
- if: &builds github.event_name != 'push' || steps.rust-cache.outputs.cache-hit != 'true'
run: just rust lint
- if: *builds
run: just doc
- if: *builds
run: just doc-test ${{ github.event_name == 'push' && '--list' || '' }}
# Everything `just publish` does except uploading: packages each crate and
# builds it from its package, as `cargo install` and crates.io would, then
# packs @sourceorigin/auth, whose `prepack` script builds it.
package:
name: package
needs: changes
if: needs.changes.outputs.rust == 'true' || needs.changes.outputs.web == 'true'
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- *install-just
- *setup-pnpm
- *setup-node
- *rust-cache
- run: just install
- if: *builds
run: just publish --dry-run
# Builds the published crates with the oldest Rust their `rust-version`
# promises. Warnings aren't errors here: lints differ between Rust versions,
# and rust-lint lints with the pinned one.
msrv:
name: msrv
needs: changes
if: needs.changes.outputs.rust == 'true'
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
# RUSTUP_TOOLCHAIN overrides rust-toolchain.toml for every later step,
# the cache key included.
- name: Install the oldest supported Rust
run: |
msrv=$(sed -n 's/^rust-version = "\(.*\)"$/\1/p' Cargo.toml)
rustup toolchain install "$msrv" --profile minimal
echo "RUSTUP_TOOLCHAIN=$msrv" >> "$GITHUB_ENV"
- *install-just
- *rust-cache
- if: *builds
run: cargo check --locked --all-features --package sourceorigin-common --package sourceorigin-crypto --package sourceorigin-auth
- if: *builds
run: just rust features
rust:
name: rust
needs: changes
if: needs.changes.outputs.rust == 'true'
runs-on: ubuntu-latest
timeout-minutes: 30
env:
TEST_DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable
# A disposable server for the database tests, and for the browser suite.
# Pushes to main run no test, so they start no service: GitHub skips a
# service whose image is empty.
services:
postgres: &postgres
image: ${{ github.event_name != 'push' && 'postgres:18-bookworm' || '' }}
env:
POSTGRES_PASSWORD: postgres
ports: ['5432:5432']
options: >-
--health-cmd pg_isready --health-interval 2s --health-timeout 5s --health-retries 15
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: taiki-e/install-action@3f74d7c16a4242f1c95561e98edc25d36adb4375 # v2
with:
tool: just,cargo-nextest,cargo-llvm-cov
- *rust-cache
# sqlx-cli publishes no prebuilt binaries. rust-cache keeps binaries
# installed after it restores, so this compiles when main's cache lacks
# the latest release, until main next saves a cache.
- if: *builds
run: just db install-sqlx
# Every unit and database test, instrumented. Coverage is reported, not
# enforced: per crate in the log, per line in the rust-coverage artifact.
# cargo-llvm-cov adds the llvm-tools-preview component it needs.
#
# Steps main skips: they test what the queue already tested.
- if: &tests github.event_name != 'push'
run: just coverage
- if: *tests
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: rust-coverage
path: target/lcov.info
if-no-files-found: error
# The database tests migrated TEST_DATABASE_URL, so a migration that
# breaks a cached query fails here even if no test runs that query, as
# does a cached query the code no longer uses.
- if: *tests
run: just db prepare-check
# When main saves a new cache, it compiles what the two steps above do,
# without running a test or needing a database.
- if: github.event_name == 'push' && steps.rust-cache.outputs.cache-hit != 'true'
run: |
just coverage-build
just db check
e2e:
name: e2e
needs: changes
if: needs.changes.outputs.app == 'true'
runs-on: ubuntu-latest
timeout-minutes: 30
services:
postgres: *postgres
# Receives auth's email over plain SMTP on the loopback address, and lets
# the suite read it from its API. Not started on main, like Postgres.
mailpit:
image: ${{ github.event_name != 'push' && 'axllent/mailpit:v1.27' || '' }}
ports: ['1025:1025', '8025:8025']
env:
E2E_AUTH_URL: https://localhost:3443
E2E_ALLOW_SELF_SIGNED_TLS: '1'
# migrate connects as the superuser and provisions the restricted role
# that everything else connects as, as in deployments.
AUTH_DATABASE_OWNER_URL: postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable
AUTH_DATABASE_URL: postgres://sourceorigin_auth@localhost:5432/postgres?sslmode=disable
AUTH_DATABASE_PASSWORD: env://E2E_DATABASE_PASSWORD
E2E_DATABASE_PASSWORD: runtime
AUTH_PUBLIC_BASE_URL: https://localhost:3443
AUTH_PUBLIC_LISTENER: 127.0.0.1:3000
# Signup needs an invitation, as in production: each signup of the suite
# takes a new one from the CLI.
AUTH_INVITE_REQUIRED: 'true'
E2E_INVITE: target/debug/auth-service invite create
AUTH_SMTP_URL: smtp://127.0.0.1:1025
E2E_MAIL_URL: http://127.0.0.1:8025
# sourceorigin.dev on its own host, whose policies auth's pages link.
AUTH_WEB_ORIGIN: https://web.localhost:3443
E2E_WEB_URL: https://web.localhost:3443
WEB_LISTENER: 127.0.0.1:3002
WEB_AUTH_ORIGIN: https://localhost:3443
# The suite runs serially from one address, and spends in a minute what a
# person would in an hour.
AUTH_REQUESTS_PER_MINUTE: '1000'
# The dashboard on an origin of its own, as admin.sourceorigin.dev is, on another
# port of auth's host: its passkey dialog may use auth's RP ID there, which
# admin.sourceorigin.dev does through auth's related origins. Browsers fetch those
# from the RP ID on port 443, which CI does not serve. Cookies ignore the
# port, so here the dashboard and auth share them; previews keep them apart.
AUTH_ADMIN_LISTENER: 127.0.0.1:3001
AUTH_ADMIN_ORIGIN: https://localhost:3444
E2E_ADMIN_URL: https://localhost:3444
E2E_GRANT_ADMIN: target/debug/auth-service admin grant
E2E_RECOVER: target/debug/auth-service user recover
# The secret `just web browser-client` registers for the example app of
# @sourceorigin/auth/server, which server.spec.ts starts. It guards nothing.
E2E_SERVER_CLIENT_SECRET: YnJvd3Nlci1lMmUtc2VydmVyIHNlY3JldCBmb3IgY2k
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- *install-just
- *setup-pnpm
- *setup-node
- *rust-cache
- run: just install
# The binary embeds the passkey script and the stylesheet, as in the
# deployed image.
- if: *builds
run: just rust build
# The keys reach every later step, so the commands the suite runs, such as
# `user recover`, which derives its link with the token digest key, share
# them with the service.
- name: Generate the keys
if: *tests
run: |
just auth generate-secret "$RUNNER_TEMP/key-encryption-key"
just auth generate-secret "$RUNNER_TEMP/token-digest-key"
openssl rand -hex 32 > "$RUNNER_TEMP/audit-key"
{
echo "AUTH_KEY_ENCRYPTION_KEY=file://$RUNNER_TEMP/key-encryption-key"
echo "AUTH_TOKEN_DIGEST_KEY=file://$RUNNER_TEMP/token-digest-key"
echo "AUTH_AUDIT_KEY_PROVIDER=file://$RUNNER_TEMP/audit-key"
} >> "$GITHUB_ENV"
# The service accepts only HTTPS origins, as in production. Caddy
# terminates TLS with its local CA, which the suite is told to accept.
# The suite signs in through the public OIDC client from
# tests/browser/README.md, whose origin has no server.
- name: Start the auth service and sourceorigin.dev
if: *tests
run: |
cat > "$RUNNER_TEMP/Caddyfile" <<'EOF'
{
auto_https disable_redirects
skip_install_trust
}
localhost:3443 {
reverse_proxy 127.0.0.1:3000
}
localhost:3444 {
reverse_proxy 127.0.0.1:3001
}
web.localhost:3443 {
reverse_proxy 127.0.0.1:3002
}
EOF
docker run --detach --name caddy --network host --volume "$RUNNER_TEMP/Caddyfile:/etc/caddy/Caddyfile:ro" caddy:2-alpine
target/debug/auth-service migrate
just web browser-client
target/debug/auth-service serve > "$RUNNER_TEMP/auth.log" 2>&1 &
target/debug/sourceorigin-web > "$RUNNER_TEMP/web.log" 2>&1 &
curl -kfsS --retry 30 --retry-delay 1 --retry-all-errors "$E2E_AUTH_URL/health/ready"
curl -kfsS --retry 30 --retry-delay 1 --retry-all-errors "$E2E_WEB_URL/health"
# The headless build matching the pinned Playwright, so runner image
# updates cannot change the browser under test.
- if: *tests
run: pnpm exec playwright install --only-shell chromium
- if: *tests
run: just web test-browser
- if: failure()
run: |
cat "$RUNNER_TEMP"/*.log || true
docker logs caddy || true
docker:
name: docker
needs: changes
if: needs.changes.outputs.app == 'true'
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
# The docs image caches no layers, so main, which tests nothing, skips it.
- if: *tests
run: docker build --file infra/docs.Dockerfile .
# Both Rust targets share the `backend` stage, which builds once. A build
# restores main's layers, so only what changed since main recompiles:
# usually just the workspace's own crates, after cargo-chef's dependencies.
- uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
- uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
context: .
file: infra/rust.Dockerfile
target: auth
cache-from: type=gha,scope=auth
cache-to: ${{ github.ref == 'refs/heads/main' && 'type=gha,mode=max,scope=auth,ignore-error=true' || '' }}
- uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
context: .
file: infra/rust.Dockerfile
target: web
cache-from: type=gha,scope=web
cache-to: ${{ github.ref == 'refs/heads/main' && 'type=gha,mode=max,scope=web,ignore-error=true' || '' }}
# piquelctl publishes no prebuilt binaries either. rust-cache keeps it as it
# keeps sqlx-cli in `rust`, and `cargo install` upgrades it when a newer
# release is out. Docker pulls each telemetry image.
infra:
name: infra
needs: changes
if: needs.changes.outputs.infra == 'true'
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- *install-just
- *rust-cache
- if: *builds
run: cargo install --locked piquelctl
- if: *tests
run: just infra check
# mdBook and lychee at the versions `just install-tools` installs.
docs:
name: docs
if: github.event_name != 'push'
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: taiki-e/install-action@3f74d7c16a4242f1c95561e98edc25d36adb4375 # v2
with:
tool: just,mdbook@0.5.4,lychee@0.24.2
- run: just docs
ci:
name: ci
if: always()
needs:
- changes
- checks
- web
- rust
- rust-lint
- package
- msrv
- e2e
- docker
- infra
- docs
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: re-actors/alls-green@b5b5b37504aa4183270bd3d855c52a67f212be35 # v1.3.0
with:
allowed-skips: checks, web, rust, rust-lint, package, msrv, e2e, docker, infra, docs
jobs: ${{ toJSON(needs) }}