|
1 | 1 | #!/bin/bash -eu |
2 | 2 |
|
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 |
6 | 31 | fi |
7 | 32 |
|
8 | | -# Buildkite, by default, checks out a specific commit. |
9 | | -# For many release actions, we need to be on a release branch instead. |
10 | 33 | BRANCH_NAME="release/${RELEASE_VERSION}" |
11 | 34 | git fetch origin "$BRANCH_NAME" |
12 | 35 | git checkout "$BRANCH_NAME" |
|
0 commit comments