Skip to content

Commit

Permalink
Fix hotfixing process (#2443)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaceklyp authored Feb 9, 2024
1 parent 18663c3 commit 5b7ae97
Showing 1 changed file with 26 additions and 35 deletions.
61 changes: 26 additions & 35 deletions scripts/prepare_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -eo pipefail

mute=">/dev/null 2>&1"
release_branch_parent="main"
base_branch="main"
build_number=0

# Get the directory where the script is stored
Expand Down Expand Up @@ -64,6 +64,12 @@ print_usage_and_exit() {
die "${reason}"
}

stash() {
printf '%s' "Stashing your changes ... "
eval git stash "$mute"
echo ""
}

read_command_line_arguments() {
local input="$1"
local version_regexp="^[0-9]+(\.[0-9]+)*$"
Expand Down Expand Up @@ -92,29 +98,36 @@ read_command_line_arguments() {
done
}

process_release() {
process_release() { # expected input e.g. "1.72.0"
version="$1"
release_branch="release/${version}"

echo "Processing version number: $version"

if release_branch_exists; then
is_subsequent_release=1
is_subsequent_release=1
base_branch="$release_branch"
fi
}

process_hotfix() {
local input="$1"
echo "Processing hotfix branch name: $input"

process_hotfix() { # expected input e.g. "hotfix/1.72.1"
version=$(echo "$1" | cut -d '/' -f 2)
release_branch="$1"
base_branch="$1"
is_hotfix=1
release_branch="$input"

echo "Processing hotfix branch name: $release_branch"

if ! release_branch_exists; then
die "💥 Error: Hotfix branch ${release_branch} does not exist"
die "💥 Error: Hotfix branch ${release_branch} does not exist. It should be created before you run this script."
fi
}

checkout_base_branch() {
eval git checkout "${base_branch}" "$mute"
eval git pull "$mute"
}

release_branch_exists() {
if git show-ref --verify --quiet "refs/heads/${release_branch}"; then
return 0
Expand All @@ -123,21 +136,11 @@ release_branch_exists() {
fi
}

stash() {
printf '%s' "Stashing your changes ... "
eval git stash "$mute"
echo ""
}

create_release_branch() {
printf '%s' "Creating release branch ... "
eval git checkout "${release_branch_parent}" "$mute"
eval git pull "$mute"

if [[ ! $is_subsequent_release && ! $is_hotfix ]]; then
if git show-ref --quiet "refs/heads/${release_branch}"; then
die "💥 Error: Branch ${release_branch} already exists"
fi
if git show-ref --quiet "refs/heads/${release_branch}"; then
die "💥 Error: Branch ${release_branch} already exists"
fi

eval git checkout -b "${release_branch}" "$mute"
Expand All @@ -147,17 +150,10 @@ create_release_branch() {

create_build_branch() {
printf '%s' "Creating build branch ... "
eval git checkout "${release_branch}" "$mute"
eval git pull "$mute"

local temp_file
local latest_build_number

if [[ $is_hotfix ]]; then
version=$(cut -d' ' -f3 < "${base_dir}/Configuration/Version.xcconfig")
version=$(bump_patch_number "$version")
fi

temp_file=$(mktemp)
bundle exec fastlane latest_build_number_for_version version:"$version" file_name:"$temp_file"
latest_build_number="$(<"$temp_file")"
Expand All @@ -183,12 +179,6 @@ update_marketing_version() {
echo ""
}

bump_patch_number() {
IFS='.' read -ra arrIN <<< "$1"
local patch_number=$((arrIN[2] + 1))
echo "${arrIN[0]}.${arrIN[1]}.$patch_number"
}

update_build_version() {
echo "Setting build version ..."
(cd "$base_dir" && bundle exec fastlane increment_build_number_for_version version:"${version}")
Expand Down Expand Up @@ -243,8 +233,9 @@ main() {
assert_fastlane_installed
assert_gh_installed_and_authenticated

read_command_line_arguments "$@"
stash
read_command_line_arguments "$@"
checkout_base_branch

if [[ $is_subsequent_release ]]; then
create_build_branch
Expand Down

0 comments on commit 5b7ae97

Please sign in to comment.