Skip to content

Commit 790789a

Browse files
authored
feat(ci): Add script to ensure runtime is loaded (#423)
1 parent 65de897 commit 790789a

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

.github/workflows/tests.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ jobs:
3333
- name: tvOS
3434
action: test-tvos
3535
logfiles: raw-*-tvos.log
36+
platform: tvOS
3637
- name: watchOS
3738
action: test-watchos
3839
logfiles: raw-*-watchos.log
40+
platform: watchOS
3941
- name: visionOS
4042
action: test-visionos
4143
logfiles: raw-*-visionos.log
44+
platform: visionOS
4245
steps:
4346
- name: Checkout the repository
4447
uses: actions/checkout@v6
@@ -47,6 +50,10 @@ jobs:
4750
with:
4851
xcode-version: "26.2"
4952

53+
- name: Ensuring required simulator runtimes are loaded
54+
if: matrix.build.platform != null
55+
run: scripts/ensure-runtime-loaded.sh --os-version 26.2 --platform ${{ matrix.build.platform }}
56+
5057
- name: Run Tests
5158
run: make ${{ matrix.build.action }}
5259

scripts/ensure-runtime-loaded.sh

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# Parse named arguments
5+
OS_VERSION=""
6+
PLATFORM=""
7+
8+
usage() {
9+
echo "Usage: $0 --os-version <os_version> --platform <platform>"
10+
echo " OS version: Version to ensure is loaded (e.g., 26.1 for beta, 16.4 for older iOS)"
11+
echo " Platform: Platform to ensure is loaded (e.g., iOS, tvOS, visionOS)"
12+
echo " Example: $0 --os-version 26.1 --platform iOS"
13+
echo " Example: $0 --os-version 16.4"
14+
exit 1
15+
}
16+
17+
while [[ $# -gt 0 ]]; do
18+
case $1 in
19+
--os-version)
20+
OS_VERSION="$2"
21+
shift 2
22+
;;
23+
--platform)
24+
PLATFORM="$2"
25+
shift 2
26+
;;
27+
*)
28+
echo "Unknown argument: $1"
29+
usage
30+
;;
31+
esac
32+
done
33+
34+
if [ -z "$OS_VERSION" ]; then
35+
echo "Error: --os-version argument is required"
36+
usage
37+
fi
38+
39+
if [ -z "$PLATFORM" ]; then
40+
echo "Error: --platform argument is required"
41+
usage
42+
fi
43+
44+
check_runtime_loaded() {
45+
echo "Checking if runtime $PLATFORM ($OS_VERSION) is loaded..."
46+
RUNTIMES=$(xcrun simctl list runtimes -v)
47+
48+
echo "Available runtimes:"
49+
echo "$RUNTIMES"
50+
51+
if echo "$RUNTIMES" | grep -qE "$PLATFORM $OS_VERSION" && ! echo "$RUNTIMES" | grep -qE "$PLATFORM $OS_VERSION.*unavailable" ; then
52+
echo "Runtime $OS_VERSION is loaded"
53+
exit 0
54+
fi
55+
echo "Runtime $OS_VERSION is not loaded"
56+
}
57+
58+
reload_runtime() {
59+
echo "Reloading runtime $PLATFORM ($OS_VERSION)..."
60+
61+
echo "Unloading CoreSimulator services volumes"
62+
for dir in /Library/Developer/CoreSimulator/Volumes/*; do
63+
echo "Ejecting $dir"
64+
sudo diskutil unmount force "$dir" || true
65+
done
66+
67+
echo "Killing CoreSimulator services to force reload..."
68+
sudo launchctl kill -9 system/com.apple.CoreSimulator.simdiskimaged || true
69+
sudo pkill -9 com.apple.CoreSimulator.CoreSimulatorService || true
70+
71+
echo "Killed all CoreSimulator services"
72+
}
73+
74+
wait_for_runtime() {
75+
echo "Wait for a runtime to be loaded"
76+
count=0
77+
MAX_ATTEMPTS=60 # 300 seconds (5 minutes) timeout
78+
while [ $count -lt $MAX_ATTEMPTS ]; do
79+
check_runtime_loaded
80+
echo "Waiting for runtime $OS_VERSION to be loaded... attempt $count"
81+
count=$((count + 1))
82+
sleep 5
83+
done
84+
echo "Exceeded maximum attempts ($MAX_ATTEMPTS) to check for runtime"
85+
}
86+
87+
check_runtime_loaded
88+
reload_runtime
89+
wait_for_runtime
90+
91+
echo "Runtime $PLATFORM ($OS_VERSION) is not loaded after reload attempts"
92+
exit 1

0 commit comments

Comments
 (0)