Automate Distribution Process through Fastlane in iOS Swift | CI

Muhammad Ahmad
4 min readJun 8, 2023

--

Automation through Fastlane

As I have done CI/CD of a website in my development career with my previous team. I was curious how can I implement it in iOS. I have done it now. So, I will share my experience with you.

Fastlane is an open-source platform that automates the development and release of mobile apps. It may be used for the automation of processes including app development, testing, and deployment to the App Store. Fastlane is a fantastic tool for reducing wait times and raising the caliber of your app releases.

Fastlane is the simplest method to automate beta deployments and releases for your iOS and Android apps. It manages all laborious duties, including creating screenshots, taking care of code signing, and publishing the application.

You must do the following in order to set up Fastlane for an iOS app:

1. Install the Xcode command-line tools.

2. Install Fastlane.

3. Initialize Fastlane.

4. Create a Fastfile.

5. Add lanes to your Fastfile.

6. Run Fastlane.

Installation & Configuration Steps

* Install the Xcode command-line tools

Xcode Command Line Tools is a package provided by Apple that includes a set of software development tools, command-line utilities, and frameworks required for software development on macOS. Although Xcode is the full-featured integrated development environment (IDE) for creating iOS, macOS, watchOS, and tvOS applications, Xcode Command Line Tools provide a quick and easy alternative for programmers who want to work mainly through the command line.

Navigate to your project path. Run the following command in a terminal window to install the Xcode command-line tools:

xcode-select –install

* Install Fastlane

Fastlane is a Ruby-based tool, so you’ll need Ruby and RubyGems installed before proceeding. First, you’ll need to install Fastlane, by the following command in terminal

sudo gem install fastlane -NV

You can also install with Homebrew as It installs the adequate Ruby version for Fastlane itself, enter following the command in the terminal.

brew install Fastlane

If you go with Homebrew, you can also install xcbeautify for the code formatter.

brew install xcbeautify

export PATH=$PATH:$HOME/.brew/bin

Now enter your Mac password and wait for the installation — :)

Wow!!! Gem is installed. Now, Let’s move to the next steps.

If you still face any errors refer to the below

Reference:

* Initialize Fastlane

Now your Fastlane is installed and it’s time to initialize it to automate our process.

For Fastlane initialize to create files, run the following command in terminal

fastlane init swift

WOW, you did great so far!!! Let’s continue the configuration part. I’ll pass Type 3 and select Targets if you have any otherwise just enter the apple id and password. As I have added a target so I’ll select one.

Note: password should be app-specific, you can generate it with the following link.

Link:

* Create a Fastlane file

Now, you can see the Gem files and Fastlane files generated.

Check your project folder, and in the Fastlane folder, you will see Appfile. Just open it and check your information:

fastlane Directory
Appfile.swift

· Add lanes to your Fastfile

You can add your custom lane in Fastfile

class Fastfile: LaneFile {
func betaLane() {
desc("Push a new beta build to TestFlight")
incrementBuildNumber(xcodeproj: "YOUR.xcodeproj")
buildApp(
workspace: "YOUR.xcworkspace",
scheme: "YOUR_SCHEME",
clean: true,
silent: true,
xcargs: "-allowProvisioningUpdates") // automate code signing
uploadToTestflight(username: "YOUR_APPLE_ID")
}

func releaseLane() {
desc("Push a new release build to the App Store")
incrementBuildNumber(xcodeproj: "YOUR.xcodeproj")
buildApp(workspace: "YOUR.xcworkspace", scheme: "YOUR_PRO_SCHEME")
uploadToAppStore(
username: "YOUR_APPLE_ID",
appIdentifier: "YOUR_APP_IDENTIFIER",
skipScreenshots: true,
skipMetadata: true)
}
}

* Run Fastlane

Enter the command in the terminal

Reference:

By Muhammad Ahmad | Medium| GitHub | LinkedIn | Portfolio

--

--