Xcode9 + Xcode Server = Comprehensive iOS Continuous Integration
At WWDC 2017, Apple announces 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 becomes to perform Continuous Integration for Apple platforms especially iOS and macOS using Xcode 9 and Xcode Server.
CI Before Xcode 9
The iOS Continuous Integration before Xcode 9 release was very challenging. As people might have tried following things
- Fought long battle to setup CI server machines with certificates and profiles.
- Used Ruby based tool like Fastlane to automate the process of analysing, building, testing and code signing.
- Used other third party cloud CI services like TravisCI, CircleCI or self-hosted solutions like Jenkins, TeamCity to use bash scripted build 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, 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 these things of past. You rarely need the things above now. Xcode Server handles it all for us so easily. Thank all the developers working on developer tools to make this happen. Let’s see what’s 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 no need to have 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.
- Automatically signing of both development and distribution signing.
- Xcode Server creates distribution IPA with automated or manual signing
- Xcode Sever does not launch simulator anymore still able to run in parallel.
Now, we will see that in action how easy to setup and use Xcode Server.
Setting Up Xcode Server
As mentioned earlier, Xcode Server no longer needs macOS Server app, it’s now built inside Xcode. We can see “Servers & Bots” tab in the Xcode Preference. We can setup Xcode Server using 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 the continuous integration. In this tutorial, we will create a bot for both macOS and iOS application. We will create Bot for Swift package XCFit for macOS and Demo app XCS-Demo for iOS.
Creating Bots for iOS Apps – iOS
We will use Demo app XCS-Demo for iOS to set up Xcode Server. We have regular steps to create bots from Xcode “Product -> Create Bot” and name the bot as “XCFit Bot”. Next step is to add Github Repo to the Bot. We have to add Git Repo with SSH. Xcode will ask you to trust the identity repository. You have to select “Trust” and use credential of existing SSH Key. Once successfully authorised, we should able to configure build. The build configuration is the main stage to configure what we want to perform as part of the build. We will see following main configuration options.
- Actions – Analyse, Test, Archive and
Next screen will be on scheduling the Bot integration which is self-explanatory.
Next, we have the option to add code signing. We can have the option to give Xcode Server access to developer portal and it will do everything for us. We have other option to choose a certificate from server machine for manual signing.
Automated Code Signing
We click next we have seen to select devices for testing and there is “Run tests in parallel” tick box which enables parallel execution on multiple simulators.
Once bot finishes running 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 Swift package XCFit. It’s much simpler and quicker than iOS
We just saw some shiny new features of Xcode Server but what will benefit that will bring for 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 within few clicks
Although, Apple engineers made Xcode Server awesome there are couple of features still missing
- Support for testing Pull Request just like TravisCI
- Uploading the IPA to iTunes Connect or TestFlight
- do you think anything else?
With Xcode 9 and Xcode Server, we have almost everything in single place. It’s time to retire many tools from toolbox e.g Fastlane, xctool by Facebook or Bluepill by LinkedIn or other CI servers like TravisCI, CircleCI or self-hosted CI solutions like Jenkins, TeamCity. It’s time to completely switch to Xcode Server.