Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Xcode9 + Xcode Server = Comprehensive iOS Continuous Integration

DZone's Guide to

Xcode9 + Xcode Server = Comprehensive iOS Continuous Integration

Xcode Server can now be used for easy continuous integration and testing on iOS and macOS with testing bots. Learn how to build them here.

· DevOps Zone ·
Free Resource

Download the blueprint that can take a company of any maturity level all the way up to enterprise-scale continuous delivery using a combination of Automic Release Automation, Automic’s 20+ years of business automation experience, and the proven tools and practices the company is already leveraging.

At WWDC 2017, Apple announced something that made almost every iOS developer smile: a session on What's New in Signing for Xcode and Xcode Server. It's hard to explain how easy it has become to perform continuous integration for Apple platforms, especially iOS and macOS, using Xcode 9 and Xcode Server.

CI Before Xcode 9

iOS continuous integration before the Xcode 9 release was very challenging. People might have tried the following things:

  • Fought a long battle to setup CI server machines with certificates and profiles.
  • Used Ruby-based tools like Fastlane to automate the process of analyzing, building, testing, and code signing.
  • Used other third party cloud CI services like TravisCICircleCI, or self-hosted solutions like Jenkins or TeamCity to use a Bash build script or automated build from Fastlane.
  • Used tools like xctool by Facebook or Bluepill by LinkedIn to parallelize testing on multiple devices and simulators.
  • Used third party Ruby-based tools like xcov and xcpretty for code coverage and test reporting.
  • Used Xcode Server with macOS Server app and Xcode Service for CI but still fighting with code signing and parallel execution.

Xcode Server with Xcode 9 made all this a thing of the past. You rarely need the things above now. Xcode Server handles it all for us so easily, thanks to all the developers working on developer tools to make this happen. Let's see what changes.

CI After Xcode 9

In Xcode 9, we have following new CI related features integrated within Xcode:

  • Xcode Server is inbuilt with Xcode 9 so there's no need to have a separate macOS app.
  • Xcode Server bot has new tabs for code signing and parallel testing on multiple devices and simulators with automatic provisioning of devices.
  • Automatic signing of both development and distribution signing.
  • Xcode Server creates distribution IPA with automated or manual signing
  • Xcode Sever does not launch a simulator anymore, but is still able to run in parallel.

Now we will see in action how easy it is to setup and use Xcode Server.

Setting Up Xcode Server

As mentioned earlier, Xcode Server no longer needs a macOS Server app; it's now built inside Xcode. We can see the "Servers & Bots" tab in the Xcode Preferences. We can setup Xcode Server using a local Mac or another Mac. We need to select the Mac and Integration user. See the GIF below to understand the process of enabling Xcode Server.

Once the service is running, we are good to create our Xcode bots to perform continuous integration. In this tutorial, we will create a bot for both macOS and iOS applications. We will create a bot for the Swift package XCFit for macOS and a demo app, XCS-Demo, for iOS.

Creating Bots for iOS Apps - iOS

We will use the demo app XCS-Demo to set up Xcode Server for iOS. We have regular steps to create bots from  Xcode “Product -> Create Bot” and name the bot as “XCFit Bot.” The next step is to add the Github Repo to the bot. We have to add the Git Repo with SSH. Xcode will ask you to trust the identity repository. You have to select “Trust” and use credentials of an existing SSH Key. Once successfully authorized, we should able to configure the build. The build configuration is the main stage to configure what we want to perform as part of the build. We will see the following main configuration options:

  • Scheme,
  • Actions -  Analyse, Test, Archive, and
  • Configurations.

The next screen will be on scheduling the bot integration, which is self-explanatory.

Next, we have the option to add code signing. We have the option to give Xcode Server access to the developer portal; it will do everything for us. We have another option to choose a certificate from the server machine for manual signing.

Automated Code Signing

Parallel Testing

Once we click next, we have to select devices for testing. There is a "Run tests in parallel" tick box which enables parallel execution on multiple simulators.

Test Reporting

Once the bot finishes running the tests, we get nice little reports within Xcode itself. The test reporting in Xcode Server looks like this:

Watch It in Action

The entire action looks like this:

Creating Bots for Swift Packages - macOS

Swift packages don't need to be run inside simulator or devices. We can run them on macOS. Let's create a bot for the Swift package XCFit. It's much simpler and quicker than iOS.

Benefits

We just saw some shiny new features of Xcode Server, but what benefits will it bring for a business or team?

  • No need to write scripts for build automation or manage CI servers for certificates and profiles.
  • We can achieve continuous delivery by setting Xcode Server with a few clicks.

Missing Features

Although Apple engineers made Xcode Server awesome, there are a couple of features still missing:

  • Support for testing Pull Requests like TravisCI.
  • Uploading the IPA to iTunes Connect or TestFlight.

With Xcode 9 and Xcode Server, we have almost everything in single place. It's time to retire many tools from the toolbox, e.g.  Fastlanexctool by Facebook, Bluepill by LinkedIn, or other CI servers like TravisCICircleCI, or self-hosted CI solutions like Jenkins and TeamCity. It's time to completely switch to Xcode Server.

Download the ‘Practical Blueprint to Continuous Delivery’ to learn how Automic Release Automation can help you begin or continue your company’s digital transformation.

Topics:
xcode ,swift ,ios ,mobile ,test automation ,devops

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}