---
title: "Improving Fastlane"
slug: improving-fastlane
section: tech
date: 2015-07-11T12:10:00.000Z
canonical: https://roland.leth.ro/blog/tech/improving-fastlane
---

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](https://developer.apple.com/library/ios/qa/qa1827/_index.html) to increment the required values, but I use a [script](/tech/blog/fastlane-fastfile) 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](https://github.com/nomad/shenzhen) under the hood, which has a `PlistBuddy` module, but doesn't have a `set` method. Courtesy of [Nassim's gist](https://gist.github.com/nkammah/7d1de3e132d7061352a7), here is the updated module, via pull request:

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

Now you can use it in your `Fastfile`:

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

  increment_version(:minor)
  [...]
end

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"
  else
    split[2] = "#{split[2].to_i + 1}"
  end

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

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