From cc0caf50572dc7749408418f2ecc83edf2ae5ef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacek=20=C5=81yp?= Date: Fri, 25 Oct 2024 19:09:45 +0200 Subject: [PATCH] Make running the script more explicit (#3484) Task/Issue URL: https://app.asana.com/0/1203301625297703/1207921724970682/f **Description**: Make running the script more explicit, by providing additional argument if it is subsequent release. It will then fail on initial release if the release branch exists and fail on subsequent release if release branch does not. --- scripts/prepare_release.sh | 43 +++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/scripts/prepare_release.sh b/scripts/prepare_release.sh index dca7095571..06aef4d0a8 100755 --- a/scripts/prepare_release.sh +++ b/scripts/prepare_release.sh @@ -3,6 +3,7 @@ set -eo pipefail mute=">/dev/null 2>&1" +is_subsequent_release=0 base_branch="main" build_number=0 @@ -78,24 +79,28 @@ read_command_line_arguments() { print_usage_and_exit "💥 Error: Missing argument" fi + shift 1 + + while [[ "$#" -gt 0 ]]; do + case "$1" in + -v) + mute= + ;; + -s|--subsequent) + is_subsequent_release=1 + ;; + *) + print_usage_and_exit "💥 Error: Unknown option '$1'" + ;; + esac + shift + done + if [[ $input =~ $version_regexp ]]; then process_release "$input" else process_hotfix "$input" fi - - shift 1 - - while getopts 'v' option; do - case "${option}" in - v) - mute= - ;; - *) - print_usage_and_exit "💥 Error: Unknown option '${option}'" - ;; - esac - done } process_release() { # expected input e.g. "1.72.0" @@ -104,9 +109,17 @@ process_release() { # expected input e.g. "1.72.0" echo "Processing version number: $version" - if release_branch_exists; then - is_subsequent_release=1 + if [[ "$is_subsequent_release" -eq 1 ]]; then + # check if the release branch exists (it must exist for a subsequent release) + if ! release_branch_exists; then + die "💥 Error: Release branch does not exist for a subsequent release!" + fi base_branch="$release_branch" + else + # check if the release branch does NOT exist (it must NOT exist for an initial release) + if release_branch_exists; then + die "💥 Error: Release branch already exists for an initial release!" + fi fi }