Skip to content

chore: better preflight checks in release.sh#2348

Open
dunglas wants to merge 3 commits intomainfrom
chore/improve-release-script
Open

chore: better preflight checks in release.sh#2348
dunglas wants to merge 3 commits intomainfrom
chore/improve-release-script

Conversation

@dunglas
Copy link
Copy Markdown
Member

@dunglas dunglas commented Apr 16, 2026

No description provided.

Copilot AI review requested due to automatic review settings April 16, 2026 15:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the release.sh workflow by adding pre-flight Git checks before proceeding with the release/tagging steps, helping prevent releases from an incorrect local state.

Changes:

  • Add a guard requiring the current branch to be main.
  • Require a clean working tree before releasing.
  • Fetch origin and ensure local main matches origin/main before continuing.

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

Comment thread release.sh Outdated
fi

git fetch origin
if [[ -n "$(git diff HEAD origin/main)" ]]; then
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

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

The up-to-date check uses git diff HEAD origin/main, which compares trees only. It can be empty even when HEAD is a different commit than origin/main (same tree, different history), causing the release tags to be created from the wrong commit. Consider verifying commit equality (e.g., compare git rev-parse HEAD vs git rev-parse origin/main, or otherwise ensure HEAD exactly matches the remote tip).

Suggested change
if [[ -n "$(git diff HEAD origin/main)" ]]; then
head_commit="$(git rev-parse HEAD)"
origin_main_commit="$(git rev-parse origin/main)"
if [[ "${head_commit}" != "${origin_main_commit}" ]]; then

Copilot uses AI. Check for mistakes.
Comment thread release.sh Outdated
fi

git fetch origin
if [[ -n "$(git diff HEAD origin/main)" ]]; then
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

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

[[ -n "$(git diff HEAD origin/main)" ]] materializes the entire diff output into a shell variable, which is unnecessary and can be slow/memory-heavy on large diffs. Prefer a quiet check (e.g., git diff --quiet ...) and branch on the exit status.

Suggested change
if [[ -n "$(git diff HEAD origin/main)" ]]; then
if ! git diff --quiet HEAD origin/main; then

Copilot uses AI. Check for mistakes.
Comment thread release.sh
Comment on lines +49 to 54
git fetch origin
if [[ -n "$(git diff HEAD origin/main)" ]]; then
echo "Local main is not up to date with origin/main. Pull first." >&2
exit 1
fi

Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

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

The script now hardcodes origin/main (both in git fetch origin and in the comparison). This is a behavioral regression vs git pull because it will fail for clones that don't have a remote named origin or where main tracks a different upstream. Consider deriving the upstream ref from main’s configured tracking branch (e.g., @{u}) and fetching that, or emitting a clear error if no upstream is configured.

Suggested change
git fetch origin
if [[ -n "$(git diff HEAD origin/main)" ]]; then
echo "Local main is not up to date with origin/main. Pull first." >&2
exit 1
fi
upstream_ref="$(git rev-parse --abbrev-ref --symbolic-full-name '@{u}' 2>/dev/null || true)"
if [[ -z "${upstream_ref}" ]]; then
echo "The main branch has no configured upstream. Configure a tracking branch first." >&2
exit 1
fi
upstream_remote="${upstream_ref%%/*}"
git fetch "${upstream_remote}"
if [[ -n "$(git diff HEAD "${upstream_ref}")" ]]; then
echo "Local main is not up to date with ${upstream_ref}. Pull first." >&2
exit 1
fi

Copilot uses AI. Check for mistakes.
Using git rev-parse ensures we detect divergence even when tree content
is identical across different commits, and avoids materializing the
full diff output.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Provides actionable error messages so the user knows whether to pull,
push, or rebase when local main doesn't match origin/main.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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