Skip to content

Commit a33e392

Browse files
committed
👷 Runtime test the app from the CI
Leverage `reactivecircus/android-emulator-runner` to run the testapps artifact on an emulator and check the ADB logs. We're currently checking for the following pattern from the logcat output: - "I python: Initialized python" - "I python: Ran 14 tests in" - "I python: OK" Note that we're keeping things simple for the first iteration and we only run the `ubuntu-latest-sdl2-artifacts` artifact. In the future we may want to test the different bootstraps, build host and even updated recipes dynamically.
1 parent 5aa9732 commit a33e392

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

.github/workflows/push.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,26 @@ jobs:
162162
name: ${{ matrix.runs_on }}-${{ matrix.bootstrap.name }}-artifacts
163163
path: dist
164164

165+
test_on_emulator:
166+
name: Run App on Emulator
167+
needs: ubuntu_build
168+
runs-on: ubuntu-latest
169+
170+
steps:
171+
- uses: actions/checkout@v4
172+
- name: Download Artifacts
173+
uses: actions/download-artifact@v5
174+
with:
175+
name: ubuntu-latest-sdl2-artifacts
176+
path: dist/
177+
178+
- name: Setup and start Android Emulator
179+
uses: reactivecircus/android-emulator-runner@v2
180+
with:
181+
api-level: 30
182+
arch: x86_64
183+
script: ci/run_emulator_tests.sh
184+
165185
ubuntu_rebuild_updated_recipes:
166186
name: Test updated recipes for arch ${{ matrix.android_arch }} [ ubuntu-latest ]
167187
needs: [flake8]

ci/run_emulator_tests.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
set -euxo pipefail
3+
4+
# Find the built APK file
5+
APK_FILE=$(find dist -name "*.apk" -print -quit)
6+
7+
if [ -z "$APK_FILE" ]; then
8+
echo "Error: No APK file found in dist/"
9+
exit 1
10+
fi
11+
12+
echo "Installing $APK_FILE..."
13+
adb install "$APK_FILE"
14+
15+
# Extract package and activity names
16+
AAPT2_PATH=$(find ${ANDROID_HOME}/build-tools/ -name aapt2 | sort -r | head -n 1)
17+
APP_PACKAGE=$(${AAPT2_PATH} dump badging "${APK_FILE}" | awk -F"'" '/package: name=/{print $2}')
18+
APP_ACTIVITY=$(${AAPT2_PATH} dump badging "${APK_FILE}" | awk -F"'" '/launchable-activity/ {print $2}')
19+
20+
echo "Launching $APP_PACKAGE/$APP_ACTIVITY..."
21+
adb shell am start -n "$APP_PACKAGE/$APP_ACTIVITY" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
22+
23+
# Poll for test completion with timeout
24+
MAX_WAIT=300
25+
POLL_INTERVAL=5
26+
elapsed=0
27+
28+
echo "Waiting for tests to complete (max ${MAX_WAIT}s)..."
29+
30+
while [ $elapsed -lt $MAX_WAIT ]; do
31+
# Dump current logs
32+
adb logcat -d -s python:I *:S > app_logs.txt
33+
34+
# Check if all success patterns are present
35+
if grep --extended-regexp --quiet "I python[ ]+: Initialized python" app_logs.txt && \
36+
grep --extended-regexp --quiet "I python[ ]+: Ran 14 tests in" app_logs.txt && \
37+
grep --extended-regexp --quiet "I python[ ]+: OK" app_logs.txt; then
38+
echo "✅ SUCCESS: App launched and all unit tests passed in ${elapsed}s."
39+
exit 0
40+
fi
41+
42+
# Check for early failure indicators
43+
if grep --extended-regexp --quiet "I python[ ]+: FAILED" app_logs.txt; then
44+
echo "❌ FAILURE: Tests failed after ${elapsed}s."
45+
echo "--- Full Logs ---"
46+
cat app_logs.txt
47+
echo "-----------------"
48+
exit 1
49+
fi
50+
51+
sleep $POLL_INTERVAL
52+
elapsed=$((elapsed + POLL_INTERVAL))
53+
echo "Still waiting... (${elapsed}s elapsed)"
54+
done
55+
56+
echo "❌ TIMEOUT: Tests did not complete within ${MAX_WAIT}s."
57+
echo "--- Full Logs ---"
58+
cat app_logs.txt
59+
echo "-----------------"
60+
exit 1

0 commit comments

Comments
 (0)