Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions scripts/should_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,32 @@ if ! echo "$release_branches" | grep "release/2.26" >/dev/null; then
error "Could not find existing release branches. Did you run 'git fetch -ap ${remote}'?"
fi

latest_release_branch=$(echo "$release_branches" | tail -n 1)
latest_release_branch_version=${latest_release_branch#release/}
log "Latest release branch: $latest_release_branch"
log "Latest release branch version: $latest_release_branch_version"
# Step 2: Iterate from the latest release branch backwards to find the deploy
# branch. A release branch is the deploy target if its `.0` tag does not yet
# exist (i.e. the release is in progress / frozen). Release branches that only
# carry RC tags (v<x.y>.0-rc.*) are skipped — they are not considered frozen.
for branch in $(echo "$release_branches" | sort -Vr); do
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

P2 The RC-tag check couples this deploy logic to a tagging convention that is being retired ("no RC branches moving forward"). Going forward, the git tag -l branch on line 62 is effectively dead code that never triggers — but a future reader has to understand a defunct workflow to reason about correctness.

Consider an approach that doesn't depend on RC tags at all: find the latest released branch (has .0 tag), then check whether the next branch in version order exists:

for branch in $(echo "$release_branches" | sort -Vr); do
	version=${branch#release/}
	if git rev-parse "refs/tags/v${version}.0" >/dev/null 2>&1; then
		latest_released=$branch
		break
	fi
done

if [[ -n "${latest_released:-}" ]]; then
	frozen=$(echo "$release_branches" | grep -A1 "^${latest_released}$" | tail -n1)
	if [[ "$frozen" != "$latest_released" ]]; then
		deploy_branch=$frozen
	fi
fi

This expresses the real invariant directly ("frozen = the branch after the latest released one") rather than inferring it by elimination. No coupling to RC conventions, fewer git calls in the loop, and the logic stays correct whether RC tags exist or not.

Also a nit on this line: $release_branches is already sort -V'd on line 38. tac would be clearer — "same list, reversed" rather than re-sorting.

version=${branch#release/}
log "Checking release branch: $branch (version: $version)"

# Step 2: check if a matching tag `v<x.y>.0` exists. If it does not, we will
# use the release branch as the deploy branch.
if ! git rev-parse "refs/tags/v${latest_release_branch_version}.0" >/dev/null 2>&1; then
log "Tag 'v${latest_release_branch_version}.0' does not exist, using release branch as deploy branch"
deploy_branch=$latest_release_branch
else
log "Matching tag 'v${latest_release_branch_version}.0' exists, using main as deploy branch"
fi
if git rev-parse "refs/tags/v${version}.0" >/dev/null 2>&1; then
# Final .0 tag exists — this release (and all older ones) are done.
log "Tag 'v${version}.0' exists, release is complete"
break
fi

# No .0 tag. Check if there are RC tags, which would indicate this is
# an RC-only branch that we should skip.
if git tag -l "v${version}.0-rc.*" | grep -q .; then
log "Branch '$branch' only has RC tags, skipping"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nit Log says "only has RC tags" but the check verifies RC tags exist, not that they're the only tags. Minor wording mismatch — maybe "has RC tags but no final release, skipping" to match the actual condition.

continue
fi

# No .0 tag and no RC tags — this is the frozen release branch.
log "Branch '$branch' is the frozen release branch"
deploy_branch=$branch
break
done
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

P3 When the loop exhausts without finding a frozen branch (every candidate was either released or RC-only), deploy_branch stays main silently. The log on the next line shows the result but not the reason. Adding a message here would help operators triage unexpected main deploys:

done
if [[ "$deploy_branch" == "main" ]]; then
	log "No frozen release branch found, falling back to main"
fi

log "Deploy branch: $deploy_branch"

# Finally, check if the current branch is the deploy branch.
Expand Down
Loading