Skip to content

Post step: skip the mirror refresh when the commit is denied, and add refresh-mirror - #66

Open
lewisl9029 wants to merge 2 commits into
useblacksmith:mainfrom
sazabi:skip-refresh-when-commit-denied
Open

lewisl9029 wants to merge 2 commits into
useblacksmith:mainfrom
sazabi:skip-refresh-when-commit-denied

Conversation

@lewisl9029

@lewisl9029 lewisl9029 commented Nov 3, 2026 •

Copy link
Copy Markdown

Summary

With sticky disk branch protection on, jobs outside the default branch can't commit the git mirror. The post step still refreshes the mirror for every shallow checkout, then discards it. That refresh is a git ls-remote over every branch and tag plus a fetch of each changed ref. On a busy repository (about 1,500 refs) it took 3 to 29 s per job, median about 15 s, at the end of every pull-request job.

This change skips the deferred refresh when the host has already denied the job's commit (commitEarlyDenyReason). It also adds a refresh-mirror input (default true) so a workflow can turn the refresh off explicitly.

What changed

  • src/main.ts: the post step checks deferredRefreshSkipReason before the deferred syncMirrorFromRemote, and logs [git-mirror] Skipping mirror refresh: <reason> instead of syncing. Nothing else changes. The mirror stays unchanged, so the existing !mirrorChanged path releases the disk without committing, and maintenance is skipped as before.
  • src/mirror-refresh.ts (new): the skip decision and the input parsing, as pure functions, with tests in __test__/mirror-refresh.test.ts.
  • action.yml, README.md: document refresh-mirror. It only affects the post-step refresh after shallow checkouts. Full checkouts (fetch-depth: 0) still sync before populating the workspace.
  • dist/index.js: hand-applied. A rebuild needs the private @buf/blacksmith_vm-agent package, so this commit mirrors the source change in the bundle. Please regenerate dist/ with npm run build before merging; check-dist will flag the difference.

Validation

  • node --check dist/index.js passes.
  • I could not run npm test or the build: both need BUF_TOKEN.
  • We are running this branch in our own CI under branch protection, and pull-request jobs log the skip.

Start Proof
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.


Start Proof
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need. (Staging)

… refresh-mirror

The deferred mirror refresh (ls-remote plus a fetch of every changed branch
and tag) only pays off when the sticky disk is committed afterwards. Under
sticky disk branch protection the host denies the commit at mount time, yet
the post step still refreshed the mirror and then discarded it, adding
seconds to tens of seconds to the end of every non-default-branch job.

Skip the refresh when the commit is already denied, and add a
refresh-mirror input (default true) to skip it explicitly.
Hand-applied: dist/index.js needs the private buf.build vm-agent package
to rebuild, so this mirrors the src/main.ts and src/mirror-refresh.ts
change in the bundle. Regenerating dist with npm run build should produce
the same behavior.
@lewisl9029

Copy link
Copy Markdown
Author

Some more context: we actually ended up doing refresh-mirror: false on every job, except a single new job dedicated to just cloning and refreshing the mirror on main, so we only need to incur this cost once there in parallel with everything else, instead of serially at the end of every job.

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