How To Set Up A CI CD Pipeline For Your IOS App Using Fastlane And GitHub Actions?

Asked one year ago
Answer 1
Viewed 462
1

At the point when we foster iOS applications, we as a rule deal with the application distribution process utilizing the Xcode Coordinator. Then we sign, test, assemble, chronicle, submit, change forms, submit new forms over and over to the TestFlight or AppStore.

On the off chance that we create our constructs everyday, this interaction is drawn-out and tiring. Along these lines, in this article I will tell you the best way to execute Gitlab CI in your iOS task and afterward we will perceive how to transfer expands on TestFlight consequently.

What is CI/CD?

Constant Reconciliation and Consistent Conveyance (CI/Compact disc) for iOS empower us to further develop our fabricate sends. We're ready to deliver refreshes whenever in a supportable manner without the obstacle of doing it physically like clockwork. We don't have to run every one of our tests when we add new code or adopt an experimentation strategy prior to pushing a focus on our vault.

GitLab comes with CI built-in for all projects, for free.

Fastlane assists you with robotizing the most tedious beta dissemination steps including increasing the form rendition, code marking, fabricating and transferring the application, and setting a change-log.

Could GitLab at any point be utilized for persistent combination?

  • You will require an iOS application to arrange our Constant Mix and Conveyance pipeline. Then, you should design another vault.
  • Prior to hopping into the execution, let us initially grasp the work process of Gitlab CI.
  • How to set up a CI Disc pipeline for your iOS application utilizing fastlane and GitHub Activities?
  • You make changes to your duplicate of the codebase and push a focus on GitLab.
  • GitLab perceives that the codebase has changed.
  • GitLab triggers a form with the GitLab Sprinter you set up on your Macintosh for the venture.
  • The GitLab Sprinter goes through the form and test process you determined in .gitlab-ci.yml.
  • The GitLab Sprinter reports its outcomes back to GitLab.
  • GitLab shows you the aftereffects of the form.
  • For execution, we have these essential necessities:

Gitlab: as our CI(Continuous Incorporation) stage

Xcode 11 or above with Quick 5.1 (or above) as our advancement apparatuses.

XCTestCases to make and run unit tests and UI tests.

Assumptions & Prerequisites

We are accepting that you have the Gitlab storehouse of your iOS application as of now arrangement. Additionally, these things are required in your Xcode project:

  • Make a point to incorporate Unit Tests and Remember UI Tests for the undertaking.
  • Have a gitlab repo arrangement for your venture.
  • Ensure that your venture conspire is Shared.

Note: To share a plan in Xcode, pick Item > Plan > Oversee Plans.

By sharing undertaking plan, GitLab CI gets setting it needs to fabricate and test your venture.

Presently, open Terminal and explore to the organizer you made for your iOS project.
Adding a norm .gitignore file is helpful For a Quick task, enter:

$ curl -o .gitignore gitignore.io/api/swift

The twist order helpfully downloads the items in the page at the given gitignore.io URL into a document named .gitignore.

Install XCPretty

Introduce xcpretty for experiment reports. At the point when Xcode assembles and tests your undertaking, xcpretty will change the result into something more intelligible configuration.

Installation:

Open Terminal and enter the accompanying order:

$ sudo gem install xcpretty
OR
$ gem install xcpretty --user-install

Take a stab at utilizing any of the abovementioned, on the off chance that the other one tosses some consent mistake (which I for one confronted).

Installing & Registering Gitlab Runner

The GitLab Sprinter is a help that is introduced on your Macintosh, which runs the form and test process that you set up in a design file(.gitlab-ci.yml).

Installation

Download the double for your framework:

sudo curl --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-amd64

Give it authorizations to execute:

sudo chmod +x /usr/local/bin/gitlab-runner

Register

To enlist a Sprinter under macOS run the accompanying order:

$ gitlab-runner register

Enter your GitLab example URL:

Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com )

https://serveraddress.com/gitlab/

Enter the symbolic you acquired to enroll the Sprinter: (You will get this token once you signed in to the gitlab into your record setting pipeline segment. On the off chance that this token isn't right then it won't enroll sprinter to GitLab)

Enter a depiction for the Sprinter, you can change this later in GitLab's

How to verify if Runner properly registered?

  • Goto below Path <Home>/Users/<user>/gitlab-runner/config.toml
  • .gitlab-runner directory will be created. This is hidden directory
  • In that directory there is “config.toml”
  • This config file will list down all the runners installed on the Mac machine
  • increase the value of the runner limit from this file. output_limit = 20000

Commands-

To run gitlab sprinter use:
gitlab-sprinter run
To confirm that your gitlab sprinter is running or not, enter the underneath order:
gitlab-sprinter confirm
Really take a look at the sprinter status. In the event that it's not running, If it's not too much trouble, use beneath orders to run the sprinter.
gitlab-sprinter stop
gitlab-sprinter restart

Pipeline Implementation

Make a .gitlab-ci.yml in your task root registry with given form stages Construct, Test, Chronicle, Delivery.

Assemble: This stage will fabricate the your undertaking.
Test: This stage will run the Unit and UI experiments of your undertaking and show on your GitLab console/terminal.
Chronicle: This stage will produce and IPA document record, and you can likewise transfer it on Gitlab.
Discharge: There are 2 strategies to deliver the forms:

This stage will transfer the chronicle document on Gitlab(or in the nearby undertaking registry) from that point you can circulate the form to analyzers and partners.
Other strategy is to send the expand on the TestFlight utilizing Fastlane.
The last thing to do is to arrange .yml record. To do as such, open your .gitlab-ci.yml record with the word processor and enter the accompanying:

stages:
  - build
  - archive
  
build_project:
  stage: build
  script:
    - xcodebuild clean -workspace ProjectName.xcworkspace -scheme SchemeName | xcpretty
    - xcodebuild test -workspace ProjectName.xcworkspace -scheme SchemeName -destination 'platform=iOS Simulator,name=iPhone 12 Pro,OS=15.2' | xcpretty -s
  tags:
   - ios-tag
   - version-1.0archive_build:
  dependencies: []
  stage: archive
  artifacts:
    paths:
      - build/ProjectName.ipa
  script:
    - fastlane beta
  tags:
    - ios-tag
    - version-1.0
  only:
    - master

Save this document in your Xcode project organizer as .gitlab-ci.yml, and remember the period toward the start of the record name!

We should go through the record with some detail:

The document initially portrays the stages accessible to each work. For straightforwardness, we have one phase (fabricate) and one work (build_project).
The document then, at that point, gives the settings to each work. The build_project work runs two contents: one to clean the Xcode undertaking, and afterward one more to fabricate and test it. You can presumably skirt the cleaning content to save time, except if you need to be certain that you're working from a spotless state.
Under labels, add the labels you made when you enlisted the GitLab Sprinter.
The fastlane betabasically triggers the fastlane script present in the fastlane/fastfile and transfers the expand on Testflight. To just chronicle the form, then, at that point, use fastlane exercise center rather than fastlane beta . We will investigate this later in this article as it were.
There are additionally a things to pay special attention to:

Make a point to supplant all references to ProjectName with the name of your Xcode project; in the event that you're utilizing an unexpected plan in comparison to the default, ensure you pass in the legitimate SchemeName as well (the default is equivalent to the ProjectName).
In the xcodebuild test order, notice the - objective choice is set to send off an iPhone 12 Expert picture running iOS 15.2 in the Test system; if you need to run an alternate gadget (iPad, for instance), you'll have to change this.
There's a basic device for "linting" (i.e., approving) your .gitlab-ci.yml in GitLab. From your GitLab project page, click on CI/Album > Pipelines in the sidebar, then, at that point, in the upper-right corner, click on CI build up:

Other salient points

This work process ought to work for any sort of Xcode project, including tvOS, watchOS, and macOS. Simply make certain to determine the fitting Test system gadget in your .gitlab-ci.yml record.

If you have any desire to push a commit yet don't have any desire to set off a CI form, just add [ci skip] to your commit message.

On the off chance that the client that introduced the GitLab sprinter isn't signed in, the sprinter won't run. Thus, in the event that forms appear to be forthcoming for quite a while, you might need to mind this!

In the event that you're dealing with a group, or on the other hand on the off chance that your undertaking is public, you might need to introduce the GitLab Sprinter on a devoted form machine. It can in any case be very diverting to utilize your machine and have Test system send off startlingly to run a test suite.

This work process ought to work for any sort of Xcode project

In this article, we will chronicle the form utilizing fastlane and afterward send it on Testflight.

Introducing Fastlane in Macintosh

Fastlane arrangement is the urgent move toward the entire cycle since it is the foundation of the organization interaction. To introduce Fastlane in your framework, kindly go through the underneath steps: Introduce the most recent Xcode order line devices:

sudo gem install fastlane -NV

# Using RubyGems
sudo gem install fastlane -NV# Alternatively using Homebrew
brew cask install fastlane

To begin utilizing fastlane in your venture, you'll have to run fastlane init from your undertaking catalog in order line.

Fastlane will ask you for some essential design and afterward make an organizer called fastlane in your undertaking which will contain primarily two records:

1. fastlane/Appfile

This document is direct, so you simply need to check to ensure that the Apple ID and application ID that you set up before are right.

app_identifier("APP IDENTIFIER") # The bundle identifier of your app
apple_id("APPLE ID") # Your Apple email address

2. fastlane/gymfile

rec center forms and bundles iOS applications for you. It deals with all the hard work and makes it simple to create a marked ipa or application document .

To make a rec center document in your task, you'll have to run this order from your undertaking catalog in order line.

$ fastlane gym init

Since you should consequently set off another form yet don't have any desire to determine every one of the boundaries like clockwork, you can store your defaults in a supposed Gymfile.

Run fastlane rec center init to make another arrangement document. Model:

scheme("SchemeName")sdk("iphoneos15.2")clean(true)output_directory("./build")    # store the ipa in this folder
output_name("AppName")           # the name of the ipa file

3. fastlane/fastfile

The fastfile characterizes the form steps. Since we're utilizing a great deal of the inherent capacity of fastlane this is truly clear. We make a solitary path which augmentations fabricate number, gets testaments, constructs, and transfers the new form to TestFlight. Obviously, you might need to part these out into various positions relying upon your utilization case. Every one of these means, get_certificates, get_provisioning_profile, match, rec center, and upload_to_testflight are pre-packaged activities previously included with fastlane.

Read Also : What is the future growth of sales manager?
Answered one year ago Pirkko  KoskitaloPirkko Koskitalo