Skip to content

Commit a7bfac4

Browse files
AliSoftwareclaude
andcommitted
Standardize checkout-release-branch.sh across all product repos
The script had drifted into five different shapes across the repos: argument required via `${1?…}` or `${1:?…}`, argument plus a `BUILDKITE_BRANCH` fallback, argument with a hand-rolled usage check, the same under a different variable name, and — in one repo — no argument at all, reading `RELEASE_VERSION` from the environment. Having rolled the same one-line fix out thirteen times this week, the divergence is pure friction, so this settles on a single canonical version. The resolution order is a superset of what every repo did before — argument, then `RELEASE_VERSION` from the environment, then the `release/*` branch the build runs on — so no call site needed changing. The `BUILDKITE_BRANCH` fallback only ever fires on a branch matching `^release/`, and it derives the branch name back from that same value, so it cannot select a branch other than the one the build was already triggered on. It also closes two latent bugs. Under `bash -eu`, `[[ -z "${RELEASE_VERSION}" ]]` on an unset variable and a bare `RELEASE_VERSION=$1` with no arguments both abort with `unbound variable` before their intended usage message can print. And an argument that is passed but empty — which happens when a pipeline forwards an unset `$RELEASE_VERSION` — is now a hard error everywhere, rather than resolving to `release/` or silently falling through to the current branch. The redundant `echo '--- :git: Checkout Release Branch'` in simplenote-android's pipelines is dropped, since the canonical script prints that group header itself. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 7b9b476 commit a7bfac4

5 files changed

Lines changed: 28 additions & 9 deletions

File tree

.buildkite/commands/checkout-release-branch.sh

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,35 @@
11
#!/bin/bash -eu
22

3-
if [[ -z "${RELEASE_VERSION}" ]]; then
4-
echo "RELEASE_VERSION is not set."
5-
exit 1
3+
# Checks out the `release/*` branch for a given release version.
4+
#
5+
# Usage: checkout-release-branch.sh [<RELEASE_VERSION>]
6+
#
7+
# The release version is taken from, in order of precedence:
8+
# 1. the first argument, if one is passed
9+
# 2. the `RELEASE_VERSION` environment variable
10+
# 3. the `release/*` branch the build is running on, via `BUILDKITE_BRANCH`
11+
#
12+
# Buildkite, by default, checks out a specific commit, ending up in a detached HEAD state.
13+
# But some release steps need to be on the `release/*` branch instead, namely:
14+
# - when a `release-pipelines/*.yml` needs to `git push` to the `release/*` branch (for version bumps)
15+
# - when a job `pipeline upload`'d by such a pipeline builds from that branch, so that the build
16+
# includes the commit that the version bump just added.
17+
18+
echo "--- :git: Checkout Release Branch"
19+
20+
if [[ $# -gt 0 ]]; then
21+
# An argument was passed explicitly, so it must not be empty — that would mean the caller
22+
# meant to forward a version but it resolved to nothing, which is a pipeline misconfiguration.
23+
RELEASE_VERSION="${1:?release version argument was passed but is empty}"
24+
elif [[ -n "${RELEASE_VERSION:-}" ]]; then
25+
: # Already provided through the pipeline environment
26+
elif [[ "${BUILDKITE_BRANCH:-}" =~ ^release/ ]]; then
27+
RELEASE_VERSION="${BUILDKITE_BRANCH#release/}"
28+
else
29+
echo "Error: no release version. Pass it as \$1, set RELEASE_VERSION, or run on a release/* branch." >&2
30+
exit 1
631
fi
732

8-
# Buildkite, by default, checks out a specific commit.
9-
# For many release actions, we need to be on a release branch instead.
1033
BRANCH_NAME="release/${RELEASE_VERSION}"
1134
git fetch origin "$BRANCH_NAME"
1235
git checkout "$BRANCH_NAME"

.buildkite/release-pipelines/complete-code-freeze.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ steps:
1414
echo '--- :robot_face: Use bot for Git operations'
1515
source use-bot-for-git
1616
17-
echo '--- :git: Checkout release branch'
1817
.buildkite/commands/checkout-release-branch.sh
1918
2019
echo '--- :ruby: Set up Ruby Tools'

.buildkite/release-pipelines/finalize-release.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ steps:
88
echo '--- :robot_face: Use bot for git operations'
99
source use-bot-for-git
1010
11-
echo '--- :git: Checkout Release Branch'
1211
.buildkite/commands/checkout-release-branch.sh
1312
1413
echo '--- :ruby: Set up Ruby Tools'

.buildkite/release-pipelines/new-beta-release.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ steps:
88
echo '--- :robot_face: Use bot for Git operations'
99
source use-bot-for-git
1010
11-
echo '--- :git: Checkout release branch'
1211
.buildkite/commands/checkout-release-branch.sh
1312
1413
echo '--- :ruby: Set up Ruby Tools'

.buildkite/release-pipelines/publish-release.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ steps:
88
echo '--- :robot_face: Use bot for git operations'
99
source use-bot-for-git
1010
11-
echo '--- :git: Checkout Release Branch'
1211
.buildkite/commands/checkout-release-branch.sh
1312
1413
echo '--- :ruby: Setup Ruby Tools'

0 commit comments

Comments
 (0)