Skip to content

ci(pre-commit): seed hook-env cache on push to default branch - #12

Merged
blairham merged 1 commit into
mainfrom
precommit-cache-seed
Jun 2, 2026
Merged

ci(pre-commit): seed hook-env cache on push to default branch#12
blairham merged 1 commit into
mainfrom
precommit-cache-seed

Conversation

@blairham

@blairham blairham commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • 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 any hook (so we don't replay org-wide debt on main).
  • Gate the PR-only steps (PR-diff run, sticky comment, status reflection) 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. 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 main seeds the cache, and subsequent PR branches restore via the exact key (when .pre-commit-config.yaml is unchanged) or the restore-keys prefix (when only some hooks change — partial rebuild). Same fix benefits the ~/.dotnet/tools cache (csharpier) and the pnpm store.

Caller-side follow-up

Callers that currently gate their pre-commit: job with if: github.event_name == 'pull_request' need to drop that guard so the reusable workflow triggers on push to main. Companion PR opening in pinpredict/trading as a reference.

Test plan

  • Merge → confirm Pre-commit (advisory) runs on the merge commit in a consumer repo (e.g. trading) and the run log shows Install pre-commit hook envs (cache seed) step
  • Open a new PR branch in the consumer repo → confirm the Cache pre-commit hook envs step reports a cache hit (or partial restore via restore-keys) and that pre-commit run skips env install
  • Confirm no sticky PR comment is posted on push runs
  • Confirm the advisory still posts/updates its sticky comment on PR runs

🤖 Generated with Claude Code

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>
@blairham
blairham merged commit 38b207a into main Jun 2, 2026
@blairham
blairham deleted the precommit-cache-seed branch July 5, 2026 14:37
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.

1 participant