diff --git a/.agents/skills/sourceorigin-cleanup/SKILL.md b/.agents/skills/sourceorigin-cleanup/SKILL.md index 231a3cd72..f8ee01db5 100644 --- a/.agents/skills/sourceorigin-cleanup/SKILL.md +++ b/.agents/skills/sourceorigin-cleanup/SKILL.md @@ -36,8 +36,10 @@ other labels that fit (`gh label list`). `html_preview` and `html_render`, including growth over time from the JSON. 2. Read the output, then check what the script can't count: - - coverage, from the `rust-coverage` artifact of `main`'s latest CI run (or - `just coverage`) and `just web test` + - coverage, from the `rust-coverage` artifact of the latest merge queue run + (`gh run list -w ci.yml -e merge_group -s success -L 1`, then + `gh run download -n rust-coverage`), or `just coverage`, and + `just web test` - unused code and dependencies, with `just unused` - generated files missing from `.gitattributes` - which `expect` calls can really panic diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef7185b88..f89ae1788 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,17 +27,25 @@ # # 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, pushes to main 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. +# 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. Pull -# requests restore main's caches, so a branch never evicts them with copies no -# other branch can read. pnpm's small store cache is saved whenever its lockfile -# hash is new. +# 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 @@ -113,7 +121,7 @@ jobs: checks: name: checks needs: changes - if: needs.changes.outputs.rust == 'true' || needs.changes.outputs.deps == 'true' + if: github.event_name != 'push' && (needs.changes.outputs.rust == 'true' || needs.changes.outputs.deps == 'true') runs-on: ubuntu-latest timeout-minutes: 10 steps: @@ -126,10 +134,11 @@ jobs: - 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: needs.changes.outputs.web == 'true' || needs.changes.outputs.deps == 'true' + if: github.event_name != 'push' && (needs.changes.outputs.web == 'true' || needs.changes.outputs.deps == 'true') runs-on: ubuntu-latest timeout-minutes: 15 steps: @@ -162,7 +171,8 @@ jobs: # 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. + # 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 @@ -173,6 +183,7 @@ jobs: - 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. @@ -180,9 +191,14 @@ jobs: # installing sqlx-cli. prefix-key: v1-rust save-if: ${{ github.ref == 'refs/heads/main' }} - - run: just rust lint - - run: just doc - - run: just doc-test + # 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 @@ -200,7 +216,8 @@ jobs: - *setup-node - *rust-cache - run: just install - - run: just publish --dry-run + - 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, @@ -222,8 +239,10 @@ jobs: echo "RUSTUP_TOOLCHAIN=$msrv" >> "$GITHUB_ENV" - *install-just - *rust-cache - - run: cargo check --locked --all-features --package sourceorigin-common --package sourceorigin-crypto --package sourceorigin-auth - - run: just rust features + - 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 @@ -251,12 +270,17 @@ jobs: # 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. - - run: just db install-sqlx + - 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. - - run: just coverage - - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + # + # 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 @@ -264,7 +288,14 @@ jobs: # 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. - - run: just db prepare-check + - 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 @@ -326,11 +357,13 @@ jobs: - run: just install # The binary embeds the passkey script and the stylesheet, as in the # deployed image. - - run: just rust build + - 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" @@ -345,6 +378,7 @@ jobs: # 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' { @@ -370,8 +404,10 @@ jobs: 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. - - run: pnpm exec playwright install --only-shell chromium - - run: just web test-browser + - 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 @@ -418,12 +454,15 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - *install-just - *rust-cache - - run: cargo install --locked piquelctl - - run: just infra check + - 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: @@ -453,5 +492,5 @@ jobs: steps: - uses: re-actors/alls-green@b5b5b37504aa4183270bd3d855c52a67f212be35 # v1.3.0 with: - allowed-skips: checks, web, rust, rust-lint, package, msrv, e2e, docker, infra + allowed-skips: checks, web, rust, rust-lint, package, msrv, e2e, docker, infra, docs jobs: ${{ toJSON(needs) }} diff --git a/docs/dev/releasing.md b/docs/dev/releasing.md index 6526df94c..0b2b47f45 100644 --- a/docs/dev/releasing.md +++ b/docs/dev/releasing.md @@ -113,7 +113,7 @@ toolchain of `rust-toolchain.toml`, Node and pnpm. git switch main && git pull ``` - Wait for its CI run to pass. + The merge queue tested this exact commit before merging it. 3. Check the release without changing anything: ```console diff --git a/docs/dev/testing.md b/docs/dev/testing.md index 0622a1dc4..796851f56 100644 --- a/docs/dev/testing.md +++ b/docs/dev/testing.md @@ -219,9 +219,27 @@ pull request, since a change anywhere can break a link to it. The `changes` job in [ci.yml](https://github.com/sourceorigin-dev/sourceorigin/blob/main/.github/workflows/ci.yml) has the exact filters. -The merge queue, pushes to `main` and manual runs run every job. The `ci` check -sums the others up: it fails if any job failed, and passes when the rest -succeeded or were skipped. It is the one check the merge queue waits for. +The merge queue and manual runs run every job. The `ci` check sums the others +up: it fails if any job failed, and passes when the rest succeeded or were +skipped. It is the one check the merge queue waits for. + +`main` receives the exact commit the merge queue tested, so a push to `main` +doesn't test it again. It only refreshes the caches that pull requests and the +merge queue start from, since GitHub lets every branch read `main`'s caches: + +- `checks` and `docs` save no cache, and `web` saves only the pnpm store, + which `package` and `e2e` save too, so `main` skips them. +- `docker` builds the images, saving their layers. +- The jobs that restore a Rust cache build only when no cache is saved under + their current key, as after a dependency or toolchain change, or after GitHub + evicts an unused cache. Then they build without testing. `package` and + `msrv` run as usual, since they only build. `rust-lint` runs Clippy and + rustdoc, and compiles the doc tests without running them. `rust` runs + `just coverage-build` and `just db check`, `e2e` builds the binaries without + starting the browser suite, and `infra` installs piquelctl without checking + the manifests. + +A commit's coverage report is in its merge queue run. Coverage is reported, never enforced. `rust` prints it per crate and uploads `target/lcov.info` as the `rust-coverage` artifact, and `just web test` prints diff --git a/just/db.just b/just/db.just index 5403963ab..6e1f20c2d 100644 --- a/just/db.just +++ b/just/db.just @@ -35,9 +35,16 @@ prepare: # Test targets and the `test-util` feature are included so checked queries # compiled only for tests are cached too. +prepare_targets := '--all-targets --all-features' + [positional-arguments] _prepare *ARGS: - @cd crates/database && cargo sqlx prepare "$@" -- --all-targets --all-features + @cd crates/database && cargo sqlx prepare "$@" -- {{ prepare_targets }} + +# CI's pushes to main run it to cache the build `prepare-check` compiles. +# Compile what `prepare` checks, from the committed query cache, with no database. +check: + @cd crates/database && cargo check --locked {{ prepare_targets }} # DATABASE_URL, TEST_DATABASE_URL and libpq's PG* variables point at the cluster, # which listens only on a socket under /tmp (socket paths are limited to about 100 diff --git a/justfile b/justfile index 50fb28a2d..264d95714 100644 --- a/justfile +++ b/justfile @@ -77,8 +77,15 @@ test *ARGS='--workspace': doc: @RUSTDOCFLAGS='-D warnings' cargo doc --locked --workspace --no-deps -doc-test: - @cargo test --locked --doc --workspace +# CI's pushes to main pass `--list`, which compiles the merged doc tests +# without running them; one that can't be merged compiles only when it runs. +# Run the doc tests; extra arguments go to them. +[positional-arguments] +doc-test *ARGS: + @cargo test --locked --doc --workspace -- "$@" + +# The instrumented test build `coverage` runs and `coverage-build` compiles. +llvm_cov := 'cargo llvm-cov nextest --locked --workspace' # Uses a scratch cluster unless TEST_DATABASE_URL names a disposable database, # which the database tests leave migrated. Instrumented builds live in @@ -91,7 +98,7 @@ coverage *ARGS: #!/usr/bin/env bash set -euo pipefail if [[ -z "${TEST_DATABASE_URL:-}" ]]; then exec just db scratch just coverage "$@"; fi - cargo llvm-cov nextest --locked --workspace --run-ignored all --lcov --output-path target/lcov.info "$@" + {{ llvm_cov }} --run-ignored all --lcov --output-path target/lcov.info "$@" # lcov names each source file by absolute path; its crate is the # apps/ or crates/ directory holding it. awk -v root="$PWD/" ' @@ -106,6 +113,11 @@ coverage *ARGS: close("sort"); print row("workspace", LH, LF, FH, FF) }' target/lcov.info +# CI's pushes to main run it to cache the build without running a test. +# Compile every test `coverage` runs, instrumented, and run none of them. +coverage-build: + @{{ llvm_cov }} --no-report -E 'none()' --no-tests=pass + # Regenerate tests/sdk-vectors; `just test` fails while the committed files are stale. sdk-vectors: @UPDATE_SDK_VECTORS=1 cargo nextest run --locked -p sourceorigin-crypto --test sdk_vectors