How to Create Your Xcode Cloud Workflow

Use Xcode Cloud to ship App Store Connect builds with every new release on GitHub

Eskil Gjerde Sviggum
Better Programming

--

A common issue with larger projects is that one doesn’t know which commit is actually for release on the App Store.

Perhaps you were in a hurry when you made the previous release and forgot to tag it in GitHub? Or even forgot to merge the branch you were working on so the release code isn’t in the main branch?

Knowing which code is in the release is crucial when analyzing bug reports and to avoid duplicate work. CI/CD is one solution to this problem. By moving the process of deploying an app to GitHub, you can maintain good branching and release-tagging strategies.

Xcode Cloud is an elegant opportunity for Apple platform developers to make use of continuous integration and delivery (CI/CD) in their apps. Made available to all Apple developers with Xcode 14, and fully built into Xcode — configuring CI/CD for your app project couldn’t be easier.

Configuring Project

Before creating a workflow in Xcode Cloud, we need to make sure everything is set up correctly within the project. Configuring everything correctly in advance eliminates surprise build failures in the cloud.

1. Ensure Scheme is Shared and Archive is Enabled for the Target

Most projects are likely already configured correctly here. The scheme you want to build needs to be available to Xcode Cloud, and the target needs to have the Archive option (under Build) enabled.

Just to ensure it is, choose edit scheme (⌘ + ;) and see if everything looks good.

Edit scheme with “Build” selected. Shared enabled. Archive enabled for the appropriate target.

2. Make Dependencies Available to Xcode Cloud

The easiest way is to use Swift packages, which require little additional configuration.

You just need to approve that your Package.resolved file at $filename.xcodeproj/project.workspace/xcshareddata/swiftpm/Package.resolved is available in your Git repository.

Xcode Cloud uses this file instead of automatic package resolution to resolve SPM dependencies. Note that the file may be ignored in your project’s .gitignore.

If your project relies on private SPM dependencies the build in Xcode Cloud will fail, but will give you instructions on how to make the dependencies available in the build logs.

Xcode Cloud can also resolve dependencies from CocoaPods or Carthage, but this requires additional setup and is beyond the scope of this article. If you’re interested, see Apple’s great documentation on reviewing third-party dependencies.

Creating a Workflow

You’re now ready to create a workflow for your project.

Go to the Report navigator (⌘ + 9), and press Get Started… under the Cloud tab. If you’ve already created a workflow, you may instead right-click on the target and choose Manage Workflows… to create a new one.

The Report navigator pane in Xcode in the “Cloud” section with “Get started” highlighted.

Xcode will guide you through creating a new workflow, starting with selecting the target you want to use. Most configuration is done on the Review Workflow page. Press Edit Workflow… on the bottom of the sheet.

The Review Workflow step with the “Edit Workflow…” button highlighted.

To build a new app for App Store Connect on a new release, you want to change three settings.

1. Environment

In the environment settings, enable the Clean option to build every deployment from scratch. This is a requirement by Xcode Cloud when building for Release.

Environment settings with the “Clean” toggle enabled.

2. Start Conditions

Add a new start condition based on Tag Changes and remove the one based on branch. You can configure the start conditions even further by for instance requiring the commit to be tagged with a certain tag (e.g. Release).

Tag changes selected under “Start conditions” with the add button highlighted.

3. Archive

In the archive settings you want to select App Store as the Deployment Preparation. If you have TestFlight enabled, you may select Test Flight alternatives here after you have created the workflow.

Settings for achive with “App Store” selected under Deployment Preparation.

Press save and proceed to the next step of granting access and connecting the workflow to your GitHub repository.

Conclusion

Congrats! Just like that, you have set up CI/CD on your app project with Xcode Cloud. Whenever you create a new tagged release in GitHub, Xcode Cloud will invoke and build a new release of your app which you can manage in App Store Connect.

--

--