Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .agents/skills/sourceorigin-cleanup/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <id> -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
Expand Down
101 changes: 72 additions & 29 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -173,16 +183,26 @@ 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.
# 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' }}
- run: just rust lint
- run: just doc
- run: just doc-test
# Pushes to main only check whether their key has a cache: most
# have one and build nothing, so a download would go unused. A miss
# builds from nothing.
lookup-only: ${{ github.event_name == 'push' }}
# 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
Expand All @@ -200,7 +220,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,
Expand All @@ -222,8 +243,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
Expand Down Expand Up @@ -251,20 +274,32 @@ 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
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.
- 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
Expand Down Expand Up @@ -326,11 +361,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"
Expand All @@ -345,6 +382,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'
{
Expand All @@ -370,8 +408,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
Expand Down Expand Up @@ -418,12 +458,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:
Expand Down Expand Up @@ -453,5 +496,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) }}
2 changes: 1 addition & 1 deletion docs/dev/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 22 additions & 3 deletions docs/dev/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,28 @@ 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. They only check whether that cache exists, without
downloading it, so a miss builds from nothing, and 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
Expand Down
9 changes: 8 additions & 1 deletion just/db.just
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 15 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/<name> or crates/<name> directory holding it.
awk -v root="$PWD/" '
Expand All @@ -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
Expand Down