Skip to content

Commit 20aa698

Browse files
PiquelChipsclaude
andauthored
ci: validate pull requests and main on GitHub Actions (#25)
piquel.fr has no CI. Nothing checks formatting, lints, tests, the database tests, the browser suite or the images before a change reaches `main` and staging. This adds `ci.yml`, which runs the same `just` recipes as local validation, split into parallel jobs: | Job | Runs | | --- | --- | | `checks` | `fmt-check-rust`, plus `deny` when dependencies change | | `web` | `fmt-check-web`, `check-web` (svelte-check, tsc), `lint-web`, `build-web`, plus `audit-web` when dependencies change | | `rust` | `lint-rust`, every test including the database ones (`--run-ignored all`) against PostgreSQL 18, `doc-test` | | `e2e` | the Playwright suite against the debug binary with the auth pages embedded, the settings build and PostgreSQL 18, through the `browser-e2e` client from `tests/browser/README.md` | | `docker` | builds both images (pull requests only; staging builds them from every push to `main`) | | `ci` | one status to require: fails if any job failed, passes if the rest succeeded or were skipped | To keep it fast: - Pull requests run only the jobs their paths can affect. A web-only change skips `rust`, a Rust-only change skips `web`, and Markdown-only changes run nothing. - Rust builds are cached with `Swatinem/rust-cache`, saved from `main` only so branches never evict them. pnpm's store is cached by `setup-node`. - A new push cancels the PR's previous run. The first run on this PR, with every cache empty, took 3.5 minutes of wall time, with every job green. `rust` ran 44 tests, the database tests included, and `e2e` passed the browser suite. `audit.yml` reruns `just audit` weekly, so new advisories show up without a dependency change. The README documents CI and the `ci` check. The second run caught two flaky database tests in `security/tests.rs`. Their 50 ms and 100 ms deadlines also bounded a fresh connection and the follow-up request after the lock is released, both of which can take longer while the other database tests run in parallel. Each is now 1 s. The tests still prove the timeout, and each now takes about 1 s. > [!NOTE] > Written by Claude Opus 5.5 in Claude Code and reviewed by GPT 6.1 Sol (via T3 Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 1be73fc commit 20aa698

5 files changed

Lines changed: 308 additions & 4 deletions

File tree

‎.github/workflows/audit.yml‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Audits Rust and web dependencies weekly, so newly published advisories
2+
# surface without a code change. CI audits every change to the dependencies.
3+
4+
name: Dependency Audit
5+
6+
on:
7+
schedule:
8+
- cron: '0 8 * * 1' # Every Monday at 08:00 UTC
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
audit:
16+
name: audit
17+
runs-on: ubuntu-latest
18+
timeout-minutes: 10
19+
steps:
20+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
21+
- uses: taiki-e/install-action@3f74d7c16a4242f1c95561e98edc25d36adb4375 # v2
22+
with:
23+
tool: just,cargo-deny
24+
# pnpm audit reads the lockfile; it needs no installed packages.
25+
- uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
26+
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
27+
with:
28+
node-version: '24'
29+
- run: just audit

‎.github/workflows/ci.yml‎

Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
# Continuous integration for piquel.fr. Every job runs the same `just` recipes
2+
# as local validation:
3+
#
4+
# checks -> Rust formatting and the Rust dependency audit, which compile nothing
5+
# web -> Prettier, svelte-check and tsc, ESLint, both static builds and the
6+
# web dependency audit
7+
# rust -> Clippy, unit, database and doc tests against PostgreSQL
8+
# e2e -> the browser suite over HTTPS against the real binary, with the
9+
# auth pages embedded, the settings build and PostgreSQL
10+
# docker -> both deployment images, on pull requests only: staging builds
11+
# them from every push to main
12+
#
13+
# Pull requests run only the jobs their changes can affect (see `changes`).
14+
# Pushes to main and manual runs run everything. `ci` is the single status to
15+
# require: it fails if any job failed and passes when the rest succeeded or
16+
# were skipped. audit.yml audits new advisories weekly.
17+
#
18+
# Rust caches are saved from main only. Pull requests restore main's caches,
19+
# so a branch never evicts them with copies no other branch can read. pnpm's
20+
# small store cache is saved whenever its lockfile hash is new.
21+
22+
name: CI
23+
24+
on:
25+
pull_request:
26+
push:
27+
branches: [main]
28+
workflow_dispatch:
29+
30+
concurrency:
31+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
32+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
33+
34+
permissions:
35+
contents: read
36+
37+
env:
38+
CARGO_TERM_COLOR: always
39+
# Incremental artifacts only bloat CI caches; restored dependency builds
40+
# make up for the lost reuse.
41+
CARGO_INCREMENTAL: '0'
42+
RUST_BACKTRACE: short
43+
44+
jobs:
45+
# Decides which jobs a pull request needs from the paths it changes. A file
46+
# matches a filter only when it matches every pattern. `web` covers every
47+
# file Prettier, ESLint, tsc or the frontends can see, so it excludes file
48+
# types rather than directories. `app` covers everything the running
49+
# service and its images are built from.
50+
changes:
51+
name: changes
52+
runs-on: ubuntu-latest
53+
timeout-minutes: 5
54+
permissions:
55+
pull-requests: read
56+
outputs:
57+
rust: ${{ github.event_name != 'pull_request' || steps.filter.outputs.rust == 'true' }}
58+
web: ${{ github.event_name != 'pull_request' || steps.filter.outputs.web == 'true' }}
59+
deps: ${{ github.event_name != 'pull_request' || steps.filter.outputs.deps == 'true' }}
60+
app: ${{ github.event_name != 'pull_request' || steps.filter.outputs.app == 'true' }}
61+
docker: ${{ github.event_name == 'workflow_dispatch' || steps.filter.outputs.app == 'true' }}
62+
steps:
63+
- if: github.event_name == 'pull_request'
64+
id: filter
65+
uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3
66+
with:
67+
predicate-quantifier: every
68+
filters: |
69+
rust:
70+
- '{Cargo.toml,Cargo.lock,rust-toolchain.toml,justfile,apps/auth-service/**,crates/**,.github/workflows/ci.yml}'
71+
- '!**/*.md'
72+
web:
73+
- '**'
74+
- '!**/*.{rs,sql,toml,md}'
75+
- '!Cargo.lock'
76+
- '!infra/*.{Dockerfile,conf,sh}'
77+
- '!.dockerignore'
78+
deps:
79+
- '{Cargo.toml,**/Cargo.toml,Cargo.lock,deny.toml,package.json,**/package.json,pnpm-lock.yaml,pnpm-workspace.yaml,.github/workflows/ci.yml}'
80+
app:
81+
- '{Cargo.toml,Cargo.lock,rust-toolchain.toml,justfile,package.json,pnpm-lock.yaml,pnpm-workspace.yaml,playwright.config.ts,apps/**,crates/**,packages/**,tests/browser/**,infra/**,.dockerignore,.github/workflows/ci.yml}'
82+
- '!**/*.md'
83+
- '!infra/piqueld.toml'
84+
85+
checks:
86+
name: checks
87+
needs: changes
88+
if: needs.changes.outputs.rust == 'true' || needs.changes.outputs.deps == 'true'
89+
runs-on: ubuntu-latest
90+
timeout-minutes: 10
91+
steps:
92+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
93+
- uses: taiki-e/install-action@3f74d7c16a4242f1c95561e98edc25d36adb4375 # v2
94+
with:
95+
tool: just,cargo-deny
96+
- run: just fmt-check-rust
97+
- if: needs.changes.outputs.deps == 'true'
98+
run: just deny
99+
100+
web:
101+
name: web
102+
needs: changes
103+
if: needs.changes.outputs.web == 'true' || needs.changes.outputs.deps == 'true'
104+
runs-on: ubuntu-latest
105+
timeout-minutes: 15
106+
steps:
107+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
108+
- &install-just
109+
uses: taiki-e/install-action@3f74d7c16a4242f1c95561e98edc25d36adb4375 # v2
110+
with:
111+
tool: just
112+
# pnpm's version comes from package.json's packageManager.
113+
- &setup-pnpm
114+
uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
115+
- &setup-node
116+
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
117+
with:
118+
node-version: '24'
119+
cache: pnpm
120+
- run: just install
121+
- run: just fmt-check-web
122+
- run: just check-web
123+
- run: just lint-web
124+
- run: just build-web
125+
- if: needs.changes.outputs.deps == 'true'
126+
run: just audit-web
127+
128+
# Clippy runs first so lint failures report early; the tests then reuse the
129+
# dependencies it compiled for build scripts and proc macros.
130+
rust:
131+
name: rust
132+
needs: changes
133+
if: needs.changes.outputs.rust == 'true'
134+
runs-on: ubuntu-latest
135+
timeout-minutes: 30
136+
env:
137+
TEST_DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable
138+
# A disposable server for the database tests, and for the browser suite.
139+
services:
140+
postgres: &postgres
141+
image: postgres:18-bookworm
142+
env:
143+
POSTGRES_PASSWORD: postgres
144+
ports: ['5432:5432']
145+
options: >-
146+
--health-cmd pg_isready --health-interval 2s --health-timeout 5s --health-retries 15
147+
steps:
148+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
149+
- uses: taiki-e/install-action@3f74d7c16a4242f1c95561e98edc25d36adb4375 # v2
150+
with:
151+
tool: just,cargo-nextest
152+
- &rust-cache
153+
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
154+
with:
155+
save-if: ${{ github.ref == 'refs/heads/main' }}
156+
- run: just lint-rust
157+
- run: just test --workspace --run-ignored all
158+
- run: just doc-test
159+
160+
e2e:
161+
name: e2e
162+
needs: changes
163+
if: needs.changes.outputs.app == 'true'
164+
runs-on: ubuntu-latest
165+
timeout-minutes: 30
166+
services:
167+
postgres: *postgres
168+
env:
169+
E2E_AUTH_URL: https://localhost:3443
170+
E2E_SETTINGS_URL: https://localhost:4443/settings
171+
E2E_ALLOW_SELF_SIGNED_TLS: '1'
172+
AUTH_DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable
173+
AUTH_PUBLIC_BASE_URL: https://localhost:3443
174+
AUTH_PUBLIC_LISTENER: 127.0.0.1:3000
175+
AUTH_SETTINGS_URL: https://localhost:4443/settings
176+
AUTH_INVITE_REQUIRED: 'false'
177+
steps:
178+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
179+
- *install-just
180+
- *setup-pnpm
181+
- *setup-node
182+
- *rust-cache
183+
- run: just install
184+
# Embeds the auth pages, as in the deployed image.
185+
- run: just build-debug
186+
- run: VITE_AUTH_ORIGIN="$E2E_AUTH_URL" just build-settings-web
187+
# The service accepts only HTTPS origins, as in production. Caddy
188+
# terminates TLS for both servers with its local CA, which the suite is
189+
# told to accept. The suite signs in through the public OIDC client from
190+
# tests/browser/README.md.
191+
- name: Start the auth service and the settings frontend
192+
run: |
193+
just generate-key "$RUNNER_TEMP/key.pem"
194+
export AUTH_KEY_PROVIDER="file://$RUNNER_TEMP/key.pem"
195+
export AUTH_CLIENTS_FILE="$RUNNER_TEMP/clients.json"
196+
cat > "$AUTH_CLIENTS_FILE" <<'EOF'
197+
[
198+
{
199+
"id": "browser-e2e",
200+
"display_name": "Browser E2E",
201+
"redirect_uris": ["https://localhost:4443/callback"],
202+
"post_logout_uris": ["https://localhost:4443/settings"],
203+
"allowed_scopes": ["openid", "profile", "email"],
204+
"allow_refresh": false,
205+
"trusted": false
206+
}
207+
]
208+
EOF
209+
cat > "$RUNNER_TEMP/Caddyfile" <<'EOF'
210+
{
211+
auto_https disable_redirects
212+
skip_install_trust
213+
}
214+
localhost:3443 {
215+
reverse_proxy 127.0.0.1:3000
216+
}
217+
localhost:4443 {
218+
reverse_proxy 127.0.0.1:4173
219+
}
220+
EOF
221+
docker run --detach --name caddy --network host --volume "$RUNNER_TEMP/Caddyfile:/etc/caddy/Caddyfile:ro" caddy:2-alpine
222+
target/debug/auth-service migrate
223+
target/debug/auth-service serve > "$RUNNER_TEMP/auth.log" 2>&1 &
224+
pnpm --filter @piquel/piquel-web exec vite preview --host 127.0.0.1 --port 4173 --strictPort > "$RUNNER_TEMP/settings.log" 2>&1 &
225+
curl -kfsS --retry 30 --retry-delay 1 --retry-all-errors "$E2E_AUTH_URL/health/ready"
226+
curl -kfsS --retry 30 --retry-delay 1 --retry-all-errors -o /dev/null "$E2E_SETTINGS_URL"
227+
# The headless build matching the pinned Playwright, so runner image
228+
# updates cannot change the browser under test.
229+
- run: pnpm exec playwright install --only-shell chromium
230+
- run: just test-browser
231+
- if: failure()
232+
run: |
233+
cat "$RUNNER_TEMP"/*.log || true
234+
docker logs caddy || true
235+
236+
docker:
237+
name: docker (${{ matrix.image }})
238+
needs: changes
239+
if: needs.changes.outputs.docker == 'true'
240+
strategy:
241+
fail-fast: false
242+
matrix:
243+
image: [auth, web]
244+
runs-on: ubuntu-latest
245+
timeout-minutes: 30
246+
steps:
247+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
248+
- run: docker build --file infra/${{ matrix.image }}.Dockerfile .
249+
250+
ci:
251+
name: ci
252+
if: always()
253+
needs:
254+
- changes
255+
- checks
256+
- web
257+
- rust
258+
- e2e
259+
- docker
260+
runs-on: ubuntu-latest
261+
timeout-minutes: 5
262+
steps:
263+
- uses: re-actors/alls-green@b5b5b37504aa4183270bd3d855c52a67f212be35 # v1.3.0
264+
with:
265+
allowed-skips: checks, web, rust, e2e, docker
266+
jobs: ${{ toJSON(needs) }}

‎README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ Use individual recipes while iterating:
181181
| Static frontends / embedded debug binary / release binary | `just build-web` / `just build-debug` / `just build` |
182182
| Run with caller-provided auth configuration | `just serve`, `just migrate`, `just invite --expires-in 7d` |
183183

184+
CI runs these recipes on every pull request whose changes they can affect,
185+
including the database and browser tests, and on every push to `main`.
186+
Require its `ci` check: it summarizes the others.
187+
184188
Web code is formatted by Prettier and linted by type-aware ESLint (typescript-eslint
185189
`strictTypeChecked`), configured once at the repository root.
186190
`just --list` shows every recipe. Test recipes forward extra arguments to nextest

‎apps/auth-service/src/security/tests.rs‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,9 @@ async fn router_enforces_exact_browser_origins_csrf_and_public_client_cors_bound
276276
#[tokio::test]
277277
#[ignore = "requires TEST_DATABASE_URL"]
278278
async fn optional_session_preserves_database_failure_instead_of_reporting_signed_out() {
279-
let database = SecurityFixture::database(1, std::time::Duration::from_millis(50)).await;
279+
// The timeout also bounds the first connection, so it leaves room for
280+
// connecting while other database tests run.
281+
let database = SecurityFixture::database(1, std::time::Duration::from_secs(1)).await;
280282
// Exhaust only this test's private pool; the database and all other tests
281283
// remain usable. A well-formed session cookie must trigger a real lookup.
282284
let transaction = database.begin().await.expect("hold sole connection");
@@ -347,15 +349,17 @@ async fn rate_limit_deadline_includes_a_blocked_database_query() {
347349
.allow_request(bucket.as_bytes(), 120)
348350
.await
349351
.expect("hold bucket lock");
350-
fixture.policy.request_timeout = std::time::Duration::from_millis(100);
352+
// The deadline also bounds the request after the lock is released, so it
353+
// leaves room for queries while other database tests run.
354+
fixture.policy.request_timeout = std::time::Duration::from_secs(1);
351355
fixture.router = Router::new()
352356
.route("/oauth/token", any(|| async { StatusCode::ACCEPTED }))
353357
.layer(middleware::from_fn_with_state(
354358
fixture.policy.clone(),
355359
HttpSecurity::protect,
356360
));
357361
let response = tokio::time::timeout(
358-
std::time::Duration::from_secs(2),
362+
std::time::Duration::from_secs(5),
359363
fixture.request(Method::POST, "/oauth/token", None, false),
360364
)
361365
.await

‎tests/browser/README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
The browser suite uses the real auth binary and PostgreSQL, with Chromium's virtual
22
WebAuthn authenticator. It does not intercept or mock API responses. Use an isolated
3-
database: tests create accounts and credentials.
3+
database: tests create accounts and credentials. CI runs it against the embedded
4+
production build, as configured below.
45

56
Run `just preview` to build and deploy this checkout over HTTPS on piqueld.
67
Set `E2E_AUTH_URL` and `E2E_SETTINGS_URL` to the printed auth origin and web

0 commit comments

Comments
 (0)