CI/CD for iOS in GitHub actions using Fastlane: Part — 4
This is the final part of CI/CD integration. In previous parts I tried to explain Fastlane setup, AppStore Connection API and uploading app to AppStore.
Integration with Github actions
To run CI/CD for iOS project, MacOS server is a must. The cost of a MacOS machine is very high. I suggest Azure DevOps for integrating CI/CD if you have a private repository. Its free tier cap is higher than other platforms. Otherwise, if you’re working on a public repository, definitely Github workflow is the best choice because it’s free for the public repository.
Let’s move on to integration…
Github actions run workflow based on .yml files in the .github/workflows folder. Create a .github folder at the project’s root and inside the folder, create a workflows folder. Now create a .yml file inside the folder; let’s name it ios-ci-cd.yml.
You will trigger the workflow for this project when you push any commit. This configuration is written with on syntax.
name: App build
on: push
There are more events available there. You can check out the workflow doc for more details.
On push event, GitHub will do some jobs. Jobs and their steps should also be defined on that file. Possible steps to complete the CI/CD can be
- Setup MacOS machine
- Checkout the repository
- Setup Ruby
- Run Fastlane steps
Let’s define these steps one by one.
Setup MacOs machine
Several macOS versions are available for the workflow according to the Github-hosted runners doc. You’re going to use “macos-latest” here.
jobs:
build_with_signing:
runs-on: macos-latest
Checkout The Repository
From here, you’ll start defining steps for the job. Github has its action called checkout, which you’ll use here.
steps:
- name: Checkout Repository
uses: actions/checkout@v3
Setup Ruby
Before integrating CI/CD, requirements were to have ruby 2.7 or up installed on the environment. And Ruby 3.1 was chosen. Let’s install Ruby 3.1 here using setup-ruby action. Additionally, Ruby gem dependencies will be installed using the bundler.
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.1'
bundler-cache: true
Run Fastlane Steps
Final step is to build, test, archive and distribute the app using Fastlane. So basically, you’ve to execute bundle exec fastlane <lane_name> command. Before that, you must set the environment locale and languages to UTF-8 US English.
So the step is as follows:
- name: Build and distribute app
run: |
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
Bundle exec fastlane release
Let’s put all these steps together. The workflow yml file will look like this:
name: App build
on: push
jobs:
build_with_signing:
runs-on: macos-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
bundler-cache: true
- name: Build and distribute app
run: |
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
Bundle exec fastlane release
We’ve now set up a basic, fully automated CI/CD pipeline for your iOS project using Fastlane and GitHub Actions. This is just the beginning, though. There’s so much more to learn and explore in this space. For instance, managing secrets in your pipeline is a critical aspect that we haven’t touched upon. Additionally, you might want to delve into more advanced topics like parallel testing, conditional workflow execution, and deployment strategies to different environments. Remember, the goal is to continuously improve your development and deployment processes. Happy Coding!