Section 12/221 menit

12. Xcode Cloud & GitHub Actions Tuning

12. Xcode Cloud & GitHub Actions Tuning

Xcode Cloud: ci_scripts untuk Speed

swift
#!/bin/bash
# ci_scripts/ci_post_clone.sh
# Dijalankan setelah Xcode Cloud clone repo

set -e

echo "=== Setting up build environment ==="

# Install bundler dependencies (CocoaPods, Fastlane)
cd $CI_WORKSPACE
gem install bundler --no-document
bundle install --jobs $(nproc) --retry 3

# Install pods
bundle exec pod install --repo-update

# Log environment untuk debugging
echo "Xcode version: $(xcodebuild -version)"
echo "Ruby version: $(ruby --version)"
echo "Swift version: $(swift --version)"
swift
#!/bin/bash
# ci_scripts/ci_pre_xcodebuild.sh
# Dijalankan sebelum xcodebuild — cocok untuk code generation

set -e

# Generate Swift files dari R.swift, Sourcery, dsb.
if command -v sourcery &> /dev/null; then
    sourcery --config .sourcery.yml
fi

# Validasi bahwa semua required env vars tersedia
if [ -z "$API_BASE_URL" ]; then
    echo "ERROR: API_BASE_URL not set"
    exit 1
fi

echo "Pre-build setup complete"

Xcode Cloud: Caching Strategies

Xcode Cloud tidak mendukung manual cache seperti GitHub Actions — caching dikelola otomatis. Tapi ada cara untuk mempercepat:

swift
1. Gunakan Start Condition yang tepat: hanya trigger build untuk branch tertentu,
   bukan setiap push ke semua branch.

2. Custom alias untuk workflow: pisahkan workflow PR Check (cepat, unit test only)
   dan Release workflow (lengkap, all tests + archive).

3. Post-clone script yang efisien: bundle exec pod install lebih cepat dari pod install
   (menggunakan bundler untuk konsistensi versi).