Getting Started with Fastlane for iOS

Fastlane is a powerful suite of tools that helps unify the iOS developer’s build and deployment processes, affording greater automation through sophisticated integrations with various third-party tools. Powered by Spaceship, Fastlane consists of utility apps that make building and distributing iOS apps--internally or to the App Store--easier, in the continuous deployment (CD) model. Fastlane is something of a cult tool among iOS developers, which may explain Twitter's acquisition of Fastlane late last year.
 

logo-desktop-large.png

Fastlane’s tools can be used either in isolation, or they can form part of a collective that can be run as part of a scripted build (more on this later).

To install Fastlane, you first need to make sure you have Ruby installed on your Mac, which you can do by typing in terminal:

ruby -v

You then install the Fastlane gem:

sudo gem install fastlane --verbose

Within your iOS project, you initialize a new Fastlane project:

fastlane init

This will create all the files you need, stored within the /fastlane folder. During the process you will be asked to provide information including your app bundle id and your Apple ID used for logging into iTunes Connect. The info you provide determines the utilities you will be provided.

In all, there are 13 utilities. Here we examine them individually and in combination (into "Fastlanes"):

Deliver

The first utility is Deliver, which automates the uploading of screenshots, metadata and .ipa files to iTunes Connect--without the need for you to manually upload using Xcode or to log into Xcode and manually add screenshots.

Through simple terminal commands (or, even simpler, through lanes, which we will discuss later on), you can upload localized screenshots and new .ipa files while maintaining app metadata locally. To use Deliver, you start by installing the GEM, in terminal, as follows:

sudo gem install deliver

You then initialize deliver in your project, by calling:

deliver init

This will create subfolders in your project, for metadata and screenshots, that will automatically get synced up to iTunes Connect. To upload your project (.ipa, screenshots and metadata), simply call:

deliver

You can submit your app for review by appending the following to Deliver:

deliver --ipa "App.ipa" --submit_for_review

There are many other commands you can use with Deliver; find them by calling:

deliver --help

Snapshot

Snapshot, as its name suggests, automates the process of taking screenshots in multiple languages and devices (simulators), running completely in the backround.

Pem

Pem takes the hassle out of having to manually renew and generate push notification profiles.

You install pem by using:

sudo gem install pem

and create your pem file with simply:

pem

According to the documentation, this one command accomplishes the following steps:

  • Creates a new signing request
  • Creates a new push certification
  • Downloads the certificate
  • Generates a new .pem file in the current working directory, which you can upload to your server

Sigh

Sigh helps users deal with creating and managing the provisioning of profiles, all from the convenience of your terminal (as opposed to going through the Apple developer website). Sigh enables users to create, renew, download and repair provisioning profiles. Sigh supports App Store, Ad Hoc, Development and Enterprise profiles, and includes features such as auto-adding all test devices.

You can install Sigh in terminal, as follows:

sudo gem install sigh

and run the simplest form by calling:

sigh

By specifying your bundle identifier and user name, as follows:

sigh -a com.programmableweb.app -u doronk

You can skip any prompts and go straight to creating the right bundle identifier for the app,. By appending –adhoc you can generate an ad-hoc profile instead of app store profile, or –development to create a development profile.

Sigh includes many other advanced features, but, in short, it allows users to bypass tedious steps such as setting up various profiles. This may not seem like a hugely significant benefit, but later in this article we will examine how automation increases the return on this and other features.

Pilot

Pilot is your terminal portal to managing your TestFlight testers, as well as builds. With Pilot, users can list available Testflight builds, add/remove beta testers, get information on each tester and upload new builds to your testers.

You install Pilot as follows:

sudo gem install pilot

And upload a new build using:

pilot upload

You can list all the builds:

pilot builds

+-----------+---------+----------+----------+----------+
|                   Great App Builds                   |
+-----------+---------+----------+----------+----------+
| Version # | Build # | Testing  | Installs | Sessions |
+-----------+---------+----------+----------+----------+
| 0.9.13    | 1       | Expired  | 1        | 0        |
| 0.9.13    | 2       | Expired  | 0        | 0        |
| 0.9.20    | 3       | Expired  | 0        | 0        |
| 0.9.20    | 4       | Internal | 5        | 3        |
+-----------+---------+----------+----------+----------+

And, finally, you can add a new tester by entering the following:

pilot add email@address.com

Gym

Gym is the true workhorse utility in the suite, building, packaging and signing .ipa files.

You install the gym gem as follows:

sudo gem install gym

And run using:

gym

You will be prompted to specify the workspace and scheme during the process, or as follows:
gym --workspace "Example.xcworkspace" --scheme "AppName" --clean

Boarding

Boarding is a simple utility that auto-generates a simple signup page for TestFlight beta testers. The signup page consists of a form that is built via a Heroku Deploy script. You set it up by specifying the bundle identifier of your app and iTunes Connect credentials. You will then get an auto-gereated URL.

BoardingScreenshot.png

The magic lies in that you can pass the URL of the form to potential testers, whose information will automatically be added to the list of TestFlight beta testers This saves you from having to go through the process of entering their information on iTunes Connect.

Remaining Tools

Here is a quick take on the rest of the tools offered on the platform:

  • Scan allows you to automate running tests on iOS and Mac Apps.
  • Cert creates and maintains iOS certificates for code signing.
  • Match Syncs your certificates and profiles for the team using git.

Putting it All Together via Lanes

While each of the tools we went through is powerful on its own, the real strength comes when you create a configuration file that can go through the motions of building, testing and deploying builds automatically, with one command.

To do this, you define what Fastlane calls "Lanes." Each Lane consists of actions, in a configuration file, that sit within your /fastlane sub-folder. You can define Lanes for things like build, appstore and beta.

An example Lane would include something like:

To launch the appstore lane, just run:

lane :appstore do
  increment_build_number
  cocoapods
  scan
  snapshot
  sigh
  deliver
  sh "./customScript.sh"

  slack
end

There are dozens of other actions you can add to your Lane, as you see above. For exaple, increment_build_number increments your Xcode project’s build; , slack sends a slack notification to a channel when a lane is being processed; and cocoapods builds your cocoapods before calling deliver to push to the app store. You would then call this lane by simply adding:

fastlane appstore

Power Platform

If you take a look at some of the example configuration files from vendors including FireFox and MindNode, you can see the types of automation you can harness in your config file.

You can also create before_all and after_all lanes, which run before or after, respectively, any of your other lanes. You could use these if you wanted to build cocoapods before you do your main build lane or to send a slack notification after any of your other lanes.

before_all do |lane|
  cocoapods
end  

You can also call another lane from a lane. Other useful and powerful features and actions you can take advantage of in your lanes include:

  • git commands like checking out a branch, do a commit with a message, pull, push, tag
  • cleaning up build fartifacts
  • XcTest
  • Crashlytics and TestFlight, as well as HockeyApp integration
  • Slack notification integration

You can also run your own custom scripts if you are after something more particular.

Links

Be sure to read the next Application Development article: How to Build a Ruby CLI That Calls the Apps Script Execution API