|
| 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) }} |
0 commit comments