CI/CD for iOS in GitHub actions using Fastlane: Part — 1

shafayat hossain
3 min readJul 7, 2023

--

Photo by Henry Ascroft on Unsplash

I was a native Android developer for more than 4 years. Then I started developing iOS apps along with Android. On my experience during that transition period, I was planning to write the necessary steps how to automate release process of an iOS app easily using Fastlane. That’s why I am going to explain the whole thing in 4 parts:

  • Fastlane initial setup and certificates management
  • Connection with Appstore
  • Building and uploading app to test flight
  • Integration with Github actions

Let’s start with the first part.

Fastlane initial setup and certificates management

For setting up Fastlane, the primary requirement is Ruby 2.7 or up. I recommend Ruby 3.0.1. By default, macOS does have ruby 2.6. You can check your Ruby version by running the command ruby -v. If you need to install or upgrade ruby, I recommend RVM for setting up ruby. Because if you mess up with upgrading Ruby, then you’re done for that day. It’s kind of a hassle to set up Ruby and Cocoapods properly. Before proceeding, ensure your Ruby version is 2.7 or up and Cocoapods is installed properly.

Initial Setup

Create a file named Gemfile at the root of your iOS project. Now put the following contents in the file by opening it with a text editor.

source "https://rubygems.org"
gem "fastlane"

Now open a terminal window and change the working directory to your project root. Then run bundle update command. It will create a Gemfile.lock file.

Create A Fastlane Project

You can create a Fastlane project using the Fastlane command or manually. Here you’ll do it manually. It’s very easy. Just create a fastlane folder at the root of your project and inside that, create a file named Fastfile. Create .env.secret file in fastlane folder. You will put some environmental secrets here later. And don’t forget to add this file into .gitignore. Initially put following data into that file:

APP_STORE_CONNECT_TEAM_ID=<Team ID>
APP_STORE_CONNECT_USERNAME=<AppStore Username>
BUNDLE_ID=<Appliation Bundle ID>

You’ll need multiple Fastlane plugins in different steps. We’ll define those dependencies in a plugin file. Create a file named Pluginfile in the fastlane folder. Now you ’ve to connect this plugin file with the .Gemfile. Put the following lines in the .Gemfile.

plugins_path = File.join(File.expand_path("..", __FILE__), 'fastlane', 'Pluginfile')
eval_gemfile(plugins_path)

And put before all block in Fastfile where we will do some task before executing our fastlane functions. For now let’s load the .env.secret file here:

fastlane_require 'dotenv'
before_all do |lane|
Dotenv.overload '.env.secret'
end

Match setup

We’ll follow codesigning guide for certificates management. Before proceeding, ensure you have a separate repository where certificates will be uploaded for future usage

Now run bundle exec fastlane match init command. It will ask for storage mode. Select git. Then it’ll as for git repository URL. Provide the URL you created earlier to store certificates. It’ll create Matchfile into the fastlane folder.

For iOS development, we mostly need development and appstore certificates. Other than those, to upload build into firebase app distribution we need adhoc certificate. To create those, run bundle exec fastlane match development, adhoc, appstore. It will ask for a passphrase to encrypt certificates, AppStore login credentials and bundle ID. Provide everything it asks.

That’s it!! Now, from the XCode, you can see it detects that signing certificates are installed for your project.

In next part I’ll explain how to connect with the AppStore.

--

--

shafayat hossain

Lazy enough to write a bio. LinkedIn - shafayat-hossain-khan