diff --git a/.github/actions/androidapp-road-test/action.yml b/.github/actions/androidapp-road-test/action.yml index e4f374d86..dc9cc8cff 100644 --- a/.github/actions/androidapp-road-test/action.yml +++ b/.github/actions/androidapp-road-test/action.yml @@ -398,7 +398,7 @@ runs: echo "==> Starting Detox tests at $(date -u +%H:%M:%S)" bash apps/brownfield-example-shared-tests/scripts/prepare-android-emulator-for-detox.sh cd apps/AndroidApp - yarn "$ANDROIDAPP_E2E_TEST_SCRIPT" + bash apps/brownfield-example-shared-tests/scripts/run-with-android-logcat.sh apps/AndroidApp/e2e-artifacts/logcat-full.txt yarn "$ANDROIDAPP_E2E_TEST_SCRIPT" env: ANDROIDAPP_E2E_TEST_SCRIPT: ${{ env.ANDROIDAPP_E2E_TEST_SCRIPT }} diff --git a/apps/brownfield-example-shared-tests/scripts/run-with-android-logcat.sh b/apps/brownfield-example-shared-tests/scripts/run-with-android-logcat.sh new file mode 100755 index 000000000..36f71528e --- /dev/null +++ b/apps/brownfield-example-shared-tests/scripts/run-with-android-logcat.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# Runs a command while recording the full device logcat host-side (CI + local). +# Detox's own logcat artifact is filtered to the app pid and recorded on-device +# with `logcat -f`, which is killed before it flushes, so it drops the last few +# seconds before a failure and never contains system_server lines (ANRs). +# +# Usage: run-with-android-logcat.sh [args...] +set -uo pipefail + +if (( $# < 2 )); then + echo "usage: $0 [args...]" >&2 + exit 2 +fi + +LOGCAT_FILE="$1" +shift + +ADB=(adb) +if [[ -n "${ANDROID_SERIAL:-}" ]]; then + ADB=(adb -s "${ANDROID_SERIAL}") +fi + +mkdir -p "$(dirname "${LOGCAT_FILE}")" +"${ADB[@]}" logcat -v threadtime -b main,system,crash >"${LOGCAT_FILE}" 2>&1 & +logcat_pid=$! +echo "==> Recording device logcat to ${LOGCAT_FILE} (pid ${logcat_pid})" + +"$@" +status=$? + +kill "${logcat_pid}" 2>/dev/null || true +wait "${logcat_pid}" 2>/dev/null || true + +exit "${status}"