Improving Fastlane

:  ~ 1 min read

One of the problem I had was with Fastlane's new increment_version_number and increment_build_number, is that they use Apple's agvtool to increment the required values, but I use a script that already increments the CFBundleVersion and the CFBundleShortVersionString in my plist, and there's no way to update the CURRENT_PROJECT_VERSION from the project's setting, that agvtool uses.

Now, Fastlane uses an inhouse version of shenzhen under the hood, which has a PlistBuddy module, but doesn't have a set method. Courtesy of Nassim's gist, here is the updated module, via pull request:

def set(file, key, value)
  output = `/usr/libexec/PlistBuddy -c "Set #{key} #{value}" "#{file}" 2>&1`
  output == "" ? value : nil

Now you can use it in your Fastfile:

lane :release do
  ensure_git_branch(branch: 'release')

def increment_version(type)
  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"
    split[2] = "#{split[2].to_i + 1}"

  Shenzhen::PlistBuddy.set(plist, 'CFBundleShortVersionString', split.join('.'))

I know it's not much, but I'm happy I contributed to an awesome tool.