Skip to content

Commit 8a4865e

Browse files
committed
Update code to properly use the received version as source of truth throughout code freeze
1 parent 7b97d04 commit 8a4865e

File tree

1 file changed

+17
-29
lines changed

1 file changed

+17
-29
lines changed

fastlane/Fastfile

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -197,35 +197,23 @@ platform :ios do
197197
# Check out the up-to-date default branch, the designated starting point for the code freeze
198198
Fastlane::Helper::GitHelper.checkout_and_pull(DEFAULT_BRANCH)
199199

200-
# Use provided version from release tool, or fall back to computed version
201-
computed_version = release_version_next
202-
new_version = version || computed_version
203-
204-
# Fail if provided version differs from computed version
205-
if version && version != computed_version
206-
error_message = <<~ERROR
207-
❌ Version mismatch detected!
208-
209-
The explicitly-provided version from the release tool is '#{version}' but the computed version from the codebase is '#{computed_version}'.
210-
211-
This mismatch must be resolved before proceeding with the code freeze. Please investigate and ensure the versions are aligned.
212-
ERROR
213-
buildkite_annotate(style: 'error', context: 'start-code-freeze-version-mismatch', message: error_message) if is_ci
214-
UI.user_error!(error_message)
215-
end
200+
# If a new version is passed, use it as source of truth from now on
201+
new_version = version || release_version_next
202+
new_release_branch = "release/#{new_version}"
203+
new_build_code = build_code_code_freeze(version_short: new_version)
216204

217205
UI.important <<-MESSAGE
218206
219207
Code Freeze:
220-
• New release branch from #{DEFAULT_BRANCH}: release/#{new_version}
208+
• New release branch from #{DEFAULT_BRANCH}: #{new_release_branch}
209+
221210
• Current release version and build code: #{release_version_current} (#{build_code_current}).
222-
• New release version and build code: #{new_version} (#{build_code_code_freeze}).
211+
• New release version and build code: #{new_version} (#{new_build_code}).
223212
224213
MESSAGE
225214
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?')
226215

227216
# Create the release branch
228-
new_release_branch = "release/#{new_version}"
229217
ensure_branch_does_not_exist!(new_release_branch)
230218

231219
UI.message('Creating release branch...')
@@ -235,8 +223,8 @@ platform :ios do
235223
# Bump the release version and build code and write it to the `xcconfig` file
236224
UI.message('Bumping release version and build code...')
237225
VERSION_FILE.write(
238-
version_short: release_version_next,
239-
version_long: build_code_code_freeze
226+
version_short: new_version,
227+
version_long: new_build_code
240228
)
241229
commit_version_bump
242230
UI.success("Done! New Release Version: #{release_version_current}. New Build Code: #{build_code_current}")
@@ -260,7 +248,7 @@ platform :ios do
260248
copy_branch_protection(
261249
repository: GITHUB_REPO,
262250
from_branch: DEFAULT_BRANCH,
263-
to_branch: "release/#{new_version}"
251+
to_branch: new_release_branch
264252
)
265253

266254
begin
@@ -1421,9 +1409,10 @@ end
14211409

14221410
# Returns the next release version of the app in the format `1.2` or `1.2.3` if it is a hotfix
14231411
#
1424-
def release_version_next
1412+
def release_version_next(version_short: nil)
1413+
version_short ||= VERSION_FILE.read_release_version
14251414
# Read the current release version from the .xcconfig file and parse it into an AppVersion object
1426-
current_version = VERSION_FORMATTER.parse(VERSION_FILE.read_release_version)
1415+
current_version = VERSION_FORMATTER.parse(version_short)
14271416
# Calculate the next release version
14281417
next_calculated_release_version = VERSION_CALCULATOR.next_release_version(version: current_version)
14291418
# Return the formatted release version
@@ -1443,15 +1432,14 @@ end
14431432

14441433
# Returns the build code of the app for the code freeze. It is the release version name plus sets the build number to 0
14451434
#
1446-
def build_code_code_freeze
1435+
def build_code_code_freeze(version_short: nil)
1436+
version_short ||= VERSION_FILE.read_release_version
14471437
# Read the current build code from the .xcconfig file and parse it into an AppVersion object
14481438
# The AppVersion is used because WCiOS uses the four part (1.2.3.4) build code format, so the version
14491439
# calculator can be used to calculate the next four-part version
1450-
release_version_current = VERSION_FORMATTER.parse(VERSION_FILE.read_release_version)
1451-
# Calculate the next release version, which will be used as the basis of the new build code
1452-
build_code_code_freeze = VERSION_CALCULATOR.next_release_version(version: release_version_current)
1440+
release_version_current = VERSION_FORMATTER.parse(version_short)
14531441
# Return the formatted build code
1454-
BUILD_CODE_FORMATTER.build_code(version: build_code_code_freeze)
1442+
BUILD_CODE_FORMATTER.build_code(version: release_version_current)
14551443
end
14561444

14571445
# Returns the next build code of the app

0 commit comments

Comments
 (0)