Simplify you life with fastlane

What is fastlane?

Fastlane is a free set of tools created by Felix Krause that automate building and releasing your iOS apps.

  1. Automatically synchronize certificates accross your team: you’re starting a job in a new company and you need an Apple Certificate to compile the app on your phone, but first someone has to give you the p12 file to install it (if he’s not on holidays)… Forget about that, thanks to the match tool, all Certificates and Provisioning Profiles will be stored in a private Git repository, and if you don’t have the correct Certificate, it will generate it for you automatically.
  2. Automatically choose which Provisioning Profile to use: depending on the type of app you want to compile (Development, Ad Hoc, In House or App Store), the match tool will automatically fetch the correct Provisioning Profile, or create or update it if needed. Dead simple! I’ve simply forgot what it’s like to deal with that manually.
  3. Automatically run the tests, compile your app and send it to TestFlight: thanks to the scan, gym and pilot tools, fastlane will run the tests, compile your app and upload it to TestFlight or any other service provider supported (e.g. Crahlytics) with one single command line.

Requirements

Apple has recently changed their servers to require TLS 1.2, which may not be available to your system installed Ruby (2.0.0). So before installing fastlane, start by installing OpenSSL and upgrading your Ruby version to 2.3.1 with Homebrew, which will allow communication with iTunes Connect and the Apple Developer Portal servers.

Configuration

You can finally install fastlane:

  • Create a fastlane folder,
  • Create fastlane/Appfile, which stores your Apple ID and Bundle Identifier,
  • Create fastlane/Fastfile, which stores your lanes.

Appfile

The Appfile is used to define a Bundle Identifier. By default there is only one bundle identifer, but you can create one for each lane. You could also specify the app identifier directly in the Fastline file, but it’s more convenient to externalize it in the Appfile.

apple_id "<APPLE_ID>" # Your Apple email address
team_id "<TEAM_ID>" # Developer Portal Team ID
for_platform :ios do
for_lane :test do
app_identifier "com.nicolasbichon.exampleapp.test"
end
for_lane :beta do
app_identifier "com.nicolasbichon.exampleapp.beta"
end
for_lane :appstore do
app_identifier "com.nicolasbichon.exampleapp"
end
end

Fastfile

The Fastfile is the main file used by fastlane, this is where you will configure your lanes with actions.

default_platform :iosplatform :ios do
lane :test do
# Actions
end
lane :beta do
# Actions
end
lane :appstore do
# Actions
end
end

Lanes

A lane is a collection of actions. In the example above we have 3 lanes:

  • test: run all the tests,
  • beta: compile an app and send it to TestFlight,
  • appstore: submit an app to the App Store.

Actions

Fastlane provides a lot of actions, you can see the full list here, or by taping the following command-line:

Setting up a lane

Most of the time, I use fastlane to send a beta build to TestFlight, here is how I configure my lane:

lane :beta do
# Update Cocoapods
cocoapods
# Stop if not on 'develop' branch
ensure_git_branch(branch: "develop")
# Fetch Provisioning Profile
match(
git_url: "https://github.com/TakeEatEasy/ios-codesigning",
type: "appstore"
)
# Run tests on latest iOS version
scan(scheme: "ExampleApp", clean: true)
# Increment build number
increment_build_number({
build_number: latest_testflight_build_number + 1
})
# Compile IPA
gym(scheme: "ExampleApp", configuration: "Beta", clean: true)
# Send IPA to TestFlight
pilot(skip_waiting_for_build_processing: true)
# Deletes files created during the process (e.g. IPA file)
clean_build_artifacts
end

match

Match allow you to easily sync your certificates and profiles across your team using Git. The first time you’ll use it, you will be asked for:

  • your private Git repository where the Certificates and Provisioning Profiles will be stored,
  • the passphrase used to encrypt/decrypt all files on the Git repository.

scan

Scan makes it easy to run tests of your iOS and Mac app on a simulator or connected device.

gym

Gym allows you to build your app.

pilot

Pilot makes it easier to manage your app on Apple’s TestFlight, by uploading builds.

Configure Xcode to use fastlane

Since Xcode 8, Apple can automatically manage code signings, I do not use that feature since the match action does it for us, and even stores them in a private repository.

  • Disable the “Automatically manage signing” option,
  • Manually assign the correct Provisioning Profile for each configuration.

Configure fastlane on a new computer

This is where fastlane brings some magic, to configure fastlane on a new computer, you just have to run one lane:

Conclusion

I’ve been using fastlane for a few months now, and I couldn’t go back. Even with the new improvements made by Apple, it’s still far from what you can achieve with fastlane.

--

--

Freelance iOS Developer. Overly passionate about design for a developer. I like to build nice products.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nicolas Bichon

Nicolas Bichon

Freelance iOS Developer. Overly passionate about design for a developer. I like to build nice products.