fix(hooks): skip pre-push checks for tag-only pushes - #78
Merged
Conversation
.husky/pre-push ran scripts/check.sh --all unconditionally, with no inspection of what was being pushed. Pushing a release tag therefore re-ran the full build and integration suite against a commit that had already passed the same hook when its branch was pushed, and passed CI on top of that. During v0.18.0 this added 5m20s to the release and looked like a hang. The hook now reads the ref lines git sends on stdin and exits early only when every ref is a tag. Anything else, including a mixed branch-and-tag push or input it cannot classify, runs the checks exactly as before, so no code can reach the remote unchecked. Tests run the real hook against a stubbed check.sh that records whether it was invoked, so a regression in the guard fails in milliseconds instead of starting a real multi-minute check run inside the suite.
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.
Problem
.husky/pre-pushranscripts/check.sh --allunconditionally, without looking at what was being pushed. A release tag carries no new code: the commit it points at was already checked by this same hook when its branch was pushed, and again by CI. Re-running build + the full integration suite there can never produce a different answer.Concretely, during the v0.18.0 release,
git push origin v0.18.0spent 5m20s re-running the suite and read as a hang.Fix
The hook now reads the ref lines git sends on stdin (
<local-ref> <local-oid> <remote-ref> <remote-oid>) and exits early only when every ref is a tag.It deliberately fails safe: a push carrying any branch ref, a mixed branch-and-tag push, or stdin it cannot classify (empty/unexpected) runs the checks exactly as before. No code path reaches the remote unchecked.
Tests
Seven cases in
test/integration/hooks.test.tsrun the real.husky/pre-pushagainst a stubbedscripts/check.shthat touches a marker file instead of executing the real suite. That keeps the test honest (it exercises the actual shipped hook, not a copy of its logic) while ensuring a regression in the guard fails in milliseconds rather than starting a multi-minute check run inside the test suite.Covered: single tag, multiple tags, tag deletion, branch push, mixed branch+tag, empty stdin, and that a failing
check.shstill blocks a branch push with exit 1.