Set up CI/CD with Xcode Cloud and GitHub Actions for iOS.
CI/CD Overview
# Options: Xcode Cloud (Apple), GitHub Actions, Bitrise, Codemagic, CircleCI
# Xcode Cloud: Native, integrated, paid for heavy usage
# GitHub Actions: Free for public, flexible, large communityGitHub Actions for iOS
# .github/workflows/ios.yml
name: iOS CI/CD
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
workflow_dispatch:
inputs:
deploy:
description: 'Deploy to TestFlight'
required: false
default: 'false'
env:
XCODE_VERSION: '15.2'
IOS_SIMULATOR: 'iPhone 15 Pro'
IOS_VERSION: '17.2'
jobs:
# ========================================
# LINT & ANALYZE
# ========================================
lint:
name: Lint & Analyze
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Select Xcode
run: sudo xcode-select -s /Applications/Xcode_${{ env.XCODE_VERSION }}.app
- name: SwiftLint
run: |
if command -v swiftlint &> /dev/null; then
swiftlint lint --reporter github-actions-logging
else
echo "SwiftLint not installed, skipping"
end
- name: SwiftFormat Check
run: |
if command -v swiftformat &> /dev/null; then
swiftformat --lint .
else
echo "SwiftFormat not installed, skipping"
end
# ========================================
# UNIT TESTS
# ========================================
test:
name: Unit Tests
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Select Xcode
run: sudo xcode-select -s /Applications/Xcode_${{ env.XCODE_VERSION }}.app
- name: Install dependencies
run: |
# SPM resolves automatically
# For CocoaPods:
# cd ios && pod install
- name: Run Unit Tests
run: |
xcodebuild test \
-workspace MyApp.xcworkspace \
-scheme MyApp \
-configuration Debug \
-destination 'platform=iOS Simulator,name=${{ env.IOS_SIMULATOR }},OS=${{ env.IOS_VERSION }}' \
-enableCodeCoverage YES \
-quiet \
| xcpretty --test --color
- name: Upload Coverage
uses: codecov/codecov-action@v3
with:
files: ./build/Logs/Test/*.xcresult
flags: unittests
# ========================================
# UI TESTS
# ========================================
ui-test:
name: UI Tests
runs-on: macos-latest
needs: test
steps:
- uses: actions/checkout@v4
- name: Select Xcode
run: sudo xcode-select -s /Applications/Xcode_${{ env.XCODE_VERSION }}.app
- name: Run UI Tests
run: |
xcodebuild test \
-workspace MyApp.xcworkspace \
-scheme MyAppUITests \
-configuration Debug \
-destination 'platform=iOS Simulator,name=${{ env.IOS_SIMULATOR }},OS=${{ env.IOS_VERSION }}' \
-quiet \
| xcpretty --test --color
# ========================================
# BUILD
# ========================================
build:
name: Build Release
runs-on: macos-latest
needs: [test, ui-test]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- name: Select Xcode
run: sudo xcode-select -s /Applications/Xcode_${{ env.XCODE_VERSION }}.app
- name: Install dependencies
run: |
# SPM / CocoaPods
- name: Import certificates
if: env.MATCH_PASSWORD != ''
run: |
fastlane match appstore --readonly
env:
MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
APP_STORE_CONNECT_API_KEY: ${{ secrets.APP_STORE_CONNECT_API_KEY }}
APP_STORE_CONNECT_KEY_ID: ${{ secrets.APP_STORE_CONNECT_KEY_ID }}
APP_STORE_CONNECT_ISSUER_ID: ${{ secrets.APP_STORE_CONNECT_ISSUER_ID }}
- name: Build and Archive
run: |
xcodebuild archive \
-workspace MyApp.xcworkspace \
-scheme MyApp \
-configuration Release \
-archivePath build/MyApp.xcarchive \
-quiet \
| xcpretty --color
- name: Export IPA
run: |
xcodebuild -exportArchive \
-archivePath build/MyApp.xcarchive \
-exportPath build/ipa \
-exportOptionsPlist ExportOptions.plist \
-quiet \
| xcpretty --color
- name: Upload IPA Artifact
uses: actions/upload-artifact@v4
with:
name: MyApp-ipa
path: build/ipa/*.ipa
retention-days: 7
# ========================================
# DEPLOY TO TESTFLIGHT
# ========================================
deploy-testflight:
name: Deploy to TestFlight
runs-on: macos-latest
needs: build
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && github.event.inputs.deploy == 'true'
environment: production
steps:
- uses: actions/checkout@v4
- name: Download IPA
uses: actions/download-artifact@v4
with:
name: MyApp-ipa
path: build/ipa
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
bundler-cache: true
- name: Deploy to TestFlight
run: bundle exec fastlane beta
env:
APP_STORE_CONNECT_API_KEY: ${{ secrets.APP_STORE_CONNECT_API_KEY }}
APP_STORE_CONNECT_KEY_ID: ${{ secrets.APP_STORE_CONNECT_KEY_ID }}
APP_STORE_CONNECT_ISSUER_ID: ${{ secrets.APP_STORE_CONNECT_ISSUER_ID }}
# ========================================
# DEPLOY TO APP STORE
# ========================================
deploy-appstore:
name: Deploy to App Store
runs-on: macos-latest
needs: build
if: github.event_name == 'release' && github.event.action == 'published'
environment: production
steps:
- uses: actions/checkout@v4
- name: Download IPA
uses: actions/download-artifact@v4
with:
name: MyApp-ipa
path: build/ipa
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
bundler-cache: true
- name: Deploy to App Store
run: bundle exec fastlane release
env:
APP_STORE_CONNECT_API_KEY: ${{ secrets.APP_STORE_CONNECT_API_KEY }}
APP_STORE_CONNECT_KEY_ID: ${{ secrets.APP_STORE_CONNECT_KEY_ID }}
APP_STORE_CONNECT_ISSUER_ID: ${{ secrets.APP_STORE_CONNECT_ISSUER_ID }}
# ========================================
# NOTIFICATIONS
# ========================================
notify:
name: Notify
runs-on: ubuntu-latest
needs: [test, ui-test, build, deploy-testflight, deploy-appstore]
if: always()
steps:
- name: Send Slack Notification
if: env.SLACK_WEBHOOK != ''
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
channel: '#builds'
text: 'iOS Build ${{ job.status }}'
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}ExportOptions.plist
<!-- ExportOptions.plist -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>method</key>
<string>app-store</string>
<key>teamID</key>
<string>YOUR_TEAM_ID</string>
<key>uploadBitcode</key>
<false/>
<key>uploadSymbols</key>
<true/>
<key>compileBitcode</key>
<false/>
<key>signingStyle</key>
<string>manual</string>
<key>signingCertificate</key>
<string>Apple Distribution</string>
<key>provisioningProfiles</key>
<dict>
<key>com.example.myapp</key>
<string>MyApp App Store Profile</string>
</dict>
</dict>
</plist>Xcode Cloud
# Setup: Xcode → Product → Xcode Cloud → Start Using Xcode Cloud
# Configure: Workflow file in .xcodecloud/# .xcodecloud/workflows/ci.yml
name: CI
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
environment:
xcode: latest
macos: latest
jobs:
build-and-test:
name: Build & Test
steps:
- name: Select scheme
run: xcodebuild -list -workspace MyApp.xcworkspace
- name: Resolve SPM
run: xcodebuild -resolvePackageDependencies -workspace MyApp.xcworkspace -scheme MyApp
- name: Build
run: |
xcodebuild build \
-workspace MyApp.xcworkspace \
-scheme MyApp \
-configuration Debug \
-destination 'platform=iOS Simulator,name=iPhone 15 Pro,OS=17.2' \
-quiet
- name: Test
run: |
xcodebuild test \
-workspace MyApp.xcworkspace \
-scheme MyApp \
-configuration Debug \
-destination 'platform=iOS Simulator,name=iPhone 15 Pro,OS=17.2' \
-enableCodeCoverage YES \
-quiet
ui-tests:
name: UI Tests
needs: build-and-test
steps:
- name: UI Test
run: |
xcodebuild test \
-workspace MyApp.xcworkspace \
-scheme MyAppUITests \
-configuration Debug \
-destination 'platform=iOS Simulator,name=iPhone 15 Pro,OS=17.2' \
-quiet
# Archive workflow (manual trigger)
# .xcodecloud/workflows/release.yml
name: Release Archive
on:
workflow_dispatch:
inputs:
version:
description: 'Version number'
required: true
environment:
xcode: latest
macos: latest
jobs:
archive:
name: Archive & Upload
steps:
- name: Archive
run: |
xcodebuild archive \
-workspace MyApp.xcworkspace \
-scheme MyApp \
-configuration Release \
-archivePath build/MyApp.xcarchive \
-quiet
- name: Export
run: |
xcodebuild -exportArchive \
-archivePath build/MyApp.xcarchive \
-exportPath build/ipa \
-exportOptionsPlist ExportOptions.plist \
-quiet
- name: Upload to TestFlight
run: |
xcrun altool --upload-app \
-f build/ipa/MyApp.ipa \
-t ios \
-u "$APPLE_ID" \
-p "$APP_SPECIFIC_PASSWORD"Matrix Builds
# Test multiple iOS versions and devices
jobs:
test-matrix:
name: Test (${{ matrix.device }}, ${{ matrix.os }})
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
device: ['iPhone 15 Pro', 'iPhone 15', 'iPhone SE (3rd generation)', 'iPad Pro (12.9-inch) (6th generation)']
os: ['17.2', '16.4']
include:
- device: 'iPhone 15 Pro'
os: '17.2'
xcode: '15.2'
- device: 'iPhone 15'
os: '17.2'
xcode: '15.2'
- device: 'iPhone SE (3rd generation)'
os: '16.4'
xcode: '15.2'
- device: 'iPad Pro (12.9-inch) (6th generation)'
os: '17.2'
xcode: '15.2'
steps:
- uses: actions/checkout@v4
- name: Select Xcode ${{ matrix.xcode }}
run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app
- name: Test
run: |
xcodebuild test \
-workspace MyApp.xcworkspace \
-scheme MyApp \
-configuration Debug \
-destination 'platform=iOS Simulator,name=${{ matrix.device }},OS=${{ matrix.os }}' \
-quietCaching
# Cache SPM packages
- name: Cache SPM
uses: actions/cache@v3
with:
path: |
~/Library/Caches/org.swift.swiftpm
.build
key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
restore-keys: |
${{ runner.os }}-spm-
# Cache CocoaPods
- name: Cache CocoaPods
uses: actions/cache@v3
with:
path: Pods
key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
restore-keys: |
${{ runner.os }}-pods-
# Cache Xcode build
- name: Cache Build
uses: actions/cache@v3
with:
path: ~/Library/Developer/Xcode/DerivedData
key: ${{ runner.os }}-xcode-${{ hashFiles('**/project.pbxproj') }}
restore-keys: |
${{ runner.os }}-xcode-Secrets Management
# GitHub Repository → Settings → Secrets and variables → Actions
# Required secrets:
# MATCH_PASSWORD - Passphrase for match git repo
# APP_STORE_CONNECT_API_KEY - Base64 encoded .p8 file
# APP_STORE_CONNECT_KEY_ID - Key ID from App Store Connect
# APP_STORE_CONNECT_ISSUER_ID - Issuer ID from App Store Connect
# SLACK_WEBHOOK - For notifications (optional)
# Base64 encode .p8 file:
# cat AuthKey_XXXXXX.p8 | base64 -w 0Local Development
# Run tests locally
xcodebuild test \
-workspace MyApp.xcworkspace \
-scheme MyApp \
-destination 'platform=iOS Simulator,name=iPhone 15 Pro,OS=17.2'
# Build locally
xcodebuild archive \
-workspace MyApp.xcworkspace \
-scheme MyApp \
-configuration Release \
-archivePath build/MyApp.xcarchive
# Export locally
xcodebuild -exportArchive \
-archivePath build/MyApp.xcarchive \
-exportPath build/ipa \
-exportOptionsPlist ExportOptions.plistTry It
Set up GitHub Actions workflow. Add linting, tests, build. Configure certificates with Match. Deploy to TestFlight. Test matrix builds.
# Create workflow file
mkdir -p .github/workflows
# Add ios.yml from examples
# Push to triggerCI/CD pipeline
- Create GitHub Actions workflow for iOS
- Add lint (SwiftLint), unit tests, UI tests
- Configure code signing with Match
- Build and archive for release
- Deploy to TestFlight on main branch
- Deploy to App Store on release tag
- Add matrix testing for multiple iOS versions
- Set up caching for faster builds
- Add Slack notifications
GitHub Actions: flexible, free for public repos. Xcode Cloud: native, integrated, paid. Use Match for certificates. Matrix test on multiple devices/OS versions. Cache SPM, CocoaPods, DerivedData. Deploy to TestFlight from main, App Store from tags.
Resources
- GitHub Actions iOS: https://github.com/actions/starter-workflows/blob/main/ci/ios.yml
- Xcode Cloud: https://developer.apple.com/xcode-cloud/
- xcpretty: https://github.com/xcpretty/xcpretty
- Fastlane CI: https://docs.fastlane.tools/best-practices/continuous-integration/