From 9c3d6fc313d63b8f555fc65232ac15f798aede9a Mon Sep 17 00:00:00 2001 From: Vinay Gaba Date: Tue, 11 Jun 2024 22:42:40 -0700 Subject: [PATCH] Add workaround to prevent emulator from getting stuck on CI jobs (#393) * Add workaround to prevent emulator from getting stuck on CI jobs * Reference script in later step * Inverse order --- .github/workflows/android.yml | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 02e3e0bb..41f660d1 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -91,6 +91,28 @@ jobs: ~/.android/adb* key: avd-${{ matrix.api-level }} + - name: Prepare script to run + id: script + env: + SCRIPT: | + # Workaround for https://github.com/ReactiveCircus/android-emulator-runner/issues/373 + pre_terminate_crashpad() { + # For some reason pgrep/pkill sees only crashpad_handle, not crashpad_handler, + # but it's definitely called ${ANDROID_HOME}/emulator/crashpad_handler. + + # Best-effort gracefully terminate all crashpad_handler processes. + pkill --exact --echo --signal SIGTERM crashpad_handle || return + sleep 10 + pkill --exact --echo --signal SIGKILL crashpad_handle || return + } + trap pre_terminate_crashpad EXIT + + ${{ inputs.script }} + run: | + script_file="${RUNNER_TEMP}/reactivecircus-android-emulator-runner-prepared-script.sh" + echo "${SCRIPT}" > "${script_file}" + echo "file=${script_file}" >> "${GITHUB_OUTPUT}" + - name: Create AVD and generate snapshot for caching if: steps.avd-cache.outputs.cache-hit != 'true' uses: reactivecircus/android-emulator-runner@v2 @@ -108,7 +130,11 @@ jobs: force-avd-creation: false emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none disable-animations: true - script: ./gradlew connectedCheck --no-daemon --stacktrace + script: | + adb devices -l + bash --noprofile --norc -eo pipefail "${{ steps.script.outputs.file }}" + ./gradlew connectedCheck --no-daemon --stacktrace + - name: Start emulator and run UI Tests w/ KSP uses: reactivecircus/android-emulator-runner@v2 @@ -117,7 +143,10 @@ jobs: force-avd-creation: false emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none disable-animations: true - script: ./gradlew connectedCheck --no-daemon --stacktrace -PuseKsp=true + script: | + adb devices -l + bash --noprofile --norc -eo pipefail "${{ steps.script.outputs.file }}" + ./gradlew connectedCheck --no-daemon --stacktrace -PuseKsp=true - name: Run Screenshot Tests uses: reactivecircus/android-emulator-runner@v2