From 80f120bcde80b19d46164f3a6a4662b42d2e518f Mon Sep 17 00:00:00 2001 From: dprevost-perso-macos Date: Sun, 18 Oct 2026 18:56:19 -0400 Subject: [PATCH 1/2] ci: save the emulator state when the Android e2e job fails The Appium log does not show why the emulator screen stays black and taps and key events fail for the whole job (3 runs). Save a screenshot, logcat and dumpsys output in logs/device, which the job uploads on failure. --- .github/scripts/android-emulator-e2e.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.github/scripts/android-emulator-e2e.sh b/.github/scripts/android-emulator-e2e.sh index 05eb7a22..440bb6d8 100755 --- a/.github/scripts/android-emulator-e2e.sh +++ b/.github/scripts/android-emulator-e2e.sh @@ -16,7 +16,26 @@ mkdir -p logs appium --port 4723 --allow-insecure 'uiautomator2:chromedriver_autodownload' > logs/appium.log 2>&1 & APPIUM_PID=$! +# The Appium log does not show the state of the device, for example when the screen stays black and taps and key events +# fail for the whole job. Save it in logs/ (uploaded when the job fails) before the action stops the emulator. +save_device_state() { + echo "::group::Save the device state" + mkdir -p logs/device + timeout 30 adb exec-out screencap -p > logs/device/screen.png || true + timeout 60 adb logcat -d -v threadtime > logs/device/logcat.txt || true + local dumps=('window windows' 'activity activities' 'input' 'power' 'display' 'SurfaceFlinger') + for dump in "${dumps[@]}"; do + # shellcheck disable=SC2086 # split the service name from its arguments + timeout 30 adb shell dumpsys $dump > "logs/device/dumpsys-${dump%% *}.txt" 2>&1 || true + done + echo "::endgroup::" +} + cleanup() { + local status=$? + if [ "$status" -ne 0 ]; then + save_device_state + fi kill "$APPIUM_PID" 2> /dev/null || true # When the action stops the emulator, it waits for all emulator processes, but the emulator leaves its # crashpad_handler processes running, so the job hangs (ReactiveCircus/android-emulator-runner#385). From 36b8f890873237fdd0a018509e953a4275dd3767 Mon Sep 17 00:00:00 2001 From: dprevost-perso-macos Date: Sun, 18 Oct 2026 19:11:58 -0400 Subject: [PATCH 2/2] ci: do not let a failed mkdir of the device logs stop the cleanup --- .github/scripts/android-emulator-e2e.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/scripts/android-emulator-e2e.sh b/.github/scripts/android-emulator-e2e.sh index 440bb6d8..7147306f 100755 --- a/.github/scripts/android-emulator-e2e.sh +++ b/.github/scripts/android-emulator-e2e.sh @@ -19,8 +19,9 @@ APPIUM_PID=$! # The Appium log does not show the state of the device, for example when the screen stays black and taps and key events # fail for the whole job. Save it in logs/ (uploaded when the job fails) before the action stops the emulator. save_device_state() { + # A failure here must not stop the cleanup (set -e also applies in the EXIT trap) + mkdir -p logs/device || return 0 echo "::group::Save the device state" - mkdir -p logs/device timeout 30 adb exec-out screencap -p > logs/device/screen.png || true timeout 60 adb logcat -d -v threadtime > logs/device/logcat.txt || true local dumps=('window windows' 'activity activities' 'input' 'power' 'display' 'SurfaceFlinger')