ci: make auto-version.sh robust to shallow clones and forks#343
Open
prasanna-anchorage wants to merge 1 commit into
Open
ci: make auto-version.sh robust to shallow clones and forks#343prasanna-anchorage wants to merge 1 commit into
prasanna-anchorage wants to merge 1 commit into
Conversation
Found while porting this script to anchorageoss/sqisign-rs; latent here too. Pure robustness -- the version string format is unchanged. - Shallow clones make `git rev-list --count` wrong. Detect a shallow repo and, on CI, deepen to full history (failing closed if still shallow so a release can't mint a bogus version); warn locally otherwise. - Derive the upstream remote from $GITHUB_REPOSITORY (with an AUTO_VERSION_REMOTE/AUTO_VERSION_REPO override), falling back to the known slug then "origin", so forks/renames don't silently fall back to origin and compute against the wrong remote. - Resolve the default branch as main, then master, fetching both if neither remote ref is present, instead of blindly setting `master` and letting `git merge-base` crash under `set -e`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Hardens scripts/auto-version.sh against environments where the prior assumptions (full clone, canonical upstream slug, presence of main) don't hold, without changing the produced version-string format.
Changes:
- Detect shallow repositories and deepen on CI (fail closed if still shallow); warn locally.
- Derive the expected upstream repo from
$GITHUB_REPOSITORY/AUTO_VERSION_REPO(withAUTO_VERSION_REMOTEoverride) instead of the hard-codedanchorageoss/visualsign-parserslug. - Resolve default branch as
main→master, attempting a fetch of both before erroring out, sogit merge-baseno longer crashes underset -ewhen neither remote-tracking ref exists.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+84
to
+85
| git fetch "$REMOTE" main > /dev/null 2>&1 || true | ||
| git fetch "$REMOTE" master > /dev/null 2>&1 || true |
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.
What
Robustness fixes for
scripts/auto-version.sh, found while porting it toanchorageoss/sqisign-rs(Copilot flagged them there; same code here). The version string format is unchanged — pure hardening.git rev-list --count HEAD/git merge-baseare wrong on a shallow clone (actions/checkoutdefaults to depth 1). Detect a shallow repo and, on CI, deepen to full history — failing closed if it's still shallow so a release can't mint a bogus version/tag; warn loudly locally.anchorageoss/visualsign-parser, so forks/renames silently fell back toorigin. Derive the expected repo from$GITHUB_REPOSITORY(withAUTO_VERSION_REMOTE/AUTO_VERSION_REPOoverrides), then the known slug, thenorigin.DEFAULT_BRANCH=masterwhenevermainwasn't present locally without checkingmasterexists —git merge-basethen crashes underset -e. Now resolve main→master, fetching both if neither remote ref is present, and error clearly otherwise.Test
shellcheckclean. Output unchanged on this branch:0.722.0+…(both branch and simulated-main runs), matching the existing0.<height>.<diff>scheme.🤖 Generated with Claude Code