Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions fastlane/lanes/release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,20 @@

# 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?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick, and sort of out of scope because it would have required changing more of the existing code that this PR originally touched, but I noticed that other projects use hotfix_version as the name for this var, which to me sounds better in the context of this hotfix lane.

No big deal, it's just that the PR I looked before this used hotfix_version so this jumped to my attention, I think.

Copy link
Contributor Author

@iangmaia iangmaia Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think hotfix_version was an exception though, only DOApple (or maybe other one or two) used it, but admittedly I also like it 🙂 I'll update it in the PRs that are still open.

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, 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.")
previous_release_branch
else
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
message = <<-MESSAGE
Expand All @@ -223,7 +236,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

Expand All @@ -232,22 +245,27 @@
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 #{previous_version} is not tagged! A hotfix branch cannot be created.") unless git_tag_exists(tag: previous_version)
UI.user_error!("Version '#{new_version}' already exists on the remote! Abort!") if git_tag_exists(tag: new_version, remote: true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to test this earlier in the lane (e.g. line 216)?


# 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...'
Fastlane::Helper::GitHelper.create_branch("release/#{new_version}", from: previous_version)
UI.success "Done! New hotfix branch is: #{git_branch}"
UI.message("Creating hotfix branch 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
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
Expand Down