Continuous integration for iOS projects using Semaphore CI

Continuous integration for iOS projects using Semaphore CI

Posted on by Ciprian Redinciuc Ciprian Redinciuc · 3 min read

Intro

Continuous integration and delivery can help developers ship with more confidence and Semaphore CI is one of the fastest tools out there to help you achieve that.

I recently stumbled upon Semaphore CI and I've been blown away by how fast and easy to use it is, even on the free plan.

In the past, I have tried multiple tools such as TravisCI, Bitrise, CircleCI and even in-house tools such as Jenkins that comes with a higher level of flexibility but also maintenance.

What is Semaphore CI?

Semaphore CI is a CI/CD service that allows teams to build continuous integration pipelines with the promise of removing that feeling of a bottleneck when you or any team member push some changes to your repository and wait for ages for your build to just start.

With tools such as Travis I even had to wait over an hour for my builds to be queued and build. Before that build even finished I usually had some new changes that were waiting in the pipeline.

I can easily confirm that when I started using Semaphore that feeling was gone and boy they deliver on that promise of being the fastest CI/CD tool in the market.

Setting up your first project

Setting up a workflow is quite simple once you connect Semaphore CI to your Github account. Once you have done that you can just select a repository and a new project will be created for you.

Selecting a repository

This will create a setup-semaphore branch in your repository with a .semaphore folder in it and a usual .yml file to handle the build machine and workflow configuration.

I find this approach more appealing than the approach others offer - creating the folder and file yourself - as it tries to remove as much human error as possible.

When Semaphore CI finishes setting up your project you can go on and edit your first workflow.

If your project relies on Cocoapods you can just create a job that installs its dependencies and runs your tests:

checkout
pod install
xcodebuild -workspace UserDesk.xcworkspace -list
xcodebuild test -scheme UserDesk -workspace UserDesk.xcworkspace -destination 'platform=iOS Simulator,name=iPhone 11 Pro'

Setting up a workflow

Your build should pass (or fail, if you mistyped something) and it should do that pretty fast. Once your build has succeeded, you can go into your Github repository and merge the setup-semaphore branch into your develop or master branch.

Semaphore CI and iOS Projects

Semaphore for iOS

Semaphore CI is not a mobile dedicated CI service but it does a pretty good job at covering the basics. They provide decent build machines with 4 vCPUs and 8 GB of RAM or you can request one with 8 vCPUs and 16 GB of RAM.

Projects can be built with Xcode 11 running on macOS Mojave that already have preinstalled tools such as Fastlane, Homebrew, CocoaPods or Node.js and it integrates with services such as HockeyApp or TestFlight.

Because I think it's a good idea to use dependencies with the same version on both your development machine and your build machine I decided to set up fastlane for my project using gems installed via bundler. You can check an in-depth article here where I go through setting up fastlane for your project.

My project uses both fastlane and cocoapods along with some fastlane plugins such as fastlane-plugin-semaphore and fastlane-plugin-codecov_reporter for code coverage reporting, therefore the gemfile looks like this:

source "https://rubygems.org"

gem "fastlane"
gem "cocoapods"

plugins_path = File.join(File.dirname(__FILE__), './fastlane', 'Pluginfile')
eval_gemfile(plugins_path) if File.exist?(plugins_path)

The fastfile just defines a single lane to run tests but you can build more from here:

default_platform(:ios)

before_all do
  # Install with `fastlane add_plugin semaphore`
  setup_semaphore
  cocoapods
end

platform :ios do
  desc 'Run tests'
  lane :test do
    scan
    codecov_reporter
  end
end

Commit the fastlane configuration to your master branch and wait for the build to finish.

Semaphore builds

Now that you've set it up you can ship incremental improvements to your project with confidence thanks to Semaphore.

Want products news and updates?

Sign up for our newsletter to stay up to date.

We care about the protection of your data. Read our Privacy Policy.

© 2020 Applicodo SRL. All rights reserved.