Skip to content

ci: make auto-version.sh robust to shallow clones and forks#343

Open
prasanna-anchorage wants to merge 1 commit into
mainfrom
fix/auto-version-robustness
Open

ci: make auto-version.sh robust to shallow clones and forks#343
prasanna-anchorage wants to merge 1 commit into
mainfrom
fix/auto-version-robustness

Conversation

@prasanna-anchorage

Copy link
Copy Markdown
Contributor

What

Robustness fixes for scripts/auto-version.sh, found while porting it to anchorageoss/sqisign-rs (Copilot flagged them there; same code here). The version string format is unchanged — pure hardening.

  • Shallow clones: git rev-list --count HEAD / git merge-base are wrong on a shallow clone (actions/checkout defaults 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.
  • Hard-coded repo slug: remote detection matched only anchorageoss/visualsign-parser, so forks/renames silently fell back to origin. Derive the expected repo from $GITHUB_REPOSITORY (with AUTO_VERSION_REMOTE/AUTO_VERSION_REPO overrides), then the known slug, then origin.
  • Default-branch resolution: the old code set DEFAULT_BRANCH=master whenever main wasn't present locally without checking master exists — git merge-base then crashes under set -e. Now resolve main→master, fetching both if neither remote ref is present, and error clearly otherwise.

Test

shellcheck clean. Output unchanged on this branch: 0.722.0+… (both branch and simulated-main runs), matching the existing 0.<height>.<diff> scheme.

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings May 28, 2026 23:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (with AUTO_VERSION_REMOTE override) instead of the hard-coded anchorageoss/visualsign-parser slug.
  • Resolve default branch as mainmaster, attempting a fetch of both before erroring out, so git merge-base no longer crashes under set -e when neither remote-tracking ref exists.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/auto-version.sh
Comment on lines +84 to +85
git fetch "$REMOTE" main > /dev/null 2>&1 || true
git fetch "$REMOTE" master > /dev/null 2>&1 || true
@vikstrous2 vikstrous2 removed their request for review June 2, 2026 16:50
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.

2 participants