Skip to content

ci: add cargo-affected jobs (advisory) - #2475

Merged
max-sixty merged 3 commits into
mainfrom
affected
Apr 30, 2026
Merged

max-sixty merged 3 commits into
mainfrom
affected

Conversation

@max-sixty

@max-sixty max-sixty commented Apr 29, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds two CI jobs that exercise cargo affected against this repo as an advisory signal alongside the existing full test matrix.

  • collect-affected runs on push to main and on workflow_dispatch. It builds with coverage instrumentation, runs every test, and writes target/affected/coverage.db to actions/cache.
  • affected-tests runs on PRs as continue-on-error: true. It restores the cached DB and runs cargo affected run --features shell-integration-tests. Failures don't block merges.

Cache strategy

  • Cargo-affected installs from https://github.com/max-sixty/cargo-affected with no rev/branch/tag pin — baptiste0928/cargo-install resolves the latest default-branch sha at install time and caches the binary per-resolved-rev.
  • The PR job's primary cache key is the PR/main merge-base. Exact match → tight diff (PR changes only) → minimal selection.
  • Restore-keys fall back to the most recent main DB. With Fall back to all tests when selection can't be precise, cargo affected run runs all tests with a notice whenever it can't compute a precise selection — Cargo.lock change, divergent collect_sha, or no DB at all. So affected-tests always produces a useful run, even before the cache is seeded.
  • Cache key has a manual db-v1- marker. Bump it if cargo-affected ships an on-disk schema change; the cache is otherwise version-agnostic.

TODO

Once selection accuracy is calibrated against the full suite, gate the full test (linux/macos/windows) matrix to run only on pushes to main and on PRs with a full-tests label (or similar). PR pushes would default to affected-only. The full suite could fold into the existing nightly workflow.

Periodic full runs remain essential — cargo-affected misses non-Rust inputs (include_str!, templates, SQL), build-time inputs not in its fingerprint (build.rs, rust-toolchain.toml, .cargo/config.toml), and proc-macro source edits.

Test plan

  • Bootstrap PR (no DB cached): affected-tests runs cargo affected run which falls back to all tests via the upstream fix. ~6m28s on this PR vs. 5m31s for test (linux) — the ~1m delta is install + cargo-affected setup.
  • On merge to main: collect-affected runs and seeds the cache.
  • On a follow-up PR: affected-tests restores the cache, exact-match merge-base works, selection is non-empty.
  • Stale-PR scenario: open a PR, push more commits to main, confirm restore-keys fallback hits and cargo affected run runs all tests via the fallback path.
  • Cargo.lock change: confirm env-fingerprint mismatch path runs all tests.

🤖 Generated with Claude Code

Adds two jobs:

- `collect-affected` runs on push to main and refreshes
  `target/affected/coverage.db` via `cargo affected collect`. Caches it
  to actions/cache keyed on `runner.os` + the cargo-affected git rev
  (resolved at runtime — schema bumps invalidate stale DBs) + the main
  commit sha.

- `affected-tests` runs on PRs as a `continue-on-error` advisory job.
  Restores the DB with the PR's merge-base as the primary key (tight
  diff when collect ran on that exact commit) and a prefix
  restore-keys fallback to the most recent main DB. cargo-affected's
  "fall back to all tests when selection can't be precise" behavior
  (max-sixty/cargo-affected@9afb870) means the fallback path always
  produces a useful run rather than bailing.

Comments document the storage rationale and a TODO to gate the full
test matrix on merges + labeled PRs once selection accuracy is
calibrated.

Co-Authored-By: Claude <[email protected]>
max-sixty and others added 2 commits April 29, 2026 14:49
`baptiste0928/cargo-install` with no `rev:`/`branch:`/`tag:` already
resolves to the default branch's HEAD via `git ls-remote` and exposes
the resolved sha as an output — the explicit resolve step was redundant.

Drop the resolve step, omit `rev:` from the install (auto-tracks main),
and replace the rev component of the DB cache key with a manual
`db-v1-` marker. The marker is the hand-bumpable lever for handling
on-disk schema changes in cargo-affected; routine upstream commits no
longer invalidate the cache.

Co-Authored-By: Claude <[email protected]>
cargo-affected now falls back to running all tests when it can't
compute a precise selection (no DB, env-fingerprint mismatch, or
collect_sha not reachable from HEAD). The skip-on-cache-miss step and
the per-step `cache-matched-key != ''` gates were preventing exactly
the fallback behavior we want — the cached DB is now an optimization,
not a precondition.

Removing the gates means an empty/divergent cache produces a useful
"run all tests" advisory run instead of a silent skip. The cache
restore stays so exact-match merge-base hits still get a tight diff.

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit 7d9c279 into main Apr 30, 2026
27 checks passed
@max-sixty
max-sixty deleted the affected branch April 30, 2026 00:10
max-sixty added a commit that referenced this pull request Apr 30, 2026
## Summary

Both `collect-affected` and `affected-tests` (added in #2475) installed
the same 7 setup steps — cargo-insta, cargo-nextest, cargo-affected,
llvm-tools, rust-cache, apt shells, nushell. Lift them into
`.github/actions/affected-setup/action.yaml` so each job replaces the
block with one `uses:` line.

Pinned tool versions now live in one place. No behavior change — same
steps, same order.

## Test plan
- [x] `pre-commit run` passes on changed files
- [ ] `collect-affected` and `affected-tests` jobs still install the
same toolchain in CI

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants