Skip to content

Commit eea7eb6

Browse files
ci: prepare ios simulator before running
1 parent 3d5cc9a commit eea7eb6

2 files changed

Lines changed: 87 additions & 30 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
if [[ -z "${IOS_SIMULATOR_DEVICE:-}" ]]; then
6+
echo "IOS_SIMULATOR_DEVICE must be set."
7+
exit 1
8+
fi
9+
10+
echo "--- Available simulators (diagnostic) ---"
11+
xcrun simctl list
12+
13+
SIMULATOR_UDID="$(python3 - <<'PY'
14+
import json
15+
import os
16+
import re
17+
import subprocess
18+
import sys
19+
20+
target_name = os.environ["IOS_SIMULATOR_DEVICE"]
21+
raw = subprocess.check_output(
22+
["xcrun", "simctl", "list", "devices", "available", "-j"],
23+
text=True,
24+
)
25+
devices_by_runtime = json.loads(raw)["devices"]
26+
pattern = re.compile(r"com\.apple\.CoreSimulator\.SimRuntime\.iOS-(\d+)(?:-(\d+))?")
27+
28+
candidates = []
29+
for runtime_key, devices in devices_by_runtime.items():
30+
match = pattern.fullmatch(runtime_key)
31+
if not match:
32+
continue
33+
34+
version = (int(match.group(1)), int(match.group(2) or 0))
35+
for device in devices:
36+
if device.get("isAvailable") and device.get("name") == target_name:
37+
candidates.append((version, device["udid"]))
38+
39+
if not candidates:
40+
sys.exit(f"No available simulator found for {target_name} in installed iOS runtimes.")
41+
42+
candidates.sort(reverse=True)
43+
print(candidates[0][1])
44+
PY
45+
)"
46+
47+
if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
48+
echo "udid=$SIMULATOR_UDID" >> "$GITHUB_OUTPUT"
49+
else
50+
echo "Resolved simulator UDID: $SIMULATOR_UDID"
51+
fi
52+
53+
if ! boot_output="$(xcrun simctl boot "$SIMULATOR_UDID" 2>&1)"; then
54+
if [[ "$boot_output" != *"Unable to boot device in current state: Booted"* ]]; then
55+
echo "$boot_output"
56+
exit 1
57+
fi
58+
fi
59+
60+
xcrun simctl bootstatus "$SIMULATOR_UDID" -b

.github/workflows/swiftui-auth.yml

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ on:
2323
permissions:
2424
contents: read
2525

26+
env:
27+
XCODE_VERSION: latest-stable
28+
IOS_SIMULATOR_DEVICE: iPhone 17 Pro
29+
2630
jobs:
2731
format-check:
2832
name: Swift Format Check
@@ -37,7 +41,7 @@ jobs:
3741
- name: Check Swift formatting
3842
run: bash lint-swift.sh
3943

40-
# Package Unit Tests (standalone, no emulator needed)
44+
# Package Unit Tests (simulator-backed)
4145
unit-tests:
4246
name: Package Unit Tests
4347
runs-on: macos-26
@@ -48,22 +52,20 @@ jobs:
4852
- name: Install xcpretty
4953
run: gem install xcpretty
5054

51-
- uses: maxim-lobanov/setup-xcode@v1
55+
- uses: maxim-lobanov/setup-xcode@9a237eadec58c1a4e3c19e27a1f6e2a3dce0a919
5256
with:
53-
xcode-version: latest-stable
54-
- name: Workaround Simulator Availability issues
55-
run: |
56-
# Just listing the installed simulators fixes availability inconsistency
57-
# Without this, runs fail *intermittently* with build target not available because simulators not available
58-
# See https://github.com/actions/runner-images/issues/13459#issuecomment-3681674842
59-
xcrun simctl list
57+
xcode-version: ${{ env.XCODE_VERSION }}
58+
59+
- name: Prepare iOS Simulator
60+
id: prepare-simulator
61+
run: ./.github/workflows/scripts/prepare-ios-simulator.sh
6062

6163
- name: Run FirebaseSwiftUI Package Unit Tests
6264
run: |
6365
set -o pipefail
6466
xcodebuild test \
6567
-scheme FirebaseUI-Package \
66-
-destination 'platform=iOS Simulator,OS=26.4,name=iPhone 17 Pro' \
68+
-destination "id=${{ steps.prepare-simulator.outputs.udid }}" \
6769
-enableCodeCoverage YES \
6870
-resultBundlePath FirebaseSwiftUIPackageTests.xcresult | tee FirebaseSwiftUIPackageTests.log | xcpretty --test --color --simple
6971
@@ -111,24 +113,21 @@ jobs:
111113
- name: Install xcpretty
112114
run: gem install xcpretty
113115

114-
- uses: maxim-lobanov/setup-xcode@v1
116+
- uses: maxim-lobanov/setup-xcode@9a237eadec58c1a4e3c19e27a1f6e2a3dce0a919
115117
with:
116-
xcode-version: latest-stable
118+
xcode-version: ${{ env.XCODE_VERSION }}
117119

118-
- name: Workaround Simulator Availability issues
119-
run: |
120-
# Just listing the installed simulators fixes availability inconsistency
121-
# Without this, runs fail *intermittently* with build target not available because simulators not available
122-
# See https://github.com/actions/runner-images/issues/13459#issuecomment-3681674842
123-
xcrun simctl list
120+
- name: Prepare iOS Simulator
121+
id: prepare-simulator
122+
run: ./.github/workflows/scripts/prepare-ios-simulator.sh
124123

125124
- name: Build for Integration Tests
126125
run: |
127126
cd ./e2eTest/FirebaseSwiftUIExample
128127
set -o pipefail
129128
xcodebuild build-for-testing \
130129
-scheme FirebaseSwiftUIExampleTests \
131-
-destination 'platform=iOS Simulator,OS=26.4,name=iPhone 17 Pro' \
130+
-destination "id=${{ steps.prepare-simulator.outputs.udid }}" \
132131
-enableCodeCoverage YES | xcpretty --color --simple
133132
134133
- name: Run Integration Tests
@@ -137,7 +136,8 @@ jobs:
137136
set -o pipefail
138137
xcodebuild test-without-building \
139138
-scheme FirebaseSwiftUIExampleTests \
140-
-destination 'platform=iOS Simulator,OS=26.4,name=iPhone 17 Pro' \
139+
-destination "id=${{ steps.prepare-simulator.outputs.udid }}" \
140+
-parallel-testing-enabled NO \
141141
-enableCodeCoverage YES \
142142
-resultBundlePath FirebaseSwiftUIExampleTests.xcresult | tee FirebaseSwiftUIExampleTests.log | xcpretty --test --color --simple
143143
@@ -185,24 +185,21 @@ jobs:
185185
- name: Install xcpretty
186186
run: gem install xcpretty
187187

188-
- uses: maxim-lobanov/setup-xcode@v1
188+
- uses: maxim-lobanov/setup-xcode@9a237eadec58c1a4e3c19e27a1f6e2a3dce0a919
189189
with:
190-
xcode-version: latest-stable
190+
xcode-version: ${{ env.XCODE_VERSION }}
191191

192-
- name: Workaround Simulator Availability issues
193-
run: |
194-
# Just listing the installed simulators fixes availability inconsistency
195-
# Without this, runs fail *intermittently* with build target not available because simulators not available
196-
# See https://github.com/actions/runner-images/issues/13459#issuecomment-3681674842
197-
xcrun simctl list
192+
- name: Prepare iOS Simulator
193+
id: prepare-simulator
194+
run: ./.github/workflows/scripts/prepare-ios-simulator.sh
198195

199196
- name: Build for UI Tests
200197
run: |
201198
cd ./e2eTest/FirebaseSwiftUIExample
202199
set -o pipefail
203200
xcodebuild build-for-testing \
204201
-scheme FirebaseSwiftUIExampleUITests \
205-
-destination 'platform=iOS Simulator,OS=26.4,name=iPhone 17 Pro' \
202+
-destination "id=${{ steps.prepare-simulator.outputs.udid }}" \
206203
-enableCodeCoverage YES | xcpretty --color --simple
207204
208205
- name: Run UI Tests
@@ -211,7 +208,7 @@ jobs:
211208
set -o pipefail
212209
xcodebuild test-without-building \
213210
-scheme FirebaseSwiftUIExampleUITests \
214-
-destination 'platform=iOS Simulator,OS=26.4,name=iPhone 17 Pro' \
211+
-destination "id=${{ steps.prepare-simulator.outputs.udid }}" \
215212
-parallel-testing-enabled NO \
216213
-enableCodeCoverage YES \
217214
-resultBundlePath FirebaseSwiftUIExampleUITests.xcresult | tee FirebaseSwiftUIExampleUITests.log | xcpretty --test --color --simple

0 commit comments

Comments
 (0)