ci(pre-commit): seed hook-env cache on push to default branch - #12
Merged
Conversation
Run the advisory workflow on push to the repo default branch (in addition to PRs) and use `pre-commit install-hooks` to populate ~/.cache/pre-commit without executing hooks. PR-only steps (PR-diff run, sticky comment, status reflection) are gated behind `github.event_name == 'pull_request'`. Why: GitHub Actions caches are scoped per branch — a PR branch can only restore caches from itself or the repo default branch. Without a default-branch run, that scope is never seeded, so every new PR branch rebuilt every hook env from scratch on its first push. Callers that already trigger on push:main and drop the PR-only `if:` on their caller-side `pre-commit:` job get the speed-up automatically. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pre-commit install-hooksto populate~/.cache/pre-commitwithout executing any hook (so we don't replay org-wide debt on main).github.event_name == 'pull_request'.Why
GitHub Actions caches are scoped per branch — a PR branch can only restore caches from itself or the repo default branch. The previous job-level
if: github.event_name == 'pull_request'meant the default-branch scope was never seeded, so every new PR branch rebuilt every hook env from scratch on its first push (the symptom reported: "pre-commit seems to be starting from scratch every time").After this change, one merge to
mainseeds the cache, and subsequent PR branches restore via the exact key (when.pre-commit-config.yamlis unchanged) or therestore-keysprefix (when only some hooks change — partial rebuild). Same fix benefits the~/.dotnet/toolscache (csharpier) and the pnpm store.Caller-side follow-up
Callers that currently gate their
pre-commit:job withif: github.event_name == 'pull_request'need to drop that guard so the reusable workflow triggers on push tomain. Companion PR opening inpinpredict/tradingas a reference.Test plan
Pre-commit (advisory)runs on the merge commit in a consumer repo (e.g. trading) and the run log showsInstall pre-commit hook envs (cache seed)stepCache pre-commit hook envsstep reports a cache hit (or partial restore viarestore-keys) and thatpre-commit runskips env install🤖 Generated with Claude Code