Last time I stopped at build incrementation. Let's continue with better lanes:
# From
lane :release do
build_app 'Release'
end
# To
lane :release_patch do # | :release_minor | :release_patch | :release_quick_fix
release :major # | :minor | :patch | :quick_fix
end
# While the Hockey lanes changed to
lane :hockey_debug do
lane :hockey_beta do
build_app 'Debug' # | 'Beta'
end
Where the release(version)
and the submit(binary_flag)
methods looks like this:
def release(version)
# If we are submitting a quick fix, we don't really care what branch we are on
# as long as it contains the quick-fix text, to be sure we are where we want to be
if version == :release_quick_fix
# If current_branch doesn't include 'quick-fix', ensure to something that will surely fail
ensure_git_branch branch: 'quick-fix' unless @current_branch.include? 'quick-fix'
else
# This is a fastlane helper that checks if we are on the required branch
ensure_git_branch branch: 'development'
end
# This will increment the version, based on the kind of release
increment_version version
build_app 'Release'
submit :with_binary
end
def submit(binary_flag)
deliver(
skip_deploy: binary_flag == :without_binary,
metadata_only: binary_flag == :without_binary
)
end
As you can see, all the logic was mitigated into 3, more concise, methods, build_app
, submit
and release
. Now for the increment_version
method:
def increment_version(type)
# In case the lane fails, we revert the version number
@previous_version = version_number
split = version_number.split '.'
if type == :major
split[0] = "#{split[0].to_i + 1}"
split[1] = '0'
split[2] = '0'
elsif type == :minor
split[1] = "#{split[1].to_i + 1}"
split[2] = '0'
else # For patch and quick_fix
split[2] = "#{split[2].to_i + 1}"
end
new_version_number = split.join '.'
# Using this in the Deliverfile
ENV['VERSION_NUMBER'] = new_version_number
Shenzhen::PlistBuddy.set plist, 'CFBundleShortVersionString', new_version_number
end
def build_number
"#{Shenzhen::PlistBuddy.print(plist, 'CFBundleVersion')}"
end
Next time I will talk about tagging, committing, pull requesting or pushing and sending a message to Slack.