|
| 1 | +name: iOS Runner Prebuild (CI-only) |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +permissions: |
| 7 | + contents: read |
| 8 | + |
| 9 | +concurrency: |
| 10 | + group: ci-${{ github.workflow }}-${{ github.ref }} |
| 11 | + cancel-in-progress: true |
| 12 | + |
| 13 | +jobs: |
| 14 | + prebuild-ios-runner: |
| 15 | + name: Build iOS 26.2 Prebuilt |
| 16 | + runs-on: macos-26 |
| 17 | + timeout-minutes: 60 |
| 18 | + env: |
| 19 | + IOS_RUNTIME_VERSION: '26.2' |
| 20 | + IOS_DEVICE_NAME: 'iPhone 17 Pro' |
| 21 | + PREBUILT_DIR: ${{ runner.temp }}/ios-runner-prebuilt |
| 22 | + DERIVED_DATA_PATH: ${{ runner.temp }}/ios-runner-derived |
| 23 | + steps: |
| 24 | + - name: Checkout |
| 25 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 26 | + |
| 27 | + - name: Setup toolchain |
| 28 | + uses: ./.github/actions/setup-node-pnpm |
| 29 | + |
| 30 | + - name: Resolve Xcode cache key |
| 31 | + id: xcode |
| 32 | + run: | |
| 33 | + set -euo pipefail |
| 34 | + XCODE_VERSION="$(xcodebuild -version | tr '\n' ' ' | sed -E 's/[[:space:]]+/ /g; s/[[:space:]]$//')" |
| 35 | + XCODE_KEY="$(echo "$XCODE_VERSION" | tr ' ' '-' | tr -cd '[:alnum:]._-')" |
| 36 | + echo "version=$XCODE_VERSION" >> "$GITHUB_OUTPUT" |
| 37 | + echo "key=$XCODE_KEY" >> "$GITHUB_OUTPUT" |
| 38 | +
|
| 39 | + - name: Restore prebuilt cache |
| 40 | + id: restore-prebuilt |
| 41 | + uses: actions/cache/restore@v4 |
| 42 | + with: |
| 43 | + path: ${{ env.PREBUILT_DIR }} |
| 44 | + key: ios-runner-prebuilt-${{ steps.xcode.outputs.key }}-ios-${{ env.IOS_RUNTIME_VERSION }} |
| 45 | + |
| 46 | + - name: Resolve iOS runtime 26.2 |
| 47 | + if: steps.restore-prebuilt.outputs.cache-hit != 'true' |
| 48 | + id: runtime |
| 49 | + run: | |
| 50 | + set -euo pipefail |
| 51 | + RUNTIME_ID="$( |
| 52 | + xcrun simctl list runtimes -j | node -e " |
| 53 | + const fs = require('node:fs'); |
| 54 | + const payload = JSON.parse(fs.readFileSync(0, 'utf8')); |
| 55 | + const targetVersion = process.env.IOS_RUNTIME_VERSION; |
| 56 | + const runtime = (payload.runtimes ?? []) |
| 57 | + .filter((item) => item.isAvailable) |
| 58 | + .find((item) => item.platform === 'iOS' && item.version === targetVersion); |
| 59 | + if (!runtime?.identifier) process.exit(1); |
| 60 | + process.stdout.write(runtime.identifier); |
| 61 | + " |
| 62 | + )" |
| 63 | +
|
| 64 | + if [ -z "$RUNTIME_ID" ]; then |
| 65 | + echo "Could not find available iOS runtime ${IOS_RUNTIME_VERSION}" >&2 |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | +
|
| 69 | + echo "runtime_id=$RUNTIME_ID" >> "$GITHUB_OUTPUT" |
| 70 | +
|
| 71 | + - name: Create simulator for runtime |
| 72 | + if: steps.restore-prebuilt.outputs.cache-hit != 'true' |
| 73 | + id: simulator |
| 74 | + run: | |
| 75 | + set -euo pipefail |
| 76 | + UDID="$(xcrun simctl create "agent-device-prebuild-${GITHUB_RUN_ID}" "$IOS_DEVICE_NAME" "${{ steps.runtime.outputs.runtime_id }}")" |
| 77 | + echo "udid=$UDID" >> "$GITHUB_OUTPUT" |
| 78 | + xcrun simctl boot "$UDID" || true |
| 79 | +
|
| 80 | + - name: Build ios-runner for testing |
| 81 | + if: steps.restore-prebuilt.outputs.cache-hit != 'true' |
| 82 | + run: | |
| 83 | + set -euo pipefail |
| 84 | + rm -rf "$DERIVED_DATA_PATH" "$PREBUILT_DIR" |
| 85 | + xcodebuild build-for-testing \ |
| 86 | + -project ios-runner/AgentDeviceRunner/AgentDeviceRunner.xcodeproj \ |
| 87 | + -scheme AgentDeviceRunner \ |
| 88 | + -destination "id=${{ steps.simulator.outputs.udid }}" \ |
| 89 | + -derivedDataPath "$DERIVED_DATA_PATH" |
| 90 | +
|
| 91 | + - name: Package prebuilt artifact |
| 92 | + if: steps.restore-prebuilt.outputs.cache-hit != 'true' |
| 93 | + run: | |
| 94 | + set -euo pipefail |
| 95 | + mkdir -p "$PREBUILT_DIR" |
| 96 | + cp -R "$DERIVED_DATA_PATH" "$PREBUILT_DIR/derived-data" |
| 97 | + cat > "$PREBUILT_DIR/metadata.txt" <<EOF |
| 98 | + runtime_version=${IOS_RUNTIME_VERSION} |
| 99 | + runtime_id=${{ steps.runtime.outputs.runtime_id }} |
| 100 | + device_name=${IOS_DEVICE_NAME} |
| 101 | + simulator_udid=${{ steps.simulator.outputs.udid }} |
| 102 | + xcode_version=${{ steps.xcode.outputs.version }} |
| 103 | + github_run_id=${GITHUB_RUN_ID} |
| 104 | + github_sha=${GITHUB_SHA} |
| 105 | + EOF |
| 106 | +
|
| 107 | + - name: Save prebuilt cache |
| 108 | + if: steps.restore-prebuilt.outputs.cache-hit != 'true' |
| 109 | + uses: actions/cache/save@v4 |
| 110 | + with: |
| 111 | + path: ${{ env.PREBUILT_DIR }} |
| 112 | + key: ios-runner-prebuilt-${{ steps.xcode.outputs.key }}-ios-${{ env.IOS_RUNTIME_VERSION }} |
| 113 | + |
| 114 | + - name: Report prebuild cache status |
| 115 | + run: | |
| 116 | + set -euo pipefail |
| 117 | + if [ "${{ steps.restore-prebuilt.outputs.cache-hit }}" = "true" ]; then |
| 118 | + echo "Reused existing prebuild cache." |
| 119 | + else |
| 120 | + echo "Created/updated prebuild cache." |
| 121 | + fi |
| 122 | +
|
| 123 | + - name: Cleanup simulator |
| 124 | + if: always() && steps.restore-prebuilt.outputs.cache-hit != 'true' |
| 125 | + run: | |
| 126 | + set -euo pipefail |
| 127 | + xcrun simctl delete "${{ steps.simulator.outputs.udid }}" || true |
0 commit comments