-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[Tooling] Improve new_hotfix_release lane to work when there's no release tag
#22355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
iangmaia
wants to merge
7
commits into
trunk
Choose a base branch
from
iangmaia/improve-hotfix-handling
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+26
−8
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2972beb
Improve hotfix lane to work when there's no release tag
iangmaia 6335653
Add log when there's no release tag
iangmaia de07709
Improve code consistency
iangmaia 974a6e8
Check Git tags on remote
iangmaia 4a779c1
Add hotfix version validation
iangmaia f191830
Update to fetch base ref to ensure it's available locally
iangmaia 1f79171
Update code to ensure the new hotfix branch doesn't exist
iangmaia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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? | ||
| 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 | ||
|
|
@@ -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 | ||
|
|
||
|
|
@@ -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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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_versionas 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_versionso this jumped to my attention, I think.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
hotfix_versionwas 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.