Skip to content

Commit 33b9303

Browse files
committed
Add hotfix version validation and check tags on remote
1 parent 1c32246 commit 33b9303

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

fastlane/Fastfile

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,24 @@ platform :android do
7979
new_version = version_name
8080
version_code_new = version_code
8181

82+
# Validate that this is a hotfix version (must have a patch component > 0)
83+
parsed_version = VERSION_FORMATTER.parse(new_version)
84+
UI.user_error!("Invalid hotfix version '#{new_version}'. Must include a patch number.") unless parsed_version.patch.to_i.positive?
8285
previous_version = VERSION_FORMATTER.release_version(
83-
VERSION_CALCULATOR.previous_patch_version(version: VERSION_FORMATTER.parse(new_version))
86+
VERSION_CALCULATOR.previous_patch_version(version: parsed_version)
8487
)
8588
previous_release_branch = release_branch_name(release_version: previous_version)
8689

87-
UI.user_error!("The version `#{new_version}` tag already exists!") if git_tag_exists(tag: new_version)
90+
UI.user_error!("Version '#{new_version}' already exists on the remote! Abort!") if git_tag_exists(tag: new_version, remote: true)
8891

8992
# Determine the base for the hotfix branch: either a tag or a release branch
90-
base_ref_for_hotfix = if git_tag_exists(tag: previous_version)
93+
base_ref_for_hotfix = if git_tag_exists(tag: previous_version, remote: true)
9194
previous_version
9295
elsif Fastlane::Helper::GitHelper.branch_exists_on_remote?(branch_name: previous_release_branch)
93-
UI.message("ℹ️ Tag #{previous_version} not found. Using release branch #{previous_release_branch} as the base for hotfix instead.")
96+
UI.message("ℹ️ Tag '#{previous_version}' not found on the remote. Using release branch '#{previous_release_branch}' as the base for hotfix instead.")
9497
previous_release_branch
9598
else
96-
UI.user_error!("Neither tag #{previous_version} nor branch #{previous_release_branch} exists! A hotfix branch cannot be created.")
99+
UI.user_error!("Neither tag '#{previous_version}' nor branch '#{previous_release_branch}' exists on the remote! A hotfix branch cannot be created.")
97100
end
98101

99102
message = <<~MESSAGE
@@ -110,9 +113,9 @@ platform :android do
110113

111114
UI.user_error!("Terminating as requested. Don't forget to run the remainder of this automation manually.") unless skip_confirm || UI.confirm('Do you want to continue?')
112115

113-
UI.message("Creating hotfix branch from #{base_ref_for_hotfix}...")
116+
UI.message("Creating hotfix branch from '#{base_ref_for_hotfix}'...")
114117
Fastlane::Helper::GitHelper.create_branch(release_branch_name(release_version: new_version), from: base_ref_for_hotfix)
115-
UI.success("Done! New hotfix branch is: #{git_branch}")
118+
UI.success("Done! New hotfix branch is: '#{git_branch}'")
116119

117120
UI.message('Bumping hotfix version and build code...')
118121
VERSION_FILE.write_version(
@@ -121,7 +124,7 @@ platform :android do
121124
)
122125
commit_version_bump
123126
# Print computed version and build to let user double-check outcome in logs
124-
UI.success("Done! New release version: #{release_version_current}. New build code: #{build_code_current}.")
127+
UI.success("Done! New release version: '#{release_version_current}'. New build code: '#{build_code_current}'.")
125128

126129
UI.important('Pushing new hotfix branch to remote...')
127130
push_to_git_remote(tags: false)

0 commit comments

Comments
 (0)