Skip to content

Commit bf9fbe2

Browse files
committed
Improve hotfix lane to work when there's no release tag
1 parent 2c6489e commit bf9fbe2

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

fastlane/Fastfile

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,18 @@ platform :android do
8282
previous_version = VERSION_FORMATTER.release_version(
8383
VERSION_CALCULATOR.previous_patch_version(version: VERSION_FORMATTER.parse(new_version))
8484
)
85+
previous_release_branch = release_branch_name(release_version: previous_version)
8586

8687
UI.user_error!("The version `#{new_version}` tag already exists!") if git_tag_exists(tag: new_version)
87-
UI.user_error!("Version #{previous_version} is not tagged! A hotfix branch cannot be created.") unless git_tag_exists(tag: previous_version)
88+
89+
# 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)
91+
previous_version
92+
elsif Fastlane::Helper::GitHelper.branch_exists_on_remote?(branch_name: previous_release_branch)
93+
previous_release_branch
94+
else
95+
UI.user_error!("Neither tag #{previous_version} nor branch #{previous_release_branch} exists! A hotfix branch cannot be created.")
96+
end
8897

8998
message = <<~MESSAGE
9099
Hotfix release:
@@ -94,14 +103,14 @@ platform :android do
94103
- Current build code: #{build_code_current}
95104
- New build code: #{version_code_new}
96105
97-
Branching from tag: #{previous_version}
106+
Branching from #{base_ref_for_hotfix}
98107
MESSAGE
99108
UI.important(message)
100109

101110
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?')
102111

103-
UI.message('Creating hotfix branch...')
104-
Fastlane::Helper::GitHelper.create_branch(release_branch_name(release_version: new_version), from: previous_version)
112+
UI.message("Creating hotfix branch from #{base_ref_for_hotfix}...")
113+
Fastlane::Helper::GitHelper.create_branch(release_branch_name(release_version: new_version), from: base_ref_for_hotfix)
105114
UI.success("Done! New hotfix branch is: #{git_branch}")
106115

107116
UI.message('Bumping hotfix version and build code...')

0 commit comments

Comments
 (0)