From 2972beb534ee513aee3aba99aca1234f9f03a3ad Mon Sep 17 00:00:00 2001 From: Ian Maia Date: Mon, 17 Nov 2025 18:01:53 -0300 Subject: [PATCH 1/7] Improve hotfix lane to work when there's no release tag --- fastlane/lanes/release.rb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/fastlane/lanes/release.rb b/fastlane/lanes/release.rb index 9d234d8032ce..b27bffa15389 100644 --- a/fastlane/lanes/release.rb +++ b/fastlane/lanes/release.rb @@ -213,6 +213,16 @@ # Parse the provided version into an AppVersion object parsed_version = VERSION_FORMATTER.parse(new_version) previous_version = VERSION_FORMATTER.release_version(VERSION_CALCULATOR.previous_patch_version(version: parsed_version)) + previous_release_branch = "release/#{previous_version}" + + # Determine the base for the hotfix branch: either a tag or a release branch + base_ref_for_hotfix = if git_tag_exists(tag: previous_version) + previous_version + elsif Fastlane::Helper::GitHelper.branch_exists_on_remote?(branch_name: previous_release_branch) + previous_release_branch + else + UI.user_error!("Neither tag #{previous_version} nor branch #{previous_release_branch} exists! A hotfix branch cannot be created.") + end # Check versions message = <<-MESSAGE @@ -223,7 +233,7 @@ Current build code: #{current_build_code} New build code: #{new_build_code} - Branching from tag: #{previous_version} + Branching from #{base_ref_for_hotfix} MESSAGE @@ -233,11 +243,10 @@ # Check tags UI.user_error!("The version `#{new_version}` tag already exists!") if git_tag_exists(tag: new_version) - UI.user_error!("Version #{previous_version} is not tagged! A hotfix branch cannot be created.") unless git_tag_exists(tag: previous_version) # Create the hotfix branch - UI.message 'Creating hotfix branch...' - Fastlane::Helper::GitHelper.create_branch("release/#{new_version}", from: previous_version) + UI.message "Creating hotfix branch from #{base_ref_for_hotfix}..." + Fastlane::Helper::GitHelper.create_branch("release/#{new_version}", from: base_ref_for_hotfix) UI.success "Done! New hotfix branch is: #{git_branch}" # Bump the hotfix version and build code and write it to the `version.properties` file From 6335653db8f135b8f0f4688247fd1303720a2a1f Mon Sep 17 00:00:00 2001 From: Ian Maia Date: Mon, 17 Nov 2025 19:53:28 -0300 Subject: [PATCH 2/7] Add log when there's no release tag --- fastlane/lanes/release.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/fastlane/lanes/release.rb b/fastlane/lanes/release.rb index b27bffa15389..e2cc81a989f3 100644 --- a/fastlane/lanes/release.rb +++ b/fastlane/lanes/release.rb @@ -219,6 +219,7 @@ base_ref_for_hotfix = if git_tag_exists(tag: previous_version) previous_version elsif Fastlane::Helper::GitHelper.branch_exists_on_remote?(branch_name: previous_release_branch) + UI.message("ℹ️ Tag #{previous_version} not found. Using release branch #{previous_release_branch} as the base for hotfix instead.") previous_release_branch else UI.user_error!("Neither tag #{previous_version} nor branch #{previous_release_branch} exists! A hotfix branch cannot be created.") From de07709db2e1fe2d941075911f34bef17b8a247b Mon Sep 17 00:00:00 2001 From: Ian Maia Date: Tue, 18 Nov 2025 15:42:13 -0300 Subject: [PATCH 3/7] Improve code consistency --- fastlane/lanes/release.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fastlane/lanes/release.rb b/fastlane/lanes/release.rb index e2cc81a989f3..419f67fb987c 100644 --- a/fastlane/lanes/release.rb +++ b/fastlane/lanes/release.rb @@ -219,10 +219,10 @@ base_ref_for_hotfix = if git_tag_exists(tag: previous_version) previous_version elsif Fastlane::Helper::GitHelper.branch_exists_on_remote?(branch_name: previous_release_branch) - UI.message("ℹ️ Tag #{previous_version} not found. Using release branch #{previous_release_branch} as the base for hotfix instead.") + UI.message("ℹ️ Tag '#{previous_version}' not found on the remote. Using release branch '#{previous_release_branch}' as the base for hotfix instead.") previous_release_branch else - UI.user_error!("Neither tag #{previous_version} nor branch #{previous_release_branch} exists! A hotfix branch cannot be created.") + UI.user_error!("Neither tag '#{previous_version}' nor branch '#{previous_release_branch}' exists on the remote! A hotfix branch cannot be created.") end # Check versions @@ -246,18 +246,18 @@ UI.user_error!("The version `#{new_version}` tag already exists!") if git_tag_exists(tag: new_version) # Create the hotfix branch - UI.message "Creating hotfix branch from #{base_ref_for_hotfix}..." + UI.message("Creating hotfix branch from '#{base_ref_for_hotfix}'...") Fastlane::Helper::GitHelper.create_branch("release/#{new_version}", from: base_ref_for_hotfix) - UI.success "Done! New hotfix branch is: #{git_branch}" + UI.success("Done! New hotfix branch is: '#{git_branch}'") # Bump the hotfix version and build code and write it to the `version.properties` file - UI.message 'Bumping hotfix version and build code...' + UI.message('Bumping hotfix version and build code...') VERSION_FILE.write_version( version_name: new_version, version_code: new_build_code ) commit_version_bump - UI.success "Done! New Release Version: #{current_release_version}. New Build Code: #{current_build_code}" + UI.success("Done! New Release Version: '#{current_release_version}'. New Build Code: '#{current_build_code}'") push_to_git_remote(tags: false) end From 974a6e83dc9b320c9cc34b8f00fcd10e7a4a4e8c Mon Sep 17 00:00:00 2001 From: Ian Maia Date: Tue, 18 Nov 2025 16:03:12 -0300 Subject: [PATCH 4/7] Check Git tags on remote --- fastlane/lanes/release.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fastlane/lanes/release.rb b/fastlane/lanes/release.rb index 419f67fb987c..cca60c98fc89 100644 --- a/fastlane/lanes/release.rb +++ b/fastlane/lanes/release.rb @@ -216,7 +216,7 @@ previous_release_branch = "release/#{previous_version}" # Determine the base for the hotfix branch: either a tag or a release branch - base_ref_for_hotfix = if git_tag_exists(tag: previous_version) + base_ref_for_hotfix = if git_tag_exists(tag: previous_version, remote: true) previous_version elsif Fastlane::Helper::GitHelper.branch_exists_on_remote?(branch_name: previous_release_branch) UI.message("ℹ️ Tag '#{previous_version}' not found on the remote. Using release branch '#{previous_release_branch}' as the base for hotfix instead.") @@ -243,7 +243,7 @@ UI.user_error!('Aborted by user request') unless skip_confirm || UI.confirm('Do you want to continue?') # Check tags - UI.user_error!("The version `#{new_version}` tag already exists!") if git_tag_exists(tag: new_version) + UI.user_error!("Version '#{new_version}' already exists on the remote! Abort!") if git_tag_exists(tag: new_version, remote: true) # Create the hotfix branch UI.message("Creating hotfix branch from '#{base_ref_for_hotfix}'...") From 4a779c185e08d6ff7fe5c79705e48dd8645b3ec8 Mon Sep 17 00:00:00 2001 From: Ian Maia Date: Tue, 18 Nov 2025 16:10:05 -0300 Subject: [PATCH 5/7] Add hotfix version validation --- fastlane/lanes/release.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fastlane/lanes/release.rb b/fastlane/lanes/release.rb index cca60c98fc89..10ea05949f28 100644 --- a/fastlane/lanes/release.rb +++ b/fastlane/lanes/release.rb @@ -212,6 +212,8 @@ # Parse the provided version into an AppVersion object parsed_version = VERSION_FORMATTER.parse(new_version) + # Validate that this is a hotfix version (must have a patch component > 0) + UI.user_error!("Invalid hotfix version '#{new_version}'. Must include a patch number.") unless parsed_version.patch.to_i.positive? previous_version = VERSION_FORMATTER.release_version(VERSION_CALCULATOR.previous_patch_version(version: parsed_version)) previous_release_branch = "release/#{previous_version}" From f191830dc636d5368cbf93e952fddaed1bf60f92 Mon Sep 17 00:00:00 2001 From: Ian Maia Date: Wed, 19 Nov 2025 18:19:22 -0300 Subject: [PATCH 6/7] Update to fetch base ref to ensure it's available locally --- fastlane/lanes/release.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fastlane/lanes/release.rb b/fastlane/lanes/release.rb index 10ea05949f28..a08b693019e6 100644 --- a/fastlane/lanes/release.rb +++ b/fastlane/lanes/release.rb @@ -247,6 +247,9 @@ # Check tags UI.user_error!("Version '#{new_version}' already exists on the remote! Abort!") if git_tag_exists(tag: new_version, remote: true) + # Fetch the base ref to ensure it's available locally + sh('git', 'fetch', 'origin', base_ref_for_hotfix) + # Create the hotfix branch UI.message("Creating hotfix branch from '#{base_ref_for_hotfix}'...") Fastlane::Helper::GitHelper.create_branch("release/#{new_version}", from: base_ref_for_hotfix) From 1f791717f8ec97083139bef981acb4933d1ebbf7 Mon Sep 17 00:00:00 2001 From: Ian Maia Date: Fri, 21 Nov 2025 18:01:36 -0300 Subject: [PATCH 7/7] Update code to ensure the new hotfix branch doesn't exist --- fastlane/lanes/release.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fastlane/lanes/release.rb b/fastlane/lanes/release.rb index a08b693019e6..0864e0778bfb 100644 --- a/fastlane/lanes/release.rb +++ b/fastlane/lanes/release.rb @@ -250,9 +250,12 @@ # Fetch the base ref to ensure it's available locally sh('git', 'fetch', 'origin', base_ref_for_hotfix) + hotfix_branch = "release/#{new_version}" + ensure_branch_does_not_exist!(hotfix_branch) + # Create the hotfix branch UI.message("Creating hotfix branch from '#{base_ref_for_hotfix}'...") - Fastlane::Helper::GitHelper.create_branch("release/#{new_version}", from: base_ref_for_hotfix) + Fastlane::Helper::GitHelper.create_branch(hotfix_branch, from: base_ref_for_hotfix) UI.success("Done! New hotfix branch is: '#{git_branch}'") # Bump the hotfix version and build code and write it to the `version.properties` file