Fastlane and the secret recipe for automated iOS deployment

Yehia Beram
4 min readJun 8, 2021

Have you ever considered using an automated process to build, archive, or even test your iOS application, like you want to get rid of the pain of releasing a new version from your exciting project?

Photo by Zan on Unsplash

Then you should consider using the amazing Fastlane, the tool that created to save your day and automate your amazing deployment process.

What is Fastlane?

Fastlane is the easiest way to automate beta deployments and releases for your iOS and Android apps. 🚀 It handles all tedious tasks, like generating screenshots, dealing with code signing, and releasing your application.

You can start by creating a Fastfile file in your repository, here’s one that defines your beta or App Store release process:

lane :beta do
increment_build_number
build_app
upload_to_testflight
end
lane :release do
capture_screenshots
build_app
upload_to_app_store # Upload the screenshots and the binary to iTunes
slack # Let your team-mates know the new version is live
end

You just defined 2 different lanes, one for beta deployment, one for App Store. To release your app in the App Store, all you have to do is

fastlane release

How to install Fastlane to your machine?

You can install Fastlane in multiple ways. In this article, we will use Homebrew to install Fastlane, so first of all, you need to install Homebrew on your machine. In your terminal, add this command:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

By then, you already have brew installed on your local machine. Now, It’s time to install Fastlane using this command:

brew install fastlane

How to setup Fastlane on your project

First of all, you need to run this command inside the root directory of your project; then, run this command:

fastlane init

Since Fastlane works with Android and iOS, you will find that it’s smart enough to detect if you run this command in an Android project or iOS project, as shown in Figure 1.

Figure 1.

Type 4 and press enter as we want to install it manually to customize it as we wish you will find the output as shown in Figure 2.

Figure 2.

You will find a new directory inside your main project directory called Fastlane. Open it, and you will find two files, as shown in Figure 3.

Figure 3.

Firstly, let’s open Appfile with any text editor and update the correct values of your application, as shown in Figure 4.

Figure 4.

Then let’s go back to Fastfile as it will be our main playground, as shown in Figure 5.

Figure 5.

We need to give our lane a new name like upload_to_testflight_lane then let’s start cooking the recipes.

First of all, let’s add the build app command to prepare our app for the uploading process.

build_app(scheme: "your_scheme_name")

then add upload to test flight command

upload_to_testflight

By then, you have to be excited to run this game-changing command :D

Figure 6.

Now after you added this command all you have to do run this command

$ fastlane upload_to_testflight

FastLane will only ask you to authenticate your Apple account from the terminal, and then it will upload your app automatically on behalf of you. 🎉 🎉

Now, we have successfully automated the app uploading process locally on our machine. The next step is to get the help of a CD/CI server to automate the deployment on the cloud. Stay tuned!

--

--

Yehia Beram

iOS Team Lead — Mobile App Developer @ TrianglZ LLC | Swift | apple | Lifelong Learner | Fifa player