Fastlane integration into iOS projects

Fastlane is an instrument for automatic applications' building, loading and release. By Fastlane you can make screens of different display sizes for stores.

The task is to automize testing on pull-request, build and its sending to testflight by merge to develop brunch and screenshots making.
Configuration
For work with Fastlane we have to have:

  • XCode command line tools, using command xcode-select-install
  • Fastlane itself, using command sudo gem install fastlane -N, if you have RubyGems, and brew cask install fastlane, if you have HomeBrew
After setting go to the project folder and write fastlane init
There are 3 preset configurations:
  1. For screenshots making
  2. For builds' sending to testflight
  3. For App Store release
We choose manual configuration.
After that there's fastlane folder in project folder and there are 2 files:

  • Fastfile that has all the fastlane configurations for this project
  • Appfile that has profile information (bundle_id, app_Identifier, team_id)
All available commands are kept on official Fastlane website.
I'll tell about some of them:

  • cert - work with certificates. Download and set required certificates for signing gathered apps
  • sigh - work with provisioning profiles. It's also download and set provisioning profiles
  • increment_build_number - increase build number by 1 or set chosen value
  • scan - testing
  • gym - archiving and build .ipa file
  • slack - Slack integration
  • testflight - sending the build to testflight
Let's write first configuration that will launch tests with pull-request.
Configuration params:

  • Clean - project cleaning before build
  • Code_coverage - output of code coverage by app tests
  • Scheme - project scheme
  • Output_directory - way to directory that has generated report
  • Skip_slack - flag for ignoring Slack notifications
Let's write configuration for app loading into testflight:
While launching this configuration certificates and provisioning will be being downloaded and set, the number of their last building on TestFlight increases, the build will be built and loaded in TestFlight, also the notification will be sent to Slack with version number.
If you have double-step verification you need to add into environment the FASTLANE_APPLE_APPLICATION
_SPECIFIC_PASSWORD
variable. For the password getting:

  1. Go to the website
  2. Generate new password for application
  3. Copy and paste this password into our variable
Sometimes by the repeated build launching there can be an error "Database is locked Possibly there are two concurrent builds running in the same filesystem location". If this error appeared you need to change build system to "Legacy Build".
Also by the error appearing we will send notification to Slack with this error description:
Slack Notifications
You need to add bot to your channel for Slack notifications.
Go to Slack website, set your workspace and name. Then add Incoming Webhooks, choose channel and get URL that we can add to fastlane configuration.
CI Installation
As CI we'll use gitlab-runner. We add configuration to launch tests with pull-request and to release version by push in master on testflight. We need CI to add configuration into .gitlab-ci.yml project folder.
  • Variables
    • LC_ALL, LANG - required variables for fastlane work
    • GIT_STRATEGY - by each project launch we copy the project
  • before-script - scripts that executing before our stages execution, in our case we'll set pods in project
  • stages - stages that CI will consistently pass by required circumstances execution
Then it's time for our stages:

  1. pull-request - stage that launches if we do merge-request in develop brunch which successful passage gets report of passed and unpassed tests
  2. testflight-upload - the stage that launches if we push in master
GitLab-runner can be deployed on any PC, you only need to sign it up.
Gitlab-runner on PC, example
If one of configurations fits requirements we get new "work" attached to this commit.
Successfull passage, example
If in configuration passage the error appeared we get a notification on mail about failure.
Summing Up
GitLab with Fastlane is greatly fits for app build automatization and testing. It helps to make up for developer's time. The build loading process is becoming simpler on testflight, now you can launch it by Git and it's not connected to computer of exact developer.
Thanks for reading!