Skip to content
Merged
33 changes: 30 additions & 3 deletions .buildkite/commands/checkout-release-branch.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
#!/bin/bash -eu

# Checks out the `release/*` branch for a given release version.
#
# Usage: checkout-release-branch.sh [<RELEASE_VERSION>]
#
# The release version is taken from the first of these that is set and non-empty:
# 1. the first argument
# 2. the `RELEASE_VERSION` environment variable
# 3. the `release/*` branch the build is running on, via `BUILDKITE_BRANCH`
#
# Buildkite, by default, checks out a specific commit, ending up in a detached HEAD state.
# But some release steps need to be on the `release/*` branch instead, namely:
# - when a `release-pipelines/*.yml` needs to `git push` to the `release/*` branch (for version bumps)
# - when a job `pipeline upload`'d by such a pipeline builds from that branch, so that the build
# includes the commit that the version bump just added.

echo "--- :git: Checkout Release Branch"

RELEASE_VERSION="${1?Please provide a release version as an argument.}"
RELEASE_VERSION="${1:-${RELEASE_VERSION:-}}"

if [[ -z "$RELEASE_VERSION" && "${BUILDKITE_BRANCH:-}" =~ ^release/ ]]; then
RELEASE_VERSION="${BUILDKITE_BRANCH#release/}"
fi

if [[ -z "$RELEASE_VERSION" ]]; then
echo "Error: no release version. Pass it as \$1, set RELEASE_VERSION, or run on a release/* branch." >&2
exit 1
fi

# Buildkite, by default, checks out a specific commit. For many release actions, we need to be
# on a release branch instead.
BRANCH_NAME="release/${RELEASE_VERSION}"
git fetch origin "$BRANCH_NAME"
git checkout "$BRANCH_NAME"
# Buildkite can reuse a working copy where "$BRANCH_NAME" was left at a different commit by a previous job,
# so force the local branch to the fetched commit.
# - `reset --hard` rather than `git pull`, to avoid merging if the two diverged
# - `FETCH_HEAD` rather than `origin/$BRANCH_NAME`, which `git fetch <branch>` only updates opportunistically.
git reset --hard FETCH_HEAD
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ GEM
ast (2.4.3)
atomos (0.1.3)
aws-eventstream (1.4.0)
aws-partitions (1.1274.0)
aws-partitions (1.1277.0)
aws-sdk-core (3.254.0)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.992.0)
Expand All @@ -21,7 +21,7 @@ GEM
aws-sdk-kms (1.130.0)
aws-sdk-core (~> 3, >= 3.254.0)
aws-sigv4 (~> 1.5)
aws-sdk-s3 (1.228.1)
aws-sdk-s3 (1.228.2)
aws-sdk-core (~> 3, >= 3.254.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.5)
Expand Down Expand Up @@ -168,7 +168,7 @@ GEM
google-apis-firebaseappdistribution_v1alpha (>= 0.12.0)
fastlane-plugin-sentry (1.29.0)
os (~> 1.1, >= 1.1.4)
fastlane-plugin-wpmreleasetoolkit (14.11.1)
fastlane-plugin-wpmreleasetoolkit (14.11.2)
buildkit (~> 1.5)
chroma (= 0.2.0)
diffy (~> 3.3)
Expand Down Expand Up @@ -251,7 +251,7 @@ GEM
mutex_m
java-properties (0.3.0)
jmespath (1.6.2)
json (2.21.1)
json (2.21.2)
jwt (3.2.0)
base64
kramdown (2.5.2)
Expand Down
Loading