Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
G Guides
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • ios-general
  • Guides
  • Wiki
  • continuous integration

Last edited by Artem Kalmykov Apr 20, 2017
Page history

continuous integration

Continuous integration is this guide is based on Gitlab CI. Each step of this setup, except of the first one, is optional - implement only what you need.

1. Gitlab CI.

To setup Gitlab CI you need to add .gitlab-ci.yml file to the root of project's source. It should look like this:

stages:
  - analyze
  - test
  - crashlytics

before_all do
        ENV["SLACK_URL"] = "MySlackHookURL"
        clear_derived_data
    end
error do |lane, exception|
        slack(
            message: exception.message,
            success: false
        )
    end

analyzation:
  stage: analyze
  script:
    - ./analyze.sh
  except:
    - triggers

testing:
  stage: test
  script:
    - xcodebuild -workspace MyWorkspace.xcworkspace -scheme MyScheme -configuration MyConfiguration -destination "platform=iOS Simulator,name=iPhone 7,OS=10.3" build test | xcpretty
  except:
    - triggers

crashlytics_build:
  stage: crashlytics
  script:
    - fastlane ios release_dev
  only:
    - develop
  except:
  - triggers

Add only stages you need. Replace MySlackHookURL with your Slack incoming webhook. Or remove if not needed.

2. Analyzation Stage

To setup analyzation you need to do the following:

  • Properly configure the project for Release configuration, especially enable almost all warnings:
  • Set Treat Warnings as Errors to Yes.
  • Set Documentation Comments to Yes.
  • Set Empty Loop Bodies to Yes.
  • Set Four Character Literals to Yes.
  • Set Hidden Local Variables to Yes.
  • Set Implicit Boolean Conversions to Yes.
  • Set Implicit Constant Conversions to Yes.
  • Set Implicit Conversion to 32 Bit type to Yes.
  • Set Implicit Enum Conversions to Yes.
  • Set Implicit Integer to Pointer Conversion to Yes.
  • Set Implicit Signedness Conversions to Yes.
  • Set Infinite Recursion to Yes.
  • Set Initializer Not Fully Bracketed to Yes.
  • Set Mismatched Return Type to Yes (treat as error).
  • Set Missing Fields in Structure Initializers to Yes.
  • Set Missing Function Prototypes to Yes.
  • Set Missing Newline At End of File to Yes.
  • Set Out-of-Range Enum Assignments to Yes.
  • Set Sign Comparison to Yes.
  • Set Suspicious Implicit Conversions to Yes.
  • Set Uninitialized Variables to Yes (Aggressive).
  • Set Unknown Pragma to Yes.
  • Set Unreachable Code to Yes.
  • Set Unused Functions to Yes.
  • Set Unused Labels to Yes.
  • Set Unused Parameters to Yes.
  • Set Unused Variables to Yes.
  • Set Suspicious Moves to Yes.
  • Set Direct Usage of 'isa' to Yes (treat as error).
  • Set Duplicate Method Definitions to Yes.
  • Set Implicit Atomic Objective-C Properties to Yes.
  • Set Overriding Deprecated Objective-C Methods to Yes.
  • Set Strict Selector Matching to Yes.
  • Set Undeclared Selector to Yes.
  • Set Unintentional Root Class to Yes (treat as error).
  • Set Implicit Ownership Types on our parameters to Yes.
  • Set Implicit Retain of 'self' within blocks to Yes.
  • Set Repeatedly using a __weak reference to Yes.
  • Set Misuse of 'nonnull' to Yes (Aggressive).
  • Set Missing Localizability to Yes.
  • Set Floating Point Value used as Loop Counter to Yes.
  • Set Use of 'rand' functions to Yes.
  • Set Use of 'strcpy' and 'strcat' to Yes.
  • Add analyze.sh script to the project's root folder: analyze.sh

Replace MyWorkspace, MyScheme and MyConfiguration with appropriate values.

  • Add analyzation stage to .gitlab-ci.yml file, it should look like the following:
analyzation:
  stage: analyze
  script:
    - ./analyze.sh
  except:
    - triggers
  • Commit those changes to the repository. If everything is setup correctly, Analyzation stage should be invoked on each commit.

3. Testing Stage

This stage allows to run unit tests on each commit. To achieve that, add the following code to .gitlab-ci.yml file:

testing:
  stage: test
  script:
    - xcodebuild -workspace MyWorkspace.xcworkspace -scheme MyScheme -configuration MyConfiguration -destination "platform=iOS Simulator,name=iPhone 7,OS=10.3" build test | xcpretty
  except:
    - triggers

Replace MyWorkspace, MyScheme and MyConfiguration with appropriate values. Also, make sure that simulator name and OS version are relevant.

4. Crashlytics Build Stage

This stage allows builds to be uploaded to Crashlytics automatically with each commit or merge to develop brach.

  • Setup fastlane, if not yet done. To do that, run fastlane init in project's root folder and follow the steps.
  • Create a line for Crashlytics build in fastfile. It should look like this:
lane :lane_name do
        gym(scheme: "MyScheme", configuration: "MyConfiguration")
        crashlytics(
            api_token: "MyAPIToken",
            build_secret: "MyBuildSecret",
            debug: true,
            groups: ["members"],
            notifications: true,
            notes: last_git_commit[:message]
        )
    end

Replace lane_name, MyScheme and MyConfiguration with appropriate values of your project. Replace MyAPIToken and MyBuildSecret from appropriate values from Crashlytics configuration.

  • Test this line by invoking `fastlane ios lane_name.
  • Add crashlytics stage to .gitlab-ci.yml. Don't forget to replace lane_name with your lane name:
crashlytics_build:
  stage: crashlytics
  script:
    - fastlane ios lane_name
  only:
    - develop
  except:
  - triggers
Clone repository
  • Swift Code Style
  • automated slack builds
  • continuous integration
  • Home
  • jenkins auto build
  • shared localization
  • versioning rules