Skip to content

ci: run the corpus without the race detector, cache golangci-lint, scan the image only when it changed - #606

Merged
thomasboni merged 3 commits into
mainfrom
ci/test-corpus-split
Nov 9, 2026
Merged

thomasboni merged 3 commits into
mainfrom
ci/test-corpus-split

Conversation

@thomasboni

@thomasboni thomasboni commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

ci

What this PR does / why we need it:

A pull request waits 5 minutes for CI, and 4.5 of them are the Test job. Measured on the last 39 PR runs: Test median 4.5 min, every other job under 2.5 min. Inside Test, one test is the whole cost: TestCorpus replays the 210 captured repositories through the policy engine and accounts for 90 of the 91 seconds of test time in the control package, and -race multiplies OPA evaluation by about six.

go test (8 cores; the runner has 4) time
whole suite, no race 30 s
whole suite, -race 146 s
control package, -race 119 s
control package, -race, corpus skipped 27 s
corpus alone, no race 14.5 s
whole suite, -race, corpus skipped 32 s

Three changes, all in ci.yml:

  • Test runs go test ./... -race -skip '^TestCorpus$'. A new Corpus job runs go test ./control -run '^TestCorpus$' without the race detector. The corpus is a deterministic replay; every other test of the package, the five TestCorpus* siblings included, keeps running under -race, which is where the engine's concurrency is exercised.
  • Lint caches the linter binary (keyed on its commit pin, which is immutable) and ~/.cache/golangci-lint with actions/cache, and skips the go install on a hit: building the linter from source was most of the two minutes this step cost, the analysis cache makes the rest incremental.
  • Container Scan builds and scans the image only when Dockerfile, go.mod, go.sum or the workflow changed against the base branch, through a plain git diff. Every push to main still scans.

Expected PR wall-clock: about 2 min instead of 5, bounded by the review jobs.

Which issue(s) this PR is related to:

None.

Special notes for your reviewer:

  • -skip and -run are regular expressions, hence the anchors: only TestCorpus itself moves.
  • No third-party action is added; actions/cache is under a trusted owner. The self-scan of this branch with the current CLI gives score A, no finding.
  • The coverage artifact now excludes the corpus run. Nothing consumes it in the workflow.

Does this PR introduce a user-facing change?

NONE

How was this tested?

The CI runs of this PR, measured on the run page:

Job Before (median of 39 PR runs) This PR
Test 4.5 min 2.0 to 2.5 min
Corpus (new, parallel) 0.9 min
Lint 2.2 min 1.0 min once the cache is warm (2.2 on the run that fills it)
Container Scan 2.3 min 2.8 min here because ci.yml changed; skipped in about 10 s on a PR that touches neither the Dockerfile nor the module graph

The first push failed at workflow start: the org's lockfile policy refuses a workflow whose action is not in actions.lock, so the lockfile is regenerated with gh actions-lock in the same commit.

AI usage disclosure:

YES. Claude Code measured the runs, profiled the suite and wrote the workflow change under the author's direction.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Ft8dmcMLK7V9XZh7JX4vzs

@thomasboni
thomasboni force-pushed the ci/test-corpus-split branch 3 times, most recently from df3e749 to b5b314e Compare November 9, 2026 05:21
Comment thread .github/workflows/ci.yml Resolved
@thomasboni
thomasboni requested review from Exypte and removed request for Totara-thib and coconux3 November 9, 2026 05:41
…an the image only when it changed

The Test job carried 4.5 of a PR's 5 minutes, and one test was the reason: TestCorpus replays 210 captured repositories through the policy engine, 90 of the 91 seconds of test time in the control package, and -race multiplies OPA evaluation by about six. The corpus now runs in its own job without -race; the other 735 tests of the package keep the race detector. Lint restores golangci-lint's analysis cache between runs, and the container scan runs only when the Dockerfile or the module graph changed.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ft8dmcMLK7V9XZh7JX4vzs
@thomasboni
thomasboni force-pushed the ci/test-corpus-split branch from b5b314e to d440062 Compare November 9, 2026 05:42
…arden the scan gate

TestCorpus is the only t.Parallel test in the control package, so it is
what race-checks the OPA engine's shared caches: the Corpus job keeps
-race and still runs in parallel with Test.

golangci-lint runs through golangci-lint-action, pinned in actions.lock,
in place of the hand-rolled binary cache.

The image scan gate also watches .dockerignore and scans when the base
commit cannot be fetched instead of failing the job.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Exypte

Exypte commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

I reviewed this and pushed 3523984 on top of it. Changes:

Corpus keeps -race. TestCorpus is the only t.Parallel test in control (corpus_test.go:220). Without it, nothing race-checks the engine's shared state: preparedQueries in internal/engine/opa/prepared.go and libraryModules in engine.go. The other 735 tests run serially, so the comment saying they cover the concurrency was wrong. The corpus still gets its own job, which runs in parallel with Test. The PR's wall clock will likely stay close to the Corpus job's duration, not drop to the Test job's.

Lint goes through golangci/golangci-lint-action@v9.3.0 (version: v2.10.1, commit pinned in actions.lock by gh actions-lock). This replaces the actions/cache + go install setup, which had several problems:

  • The key did not include the Go version. After a Go bump, the restore-key would bring back a binary built with the old Go, and golangci-lint v2 refuses to run on a newer target.
  • github.sha in the key saved a new cache entry on every run. That uses up the 10 GB quota and evicts the setup-go caches.
  • On a cache hit the binary ran without verification, while the comment still said sum.golang.org checks it.
  • id: lint-cache was never referenced.

The action downloads a checksummed release binary and handles the analysis cache itself.

Container scan gate:

  • Added .dockerignore to the watched paths, since it changes what COPY . . puts in the build.
  • If git fetch of the base SHA fails, the step now scans. Before, it failed the job.

Not changed, needs follow-up:

  • Add Corpus as a required check in branch protection. Otherwise a corpus regression shows red but no longer blocks the merge, as it did when it was part of Test.
  • coverage.out no longer covers the lines only the corpus reaches, so the coverage artifact will show a drop that isn't real.

Comment thread .github/workflows/ci.yml Fixed
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Exypte

Exypte commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Follow-up a261db8: adds golangci/golangci-lint-action to trustedGithubActions in .plumber.yaml. Without it, the Plumber gate flagged the new action as coming from an unauthorized source (90/100). All checks pass now. Corpus under -race takes about 3.5 min and Test about 1.7 to 2.5 min.

@thomasboni
thomasboni merged commit 3d71094 into main Nov 9, 2026
18 checks passed
@thomasboni
thomasboni deleted the ci/test-corpus-split branch November 9, 2026 22:18
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.

3 participants