Home Automating Build/Version Number Bumps for a Specific iOS Target using Fastlane
Post
Cancel

Automating Build/Version Number Bumps for a Specific iOS Target using Fastlane

Prerequisite

This article assumes you are familiar with fastlane and modern mobile CD (continuous delivery) practices. Fastlane is a powerful automation tool for mobile app development that allows you to streamline and automate many tasks, such as building and testing your app, as well as deploying it to various app stores. Modern mobile CD practices help you to continuously deliver updates and new features to your users, ensuring that your app stays relevant and up-to-date. If you are new to fastlane and mobile CD, i recommend taking some time to familiarize yourself with these concepts before diving into the specifics of automating build/version number bumps for a specific iOS target.

Intro

If you don’t know what Fastlane is; fastlane is an open-source suite of tools that allows you to automate your iOS or Android mobile app releases, potentially saving you hours of development time. It is powered by a Ruby configuration file called a Fastfile, in which you can add lanes to serve different purposes and handle common tasks in your release process.

The Need for Automation 🤖

A common task in an iOS deployment process is to bump up a build or version number before deploying a build to AppStore for prod or TestFlight for qa. You can of course do this manually via Xcode general settings GUI but why go through that headache for every deployment when you can automate it, amirite?😅

Well if you’re familiar with Fastlane, chances are you’ve either tried the increment_version_number action or its twin the increment_build_number action. Both are pretty explicit in what they automate for you. Both action uses apple’s agvtool under the hood to help accomplish their task, this is important as you will see in a moment.

Now everything is dandy if you are simply automating a project with a single target. However if you’ve a multi target Xcode project, these two default Fastlane actions won’t cut it for you. Unfortunately, deploying either actions to automate the build or version numbers just ends up increasing the numbers across all of the targets in a project. And since both actions are just a wrapper for agvtool, we have a problem. This is made clear by this statement in agvtool documentation:

Important: When your app includes multiple targets, agvtool will set the version numbers of all your targets to the same number.

So the golden question then is, Is there a way to use increment_version_number and increment_build_number for automating a specific target’s build or version number in a multi target project? The answer is yes but you’ll have to look for another tool that extends their functions and doesn’t use apple’s agvtool approach.

Plugins To The Rescue 🛟

One of the ways in which Fastlane manages dependencies is through the use of plugins. Fastlane plugins are Ruby Gems that provide additional functionality to Fastlane. Plugins can be used to extend Fastlane’s capabilities, and they can be installed using the fastlane add_plugin command. When you add a plugin to your Fastlane configuration, Fastlane will automatically install any necessary dependencies for that plugin.

Fastlane Versioning Plugin

The Versioning plugin is an extension of fastlane actions that we can use to get or set versions without using the agvtool. The cool thing is that this plugin provides us with cool actions that comes with a “target” and “scheme” parameters therefore we can automate our version bumps for the specific target that we want.

Installation

Run the fastlane add_plugin versioning command in your project’s root dir, for react native project if you’ve different fastfiles for ios and android, you should cd to your ios directory and run the command.

Usage

Let’s say we have a multi target project, target A is called Uber, and target B is Lyft, we want to increment Uber’s build number without overriding Lyft’s, we can use Versioning’s increment_build_number_in_plist action like below to accomplish this:

1
2
3
4
5
6
7
8
desc "Increment Uber's Build Number"
lane :bump_uber_build_number do 
   increment_build_number_in_plist(
    build_number: "2", ## 1
    target: "Uber", ## 2
    plist_build_setting_support: true ## 3
   )
end

Run the above with:

1
fastlane bump_uber_build_number

What’s Going

  1. Your value goes here, remember the build_number parameter has to be a string
  2. This is the special sauce to only modify your specific target’s build number
  3. Keep this if you want fastlane to sync the build increment both in Xcode’s general settings tab and in your target’s info.plist file

For Versioning documentation, if you’ve already installed the plugin, you can just run fastlane action ENTER_ACTION_NAME to get a list of available params for an action and what their value / purpose is. Example: fastlane action increment_build_number_in_plist will list all of increment_build_number_in_plist’s documentation.

And with the custom lane bump_uber_build_number we have now automated Uber’s build number bump. Pretty neat right?

Versioning helps with automating version number bumps as well as obtaining build or version numbers. To learn more about the available options that may suit your needs, check out their GitHub repository.

c’est fini 👋

Hope you found this helpful, till next time adios ✌️

IMOOAU ❤️

This post is licensed under CC BY 4.0 by the author.