dimas-b commented on code in PR #2156: URL: https://github.com/apache/polaris/pull/2156#discussion_r2276970064
########## releasey/02-create-release-branch.sh: ########## @@ -0,0 +1,201 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +# +# Create Release Branch Script +# +# Automates the "Create release branch" section of the release guide. +# Creates a new release branch and sets the target release version. +# + +set -euo pipefail + +releasey_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +LIBS_DIR="${releasey_dir}/libs" + +source "${LIBS_DIR}/_log.sh" +source "${LIBS_DIR}/_constants.sh" +source "${LIBS_DIR}/_exec.sh" +source "${LIBS_DIR}/_version.sh" + +function usage() { + cat << EOF +$(basename "$0") --version VERSION [--commit GIT_COMMIT] [--recreate] [--help | -h] + + Creates a release branch and sets the target release version. + + Behavior: + - RC1: Creates the release branch and sets up the version + - RC2+: Exits successfully if release branch exists, errors if it doesn't + + Options: + --version VERSION + The release version in format x.y.z-incubating-rcN where N is the RC number + --commit GIT_COMMIT + The Git commit SHA to create the release branch from. Defaults to current HEAD. + --recreate + Drop the release branch if it already exists and recreate it to the new SHA. + -h --help + Print usage information. + + Examples: + $(basename "$0") --version 1.0.0-incubating-rc1 --commit HEAD + $(basename "$0") --version 0.1.0-incubating-rc1 --commit abc123def456 + $(basename "$0") --version 1.0.0-incubating-rc1 --commit HEAD --recreate + $(basename "$0") --version 1.0.0-incubating-rc2 # Will exit successfully if branch exists + +EOF +} + +version="" +commit="HEAD" +recreate=false + +while [[ $# -gt 0 ]]; do + case $1 in + --version) + if [[ $# -lt 2 ]]; then + print_error "Missing argument for --version" + usage >&2 + exit 1 + fi + version="$2" + shift 2 + ;; + --commit) + if [[ $# -lt 2 ]]; then + print_error "Missing argument for --commit" + usage >&2 + exit 1 + fi + commit="$2" + shift 2 + ;; + --recreate) + recreate=true + shift + ;; + --help|-h) + usage + exit 0 + ;; + *) + print_error "Unknown option/argument $1" + usage >&2 + exit 1 + ;; + esac +done + +# Ensure the version is provided +if [[ -z ${version} ]]; then + print_error "Missing version" + usage >&2 + exit 1 +fi + +# Validate that the commit exists +if ! git rev-parse --verify "${commit}" >/dev/null 2>&1; then + print_error "Invalid Git commit: ${commit}" + usage >&2 + exit 1 +fi + +# Validate version format: x.y.z-incubating-rcN +# TODO: Remove incubating when we are a TLP +if ! validate_and_extract_rc_version "${version}"; then + print_error "Invalid version format. Expected: x.y.z-incubating-rcN where N>0, got: ${version}" + usage >&2 + exit 1 +fi + +# Define polaris_version from extracted components +polaris_version="${major}.${minor}.${patch}-incubating" +release_branch="release/${polaris_version}" + +# Handle RC > 1 scenarios +if [[ ${rc_number} -gt 1 ]]; then + # Check if release branch already exists + if git show-ref --verify --quiet "refs/heads/${release_branch}"; then + print_info "RC${rc_number} detected and release branch ${release_branch} already exists." + print_info "This script only creates release branches for RC1. Nothing to do." + exit 0 + else + print_error "RC${rc_number} detected but release branch ${release_branch} does not exist." + exit 1 + fi +fi + +print_info "Starting release branch creation..." +print_info "Version: ${version}" +print_info "Polaris version: ${polaris_version}" +print_info "From commit: ${commit}" +echo + +# Check if release branch already exists +if git show-ref --verify --quiet "refs/heads/${release_branch}"; then + if [[ "${recreate}" == "true" ]]; then + print_info "Release branch ${release_branch} already exists, deleting it..." + exec_process git branch -D "${release_branch}" + if git show-ref --verify --quiet "refs/remotes/${APACHE_REMOTE_NAME}/${release_branch}"; then + print_info "Deleting remote release branch from ${APACHE_REMOTE_NAME}..." + exec_process git push "${APACHE_REMOTE_NAME}" --delete "${release_branch}" + fi + else + print_error "Release branch ${release_branch} already exists. Use --recreate to delete and recreate it." + exit 1 + fi +fi + +print_info "Checking out commit: ${commit}" +exec_process git checkout "${commit}" + +print_info "Creating release branch: ${release_branch}" +exec_process git branch "${release_branch}" + +print_info "Pushing release branch to ${APACHE_REMOTE_NAME}" +exec_process git push "${APACHE_REMOTE_NAME}" "${release_branch}" --set-upstream + +print_info "Checking out release branch" +exec_process git checkout "${release_branch}" + +print_info "Setting version to ${polaris_version} in version.txt" +update_version "${polaris_version}" + +print_info "Committing and pushing version change" +exec_process git add "$VERSION_FILE" "$HELM_CHART_YAML_FILE" "$HELM_README_FILE" "$HELM_VALUES_FILE" +exec_process git commit -m "[chore] Bump version to ${polaris_version} for release" +exec_process git push + +print_info "Updating CHANGELOG.md" +exec_process cd "${releasey_dir}/.." +exec_process ./gradlew patchChangelog Review Comment: If there are CHANGELOG.md changes on `main` while the release is in progress, then automatically handling the release sub-sections in that file will likely lead to merge conflicts. If we want to completely automate this process, I'd suggest to identify CHANGELOG entries with PR numbers and make custom tooling for generating release sub-sections. The tool can use the PR number IDs for reconciling `main` and `release` branches... not sure if there's appetite for this :sweat_smile: My original idea was to leverage the existing gradle plugin for that, but it apparently does not fit the multi-branch use case. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@polaris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org