From 92f10531d0d1242926d3abafa22de1cf819beb58 Mon Sep 17 00:00:00 2001 From: Maurice Date: Sat, 7 Nov 2026 13:36:37 +0100 Subject: [PATCH] ci(native): capture the watch screens one watch at a time, retried, and complete Each launch is terminated first, retried after 2, 5 and 10 seconds when the simulator refuses it, and captured once the app reports the screen drawn instead of after a fixed wait. The job fails when any expected image is missing. --- .github/workflows/native.yml | 2 +- client/ios/App/TREKWatch/DemoMode.swift | 13 ++++ client/ios/App/TREKWatch/TREKWatchApp.swift | 5 +- client/ios/scripts/watch-screens.sh | 70 +++++++++++++++------ 4 files changed, 68 insertions(+), 22 deletions(-) diff --git a/.github/workflows/native.yml b/.github/workflows/native.yml index 6a7c387ed..6c6871e7f 100644 --- a/.github/workflows/native.yml +++ b/.github/workflows/native.yml @@ -195,7 +195,7 @@ jobs: # language, and the complications, as PNGs to look at without a watch. watch-screens: runs-on: macos-15 - timeout-minutes: 60 + timeout-minutes: 90 steps: - uses: actions/checkout@v6 diff --git a/client/ios/App/TREKWatch/DemoMode.swift b/client/ios/App/TREKWatch/DemoMode.swift index 52a9723a3..0970fbb2c 100644 --- a/client/ios/App/TREKWatch/DemoMode.swift +++ b/client/ios/App/TREKWatch/DemoMode.swift @@ -9,6 +9,8 @@ import Foundation /// trip, days, packing, todos, lists, countdown, empty, /// nosync, faces /// -TrekScenario running, travelday or upcoming (default by screen) +/// -TrekReady once the screen has drawn, writes Documents/ready- +/// in the app's container, which the script waits for /// -TrekNow the time the screens think it is; without it the /// real time, which the capture script moves to the /// hour it wants with the app's time zone (TZ), so the @@ -23,6 +25,17 @@ enum DemoMode { value(after: "-TrekDemo").flatMap(Screen.init(rawValue:)) } + /// Tells the capture script the screen is up: a moment after it appeared, + /// so the navigation to it and the first layout have settled. + static func signalReady() { + guard let token = value(after: "-TrekReady"), + let documents = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else { return } + DispatchQueue.main.asyncAfter(deadline: .now() + 1.2) { + try? FileManager.default.createDirectory(at: documents, withIntermediateDirectories: true) + try? Data().write(to: documents.appendingPathComponent("ready-\(token)")) + } + } + @MainActor static func start() { guard let screen else { return } diff --git a/client/ios/App/TREKWatch/TREKWatchApp.swift b/client/ios/App/TREKWatch/TREKWatchApp.swift index 62594633b..21cde2f06 100644 --- a/client/ios/App/TREKWatch/TREKWatchApp.swift +++ b/client/ios/App/TREKWatch/TREKWatchApp.swift @@ -64,7 +64,10 @@ struct RootView: View { } .environment(\.trekNow, now) } - .onAppear(perform: openDemoScreen) + .onAppear { + openDemoScreen() + DemoMode.signalReady() + } .onChange(of: scenePhase) { _, phase in if phase == .active && !model.isDemo { WatchLink.shared.requestRefresh() } } diff --git a/client/ios/scripts/watch-screens.sh b/client/ios/scripts/watch-screens.sh index b43df516c..c34a9e44c 100644 --- a/client/ios/scripts/watch-screens.sh +++ b/client/ios/scripts/watch-screens.sh @@ -49,15 +49,37 @@ zone_for() { if [ "$offset" -ge 0 ]; then echo "Etc/GMT-$offset"; else echo "Etc/GMT+$(( -offset ))"; fi } -# shot +# Waits for the ready file the app writes once the screen has drawn (DemoMode.signalReady). +wait_ready() { + local udid=$1 token=$2 container + for _ in $(seq 1 40); do + container=$(xcrun simctl get_app_container "$udid" "$BUNDLE" data 2>/dev/null || true) + [ -n "$container" ] && [ -f "$container/Documents/ready-$token" ] && return 0 + sleep 0.25 + done + return 1 +} + +TOKEN=0 +# shot : one launch, retried +# after 2, 5 and 10 seconds when the simulator refuses it. shot() { local udid=$1 file=$2 screen=$3 scenario=$4 hour=$5 lang=$6 - local locale=${lang//-/_} - SIMCTL_CHILD_TZ=$(zone_for "$hour") xcrun simctl launch --terminate-running-process "$udid" "$BUNDLE" \ - -AppleLanguages "($lang)" -AppleLocale "$locale" -TrekDemo "$screen" -TrekScenario "$scenario" >/dev/null \ - || { echo "could not launch $file"; return 0; } - case "$screen" in place) sleep 10 ;; *) sleep 4 ;; esac - xcrun simctl io "$udid" screenshot --type=png "$file" >/dev/null 2>&1 || echo "could not capture $file" + local locale=${lang//-/_} attempt + for attempt in 0 2 5 10; do + [ "$attempt" -gt 0 ] && { echo "retrying $(basename "$file") in ${attempt}s"; sleep "$attempt"; } + TOKEN=$((TOKEN + 1)) + xcrun simctl terminate "$udid" "$BUNDLE" >/dev/null 2>&1 || true + sleep 0.5 + SIMCTL_CHILD_TZ=$(zone_for "$hour") xcrun simctl launch "$udid" "$BUNDLE" \ + -AppleLanguages "($lang)" -AppleLocale "$locale" -TrekDemo "$screen" -TrekScenario "$scenario" \ + -TrekReady "$TOKEN" >/dev/null 2>&1 || continue + wait_ready "$udid" "$TOKEN" || continue + # The map's tiles come over the network after the screen is up. + [ "$screen" = place ] && sleep 6 + xcrun simctl io "$udid" screenshot --type=png "$file" >/dev/null 2>&1 && return 0 + done + echo "gave up on $(basename "$file")" } # name screen scenario hour: every screen, and the states a screen has. @@ -85,12 +107,13 @@ faces faces running 13 MAIN="today booking countdown trip lists packing day" LANGS="ar az ca cs de el en es et fr he hu id it ja ko nl pl pt-BR ru sk sv th tr uk vi zh-Hans zh-Hant" +EXPECTED=() run() { - local size=$1 name=$2 udid - udid=$(boot "$name" | tail -1) + local size=$1 udid=$2 lang shotname screen scenario hour for lang in en de ru; do while read -r shotname screen scenario hour; do [ -n "$shotname" ] || continue + EXPECTED+=("$size-$lang-$shotname.png") shot "$udid" "$OUT/$size-$lang-$shotname.png" "$screen" "$scenario" "$hour" "$lang" done <<< "$SHOTS" done @@ -99,21 +122,28 @@ run() { case "$lang" in en|de|ru) continue ;; esac while read -r shotname screen scenario hour; do [ -n "$shotname" ] || continue - case " $MAIN " in *" $shotname "*) shot "$udid" "$OUT/$size-$lang-$shotname.png" "$screen" "$scenario" "$hour" "$lang" ;; esac + case " $MAIN " in + *" $shotname "*) + EXPECTED+=("$size-$lang-$shotname.png") + shot "$udid" "$OUT/$size-$lang-$shotname.png" "$screen" "$scenario" "$hour" "$lang" + ;; + esac done <<< "$SHOTS" done fi xcrun simctl shutdown "$udid" || true } -run large "$LARGE" & -large=$! -run medium "$MEDIUM" & -medium=$! -run small "$SMALL" & -small=$! -wait "$large" -wait "$medium" -wait "$small" +# One watch at a time: launches on several booted simulators at once is what +# makes SpringBoard refuse them ("Scene update failed"). +run large "$(boot "$LARGE" | tail -1)" +run medium "$(boot "$MEDIUM" | tail -1)" +run small "$(boot "$SMALL" | tail -1)" printf '%s\n' "large: $LARGE" "medium: $MEDIUM" "small: $SMALL" > "$OUT/devices.txt" -ls "$OUT" | wc -l + +missing=0 +for file in "${EXPECTED[@]}"; do + [ -s "$OUT/$file" ] || { echo "missing: $file"; missing=$((missing + 1)); } +done +echo "${#EXPECTED[@]} expected, $missing missing" +[ "$missing" -eq 0 ]