| 1 |
#!/bin/bash -ex |
| 2 |
# |
| 3 |
# Copyright The OpenTelemetry Authors |
| 4 |
# SPDX-License-Identifier: Apache-2.0 |
| 5 |
|
| 6 |
# --- Configuration --- |
| 7 |
UPSTREAM_REMOTE_NAME=${UPSTREAM_REMOTE_NAME:-"upstream"} # Your upstream remote name for open-telemetry/opentelemetry-collector |
| 8 |
MAIN_BRANCH_NAME=${MAIN_BRANCH_NAME:-"main"} |
| 9 |
LOCAL_MAIN_BRANCH_NAME=${LOCAL_MAIN_BRANCH_NAME:-"${MAIN_BRANCH_NAME}"} |
| 10 |
# These variables are only used if git user.name and git user.email are not configured |
| 11 |
GIT_CONFIG_USER_NAME=${GIT_CONFIG_USER_NAME:-"otelbot"} |
| 12 |
GIT_CONFIG_USER_EMAIL=${GIT_CONFIG_USER_EMAIL:-"[email protected]"} |
| 13 |
|
| 14 |
# --- Extract release information from tag --- |
| 15 |
if [[ -z "$GITHUB_REF" ]]; then |
| 16 |
echo "Error: GITHUB_REF environment variable must be provided when running in GitHub Actions." |
| 17 |
echo "For manual usage: GITHUB_REF=refs/tags/v0.85.0 $0" |
| 18 |
exit 1 |
| 19 |
fi |
| 20 |
|
| 21 |
# Extract tag name and validate format using regex |
| 22 |
if [[ ! $GITHUB_REF =~ ^refs/tags/v([0-9]+\.[0-9]+)\.[0-9]+(-.+)?$ ]]; then |
| 23 |
echo "Error: GITHUB_REF did not match expected format (refs/tags/vX.XX.X)" |
| 24 |
exit 1 |
| 25 |
fi |
| 26 |
|
| 27 |
# Extract version numbers from regex match |
| 28 |
VERSION_MAJOR_MINOR=${BASH_REMATCH[1]} |
| 29 |
RELEASE_SERIES="v${VERSION_MAJOR_MINOR}.x" |
| 30 |
echo "Release series: ${RELEASE_SERIES}" |
| 31 |
|
| 32 |
# --- Use current commit as prepare release commit --- |
| 33 |
PREPARE_RELEASE_COMMIT_HASH="${GITHUB_SHA:-HEAD}" |
| 34 |
echo "Using current commit as prepare release commit: ${PREPARE_RELEASE_COMMIT_HASH}" |
| 35 |
|
| 36 |
RELEASE_BRANCH_NAME="release/${RELEASE_SERIES}" |
| 37 |
|
| 38 |
echo "Automating Release Steps for: ${RELEASE_SERIES}" |
| 39 |
echo "Release Branch Name: ${RELEASE_BRANCH_NAME}" |
| 40 |
echo "'Prepare release' commit hash: ${PREPARE_RELEASE_COMMIT_HASH}" |
| 41 |
echo "Upstream Remote: ${UPSTREAM_REMOTE_NAME}" |
| 42 |
echo "--------------------------------------------------" |
| 43 |
|
| 44 |
# --- Step 4: Checkout main, Pull, Create/Update and Push Release Branch --- |
| 45 |
echo "" |
| 46 |
echo "=== Step 4: Preparing and Pushing Release Branch ===" |
| 47 |
|
| 48 |
# 1. Checkout main |
| 49 |
git checkout "${LOCAL_MAIN_BRANCH_NAME}" |
| 50 |
|
| 51 |
# 2. Fetch from upstream (updates remote-tracking branches including potential existing release branch) |
| 52 |
git fetch "${UPSTREAM_REMOTE_NAME}" |
| 53 |
|
| 54 |
# 3. Rebase local main with upstream/main |
| 55 |
git rebase "${UPSTREAM_REMOTE_NAME}/${MAIN_BRANCH_NAME}" |
| 56 |
echo "'${LOCAL_MAIN_BRANCH_NAME}' branch is now up-to-date." |
| 57 |
|
| 58 |
# Verify the commit exists (it should be reachable from main after fetch) |
| 59 |
if ! git cat-file -e "${PREPARE_RELEASE_COMMIT_HASH}^{commit}" 2>/dev/null; then |
| 60 |
echo "Error: Provided 'Prepare release' commit hash '${PREPARE_RELEASE_COMMIT_HASH}' not found." |
| 61 |
exit 1 |
| 62 |
fi |
| 63 |
# 4. Handle Release Branch: Check existence, create or switch, and merge/base |
| 64 |
BRANCH_EXISTS_LOCALLY=$(git branch --list "${RELEASE_BRANCH_NAME}") |
| 65 |
# Check remote by looking for the remote tracking branch ref after fetch |
| 66 |
if git rev-parse --verify --quiet "${UPSTREAM_REMOTE_NAME}/${RELEASE_BRANCH_NAME}" > /dev/null 2>&1; then |
| 67 |
BRANCH_EXISTS_REMOTELY=true |
| 68 |
fi |
| 69 |
|
| 70 |
if [[ -n "$BRANCH_EXISTS_LOCALLY" ]]; then |
| 71 |
echo "Release branch '${RELEASE_BRANCH_NAME}' found locally." |
| 72 |
echo "Please delete local release branch using 'git branch -D ${RELEASE_BRANCH_NAME}' and run the script again." |
| 73 |
exit 1 |
| 74 |
elif [[ -n "$BRANCH_EXISTS_REMOTELY" ]]; then |
| 75 |
echo "Release branch '${RELEASE_BRANCH_NAME}' found on remote '${UPSTREAM_REMOTE_NAME}'." |
| 76 |
echo "Nothing to do, exiting." |
| 77 |
exit 0 |
| 78 |
else |
| 79 |
echo "Release branch '${RELEASE_BRANCH_NAME}' not found locally or on remote." |
| 80 |
git switch -c "${RELEASE_BRANCH_NAME}" "${PREPARE_RELEASE_COMMIT_HASH}" |
| 81 |
fi |
| 82 |
|
| 83 |
echo "Current branch is now '${RELEASE_BRANCH_NAME}'." |
| 84 |
git --no-pager log -1 --pretty=oneline # Show the commit at the tip of the release branch |
| 85 |
|
| 86 |
# 5. Push the release branch to upstream |
| 87 |
git push -u "${UPSTREAM_REMOTE_NAME}" "${RELEASE_BRANCH_NAME}" |
| 88 |
echo "Branch '${RELEASE_BRANCH_NAME}' pushed (or updated) on '${UPSTREAM_REMOTE_NAME}'." |
| 89 |
echo "Step 4 completed." |
| 90 |
echo "--------------------------------------------------" |
| 91 |
|
| 92 |
echo "" |
| 93 |
echo "Automation for release branch creation complete." |
| 94 |
echo "Release branch '${RELEASE_BRANCH_NAME}' has been created from the prepare release commit." |
| 95 |
echo "Tag-triggered build workflows should now be running for the pushed tags." |