In the testing and release stage of an iOS project, it will generally go through the process of packaging – screenshot – upload and metadata filling and modification again and again. At this point, the students doing server development are much happier than us, because they can entrust this part of the work to the operation and maintenance students. So we have to do all these repetitive and time-consuming operations manually? The answer is no, Fastlane gives us a whole suite of tools to help us automate.

Fastlane introduction, configuration and installation

1. Introduction

Fastlane is an automated build tool based on Ruby development that provides a complete solution for the project release process.

2. Install

2.1 Ensure that the latest Xcode Command Line Tools is installed

This is standard for iOS developers using Xcode. If you are prompted not to install it, use the following command to install it

xcode-select --install 
Copy the code

2.2 Selecting an installation mode

There are three installation modes:

homebrew installer script RubyGem
brew cask install fastlane Download the installation package and run the installation script sudo gem install fastlane -NV

I used Cocoapods for all of my projects with a native Ruby environment, so I chose the third installation option

2.3 installation bundler

If you don’t have Bundler installed in your Ruby environment, run the following command to install Bundler

sudo gem install bundler
Copy the code

Configuration of 3.

Go to the root directory of the project

3.1 the initialization

fastlane init
Copy the code

During initialization, your APPID and password will be asked. Please be assured that the password will only be stored in the local keychain and will not be transmitted to the cloud server.

During initialization, there are four options to create configurations for four different tasks:

  1. Automatic screenshots
  2. Automatically createdTestFlightBeta release project
  3. Automatically createdAppstorePublish the project
  4. Manually set the configuration of your required tasks

You can select the third item when you create it for the first time. It will automatically detect the App Name and App bundleID of the current project and output them to the console. If the information is wrong, you can select N when confirming the information and manually edit it in the configuration file. If y is selected, a directory structure similar to the following will be generated, in which the two core files Appfile and Fastfile will be created.

Heavy Metal Metal Metal Metal Metal Metal Metal Metal Metal Metal Metal Metal Metal Metal Metal Metal Metal Metal Metal Metal Metal Metal Metal Metal Metal Metal Metal Metal Metal Metal Metal Metal Metal Metal metal metal metal metal metal metal metal metal metal metal metal metal metal metal metal │ ├ ─ ─ keywords. TXT │ │ ├ ─ ─ marketing_url. TXT │ │ ├ ─ ─ name. TXT │ │ ├ ─ ─ privacy_url. TXT │ │ ├ ─ ─ release_notes. TXT │ │ └ ─ ─ TXT │ ├─ Heavy metal Exercises ─ heavy metal Exercises. TXT │ ├─ Heavy metal Exercises ─ heavy metal exercises ├ ─ ─ secondary_category. TXT │ ├ ─ ─ secondary_first_sub_category. TXT │ ├ ─ ─ secondary_second_sub_category. TXT │ └ ─ ─ useful - Hans │ ├ ─ ─ the description. TXT │ ├ ─ ─ keywords. TXT │ ├ ─ ─ marketing_url. TXT │ ├ ─ ─ name. TXT │ ├ ─ ─ privacy_url. TXT │ ├ ─ ─ TXT │ ├─ ├─ └.txtCopy the code

If n is selected, you can use the commands of fastlane to generate the configuration file.

I’m used to manually setting up the configuration files myself, and generally use the fourth method to create tasks directly.

3.2 Use Gemfile to manage fastlane versions and dependencies

Like Cocoapods, Fastlane can use Gemfile to manage versions and dependencies.

When init is executed, a Gemfile is automatically generated with the following contents:

source "https://rubygems.org"

gem "fastlane"
Copy the code

You can specify the fastlane version information directly here.

Our initialization operation is complete.

Second, Fastlane concept and components

In the previous initialization, two core files Appfile and Fastfile were generated. Appfile holds the bundleID and appID of your app.

Fastfile is our actual automated process operation implementation file where we will implement the relevant actions.

1. The concept

There are two important concepts in Fastlane:

  • Action: Each action is an action and corresponds to a command.
  • Lane: An operational process, such as publishingappstoreA series of packagesactionThe collection is a lane, publishedadhocThe bag is another lane

When you run the Fastlane command line tool, the Fastfile file in the Fastlane directory is read and the corresponding Lane action is performed

A simple process:

lane :dependence_manager do
Cocoapods belongs to an action
cocoapods
Carthage belongs to an action
carthage
end
Copy the code

2. The component

Fastlane provides a toolset that covers most of the operations that are likely to be used in the publishing process, including several broad categories:

  • Testing:scan– Automatically generates test tools and can generateHTMLThe report
  • Construction:gym– Project packaging tools,cocoapod– performpod installoperation
  • Screenshots:snapshot– Screenshot tool (need to write UI test),framekit– Generates a screenshot with a border
  • Project:increment_build_number: Increases the number of project builds
  • Signature:match– Synchronize signature information and itemsprovision profile,certSynchronization –ADCCertificate information,register_device– toADCTo add a new device
  • Documents:appledoc– Generated from source codeAppleStyle code documentation
  • Beta: testflight– Publish the project totestflight
  • Push:pem– Obtain the push certificate
  • Release:deliver– Publish the project toappstoreEtc.
  • Version control:git pull– I don’t need to explain
  • Notice:Slack– Communicate packaging information to your development team

Fastlane provides a wide variety of tools. The above list only lists some of the commonly used components. For more information, visit the Fastlane Actions document

3. Third-party plug-ins

Fastlane provides plenty of tools in-house, but also supports third-party plugins. You can use

fastlane search_plugins
Copy the code

Command to view all available third-party plug-ins.

Here are two of the most commonly used plug-ins:

  • Firim: Release the test package tofirim
fastlane add_plugin firim
Copy the code
  • Pgyer: Publish the test package to dandelion
fastlane add_plugin pgyer
Copy the code

Three, Fastlane practice tour

Because fastlane provides so many components, not all of them are necessarily available in project practice. For example, with the Snapshot screenshot tool, the author has not had the opportunity to practice it because the company’s promotional pages are all using THE UI cutting image. This section only provides an overview of the components that I actually used in my project, but fastlane provides very detailed documentation if the parts you are looking for are not covered.

1. Match – Synchronizes certificates and provision profiles

In iOS projects developed by many people, most of the novices should have made jokes about deleting certificates. Especially, some small companies use personal developer accounts to develop company projects, and members need to rely on P12 files of certificates to transfer certificates, which is inefficient and inconvenient to manage.

The Fastlane match command provides a git-based certificate and provision profile management solution. The certificates and provision profiles generated by match will be synchronized to a git address specified by you. The required members can use Match to pull down the required certificates to the local directory. Match will synchronize the ADC certificates and provision profiles with the required certificates.

1.1 Initializing match

Through the command

match init
Copy the code

This will ask you to enter a Git address that is where the certificate will be stored, and it will create a Matchfile in the fastlane of your project that will contain the git address

1.2 Generating a Certificate and provision Profile

Generate the appstore publishing certificate and provision profile
fastlane match appstore

Generate adhoc issue certificates and provision profiles
fastlane match adhoc

Generate a debug certificate
fastlane match development
Copy the code

In this step, match checks whether the required certificates and provision profiles are available in the ADC. If yes, the certificates and provision profiles are directly downloaded to the ADC. If not, the certificates and provision profiles are directly created in the ADC

The provision profile automatically created by match is shown in the following figure:

Not having to create it manually in an ADC at all is very interesting

1.3 Configuring a Certificate and provision Profile in Xcode

This step is the same as manually creating the configuration certificate.

1.4 Configuring lane for certificate Operations in Fastlanefile

The actual configuration affixed to the project

desc "Init develope environment"
  lane :config do
    match(type: "appstore".app_identifier: AppID, readonly: true)
    match(type: "adhoc".app_identifier: AppID, readonly: true)
    cocoapods
  end
Copy the code

After the above configuration is complete, you only need to perform it after joining a new team member or changing a device

fastlane config 
Copy the code

Command can synchronize the entire development release environment, quite convenient.

2. Sigh-select the correct provision profile

Match downloads the provision profile to the local PC, and Sigh confirms the provision profile before packaging

Usage:

sync_code_signing(type: "appstore".readonly: true.app_identifier: AppID)
Copy the code

3. Gym – Compilation and packaging tool

This action is the corresponding Xcode Archive operation

# gym is an alias for the build_app command
build_app(workspace: "xxxxxx.xcworkspace".scheme: "xxxxxxxx".configuration: "release".The path to the. Ipa file
              output_directory: "./Package/AppStore".export_method: "app-store")
Copy the code

4. Deliver – Publishing tools

If fastlane init does not allow fastlane to automatically synchronize project metadata in the ADC. You can use

fastlane deliver init 
Copy the code

The metadata folder and Deliverfile are created in the Fastlane directory of the project.

If the METADATA information already exists in the ADC, this parameter can be used

fastlane deliver download_metadata
Copy the code

To synchronize metadata information on the ADC.

Note: If there is an edited metadata in the ADC that is not synchronized locally, the metadata delivered will overwrite the original metadata

The actual use in Fastfile is as simple as one line:

# deliver is an alias for upload_to_app_store
upload_to_app_store
Copy the code

5. Lane for the full appstore launch

The Fastfile is as follows:

desc "upload release version"
  lane :release do
    sync_code_signing(type: "appstore".readonly: true.app_identifier: AppID)
    build_app(workspace: "xxxxx.xcworkspace".scheme: "xxxxxxx".configuration: "release".output_directory: "./Package/AppStore".export_method: "app-store")
    upload_to_app_store
  end
Copy the code

Just do it from the command line

fastlane release
Copy the code

The release process can be fully automated, greatly saving the developer’s time.

6. Post to FIR.im or dandelion

Replace upload_to_APP_store with the upload method provided by the FIRIM or PGYER plug-in.

firim(firim_api_token:"xxxxxxxxxxxxxxxxxx")

Four,

Fastlane is an extremely powerful automated build tool that allows you to customize many personalized actions using Action. I’ve just provided a set of solutions that meet the most basic publishing needs. If you have a better solution, welcome email exchange.

Since my company doesn’t have a dedicated iOS baler, unfortunately I didn’t have the opportunity to practice Fastlane + Jekins. However, as software development engineers, we have always been pursuing a more “relaxed” way of working, and the author will continue to make efforts in this direction in the future work.

5. References

A small team of automatic release: WHLSXL. Making. IO/index. HTML

How to Set Up Fastlane: blog.metova.com/how-to-set-…

Fastlane official documentation: docs.fastlane.tools/

Definition of abbreviation

ADC: Apple Developer Center

ITC: iTunes Connect