How to implement private dependencies to Xcode Cloud

Kaan Ozdemir
Mobillium
Published in
4 min readJun 16, 2022

Hello everyone,

In this article, we will try to explain running a project which has private repository on Xcode Cloud workflow without committing Pod files.

But firstly, Let’s find out why we should integrate Xcode Cloud to our project.
Apple says;

Automatically build, test, and distribute your apps with Xcode Cloud to verify changes and create high-quality apps.

If you have an intention to get rid of preparing version, please continue to read this article.

Let’s check Xcode Cloud overview. It say;

Xcode Cloud lets you adopt continuous integration and delivery (CI/CD), a standard software development practice that helps you develop and maintain your code and deliver apps to testers and users. Xcode Cloud is a CI/CD system that combines the tools you use to create apps and frameworks for Apple platforms: Xcode, TestFlight, and App Store Connect.

Why do we need to use Continuous Integration(CI) and Continuous Delivery/Development(CD)?

The aim with CI is to make software development easier and more tracable.

The goal with CD is to deliver a build to the production environment safely and repeatedly. CD goes after CI.

Let’s say we developped a feature, committed it and opened a PR, after our PR, CI will take over the process. CI will build our project, run our tests in the project and achieve our package.

After CI, CD will take over the process. And then CD will deploy a package to team automatically.

Please google it if you want to know more.

Let’s integrate Xcode Cloud to our project.

The process that you will follow in Apple’s documentation about Xcode Cloud is too clear. Please follow this documentation first.

After ingrated Xcode Cloud to our project, let’s solve private repository problem.

Firstly, If we don’t commit pod files to our repository, Xcode Cloud will fail at building process about not to find pod files that we used in our project. Because we don’t have it in our main project repo.

What do we need to do?

We need to run pod install before build. To make that happen, we should use custom build script. We can use Home Brew for it. Because Cloud includes Home Brew. If you don’t have it in your Mac, please check this link.

To install a tool using Home Brew;

1. Create a folder next to your Xcode project or workspace and name it ci_scripts.

2. Create an executable shell script, name it ci_post_clone.sh, and save it in the ci_scripts directory. For example, use the Shell Script template in Xcode to create the file(TextEdit → Go to ci_scripts directory → Save and make its extension as .sh).

And then, open terminal, go to ci_scripts directory to make it an executable by running chmod +x ci_post_clone.sh .

3. Open the custom script in Xcode and add the necessary commands to install a tool with Homebrew.

But first if you’re using CocoaPods, first make sure you commit both your Podfile and the Podfile.lock file.

Then, exclude the Pods directory from source control by adding it to your .gitignore file.

Now, time to write custom script to install CocoaPods. Open Xcode and Go to Build Phases. Click plus(+) button and add new Run Script Phase.

Adding the codes below to our run script.

#!/bin/sh

# Install CocoaPods using Homebrew.

brew install cocoapods

# Install dependencies you manage with CocoaPods.

pod install

Now, after adding run script to our project, we should commit some changes to trigger Xcode Cloud. It will run some operations and throw an error about private repo. After this error we should go to AppStore Connect.

AppStore Connect → App that we want to grant access → Xcode Cloud → Settings → Additional Repositories → Access Requested

You will see grant access about private repo in additional part of this page. By tapping Grant button, you can grant access to Xcode Cloud to have access our private repo.

Select Complete Step 2 in GitHub and follow the steps to grant permission about the private repo.

After completed the steps correctly you will see your repo on Access Granted tab.

Now we are able to use Xcode Cloud with private repo.

Thank you for your time. See you for the next article. :)

--

--