iOS Builds on macOS Runners
Xcode, the iOS SDKs, the simulators and codesign exist only on macOS, and Apple's licence only allows macOS to run on Apple hardware. So every iOS pipeline needs a Mac somewhere:
| Option | Notes |
|---|---|
GitHub-hosted macOS runners (macos-15, …) |
Apple Silicon VMs with several Xcode versions preinstalled; billed at a higher per-minute rate than Linux |
| Xcode Cloud | Apple's CI, configured in Xcode/App Store Connect; signing handled for you; limited customisation |
| Other hosted CI (Bitrise, Codemagic, CircleCI, GitLab SaaS macOS) | similar VMs, often with mobile-specific steps |
| Self-hosted Macs (Mac minis, Mac Studio, cloud Macs such as AWS EC2 Mac) | cheapest at scale, fastest caches; you maintain Xcode versions, cleanup and security |
A common split keeps everything that doesn't need a Mac on Linux (linting, SwiftPM packages that compile on Linux, backend work) and sends only the Xcode build, tests and archive to the expensive machines.
Pin the Xcode version
A macOS runner image contains several Xcodes; the default changes when the image is updated. Select one explicitly, and fail loudly if it's missing:
sudo xcode-select -s /Applications/Xcode_16.4.app # path as installed on the runner image
xcodebuild -versionPin both the runner image (macos-15, not macos-latest) and the Xcode path. Upgrading Xcode is then a reviewed change, like upgrading AGP.
The workflow
# .github/workflows/ios-release.yml (non-run)
name: ios-release
on:
push:
tags: ['v*']
jobs:
testflight:
runs-on: macos-15
environment: production
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
with: { fetch-depth: 0 }
- name: Select Xcode
run: sudo xcode-select -s /Applications/Xcode_16.4.app
- name: Cache SwiftPM checkouts
uses: actions/cache@v4
with:
path: build/SourcePackages
key: spm-${{ runner.os }}-${{ hashFiles('**/Package.resolved') }}
- uses: ruby/setup-ruby@v1
with: { bundler-cache: true } # installs Fastlane from Gemfile.lock
- name: Test
run: |
set -o pipefail
xcodebuild test -scheme Hello \
-destination 'platform=iOS Simulator,name=iPhone 16' \
-clonedSourcePackagesDirPath build/SourcePackages \
-onlyUsePackageVersionsFromResolvedFile \
-resultBundlePath build/Tests.xcresult | xcbeautify
- name: Archive, sign and upload to TestFlight
run: bundle exec fastlane ios beta
env:
MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
MATCH_GIT_BASIC_AUTHORIZATION: ${{ secrets.MATCH_GIT_TOKEN_B64 }}
ASC_KEY_ID: ${{ secrets.ASC_KEY_ID }}
ASC_ISSUER_ID: ${{ secrets.ASC_ISSUER_ID }}
ASC_KEY_P8: ${{ secrets.ASC_KEY_P8 }}
BUILD_NUMBER: ${{ github.run_number }}
- uses: actions/upload-artifact@v4
if: always()
with:
name: ios-${{ github.ref_name }}
path: |
build/*.ipa
build/*.dSYM.zip
build/Tests.xcresultThe Android release job and this one share their shape on purpose: checkout with tags, pinned toolchain, dependency cache keyed on the lockfile, tests, a signed release artifact, upload, archived symbols. The Fastlane lane beta is written in Fastlane for iOS.
Simulators and destinations
-destination 'platform=iOS Simulator,name=iPhone 16' needs a simulator runtime that exists on that image; a new Xcode often drops old device names. Two robust habits:
- list what's available in the job (
xcrun simctl list devices available) and pick by OS (platform=iOS Simulator,OS=latest,name=…); - build for testing once and run tests separately (
xcodebuild build-for-testingthentest-without-building), which also lets you shard tests across machines.
Making macOS minutes cheaper
| Technique | Saves |
|---|---|
Cache build/SourcePackages keyed on Package.resolved |
package checkouts |
-derivedDataPath + cache (carefully: large, Xcode-version-specific) |
incremental compilation |
Run unit tests of portable packages with swift test on Linux |
Mac minutes |
Skip the Mac job when only Android files changed (paths: filters) |
entire jobs |
| Self-hosted Macs for heavy users | per-minute cost (but adds maintenance) |
A runnable model: which jobs does a change need?
Path filters decide whether the expensive job runs at all. A model of the rules a monorepo with both apps might use:
from fnmatch import fnmatch
RULES = {
"android": ["android/**", "shared/**", ".github/workflows/android-*.yml"],
"ios (macOS)": ["ios/**", "shared/**", ".github/workflows/ios-*.yml"],
"swift-linux": ["ios/Packages/Core/**"],
}
def jobs_for(changed):
return [job for job, patterns in RULES.items()
if any(fnmatch(path, pat) for path in changed for pat in patterns)]
changes = {
"Android only": ["android/app/build.gradle.kts"],
"iOS UI": ["ios/Hello/ContentView.swift"],
"iOS Core package": ["ios/Packages/Core/Sources/Core/Price.swift"],
"shared API schema": ["shared/api.graphql"],
"docs": ["README.md"],
}
for name, files in changes.items():
print(f"{name:<18} -> {', '.join(jobs_for(files)) or 'nothing'}")Android only -> android
iOS UI -> ios (macOS)
iOS Core package -> ios (macOS), swift-linux
shared API schema -> android, ios (macOS)
docs -> nothing
Test yourself
Why pin macos-15 and an explicit Xcode path rather than using macos-latest?
- macos-latest is slower
- The default image and default Xcode change over time, which would change your build without a commit
- Xcode can't be selected otherwise
- It's required for code signing
Why add set -o pipefail before xcodebuild … | xcbeautify?
- xcbeautify needs it
- Without it, the pipeline's exit status is xcbeautify's, so failing tests could look green
- It speeds up the build
- It enables colours
Which parts of an iOS codebase can be tested without a Mac?
- None
- Swift packages that don't import Apple-only frameworks, with
swift teston Linux - The whole app via a Linux simulator
- Only UI tests