Using Gitlab CI/CD + Fastlane for iOS Project — Part 2

Phan Quang Hoàng
4 min readApr 19, 2019

--

In previous tutorial, we installed Runner, Fastlane tool to run CI/CD on Gitlab. We are also configuring for swiftlint to check code style convention and a lot errors happened.

Now, we continue with this step to fix all errors in code.

We need to create .swiftlint.yml in the root directory of the project to do that. This file tell with swiftlint library what we need to check in our project.

$ touch .swiftlint.yml

Then, open this file with vim, it is the text editor tool:

$ vim .swiftlint.yml

And paste content to your .swiftlint.yml file:

disabled_rules: # rule identifiers to exclude from running- colon- comma- control_statementopt_in_rules: # some rules are only opt-in- empty_count# Find all the available rules by running:# swiftlint rulesexcluded: # paths to ignore during linting. Takes precedence over `included`.- Pods- vendoranalyzer_rules: # Rules run by `swiftlint analyze` (experimental)- explicit_self# configurable rules can be customized from this configuration file# binary rules can set their severity levelforce_cast: warning # implicitlyforce_try:severity: warning # explicitly# rules that have both warning and error levels, can set just the warning level# implicitlyline_length: 110# they can set both implicitly with an arraytype_body_length:- 300 # warning- 400 # error# or they can set both explicitlyfile_length:warning: 500error: 1200# naming rules can set warnings/errors for min_length and max_length# additionally they can set excluded namestype_name:min_length: 4 # only warningmax_length: # warning and errorwarning: 40error: 50excluded: iPhone # excluded via stringidentifier_name:min_length: # only min_lengtherror: 1 # only errorexcluded: # excluded via string array- id- URL- GlobalAPIKeyreporter: “xcode” # reporter type (xcode, json, csv, checkstyle, junit, html, emoji, sonarqube, markdown)

Now, build again! All errors are resolved. But there are many warnings, you will try to fix by yourself later. 🤩

Come back to Fastlane. We will configure for Fastlane also can run Swiftlint and export the report. Open Fastfile in fastlane directory in the root project and paste this script in your file:

desc "Does a static analysis of the project. Configure the options in .swiftlint.yml"lane :lint doswiftlint(mode: :lint,executable: "Pods/SwiftLint/swiftlint",reporter: "html",output_file: "fastlane/swiftlint-results.html",config_file: '.swiftlint.yml',ignore_exit_status: true)end

Okay, type this command in terminal:

$ fastlane lint

Let see the result:

Then, you can see the report as .html format in your fastlane directory:

Awesome!

Next, we will integrate with code coverage to measure how many percent code is covered.

Open Fastfile, paste the following content:

desc "Test an measure code coverage"lane :test dorun_tests(devices: ["iPhone XS"])xcov(workspace: "CoinMarket.xcworkspace",scheme: "CoinMarket",output_directory: "fastlane/xcov_output")end

To can get coverage, we must allow Xcode export coverage file when run testing.

Open workspace -> Edit Schema -> Test -> Options -> check on Code coverage.

Open Gemfile, add xcov gem to the project: gem ‘xcov’, ‘~> 1.5’

Then, run bundle install to install new gem.

bundle install --path vendor

After new gem is installed, we are going to run lane test to execute code coverage action on Fastfile.

fastlane test

If everything is so far so good now, let open fastlane folder, you will see new reported in this directory. Let see the results:

This is good project! 😂

Okay! We will continue with Fastlane to complete the configuration in next tutorial.

Preferences:

--

--

Phan Quang Hoàng
Phan Quang Hoàng

No responses yet