Skip to content

Commit c02cf78

Browse files
authored
Merge pull request #3221 from kivy/feature/ci_emulator_runtime_tests
👷 Runtime test the app from the CI
2 parents 40bbdac + ee32640 commit c02cf78

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

.github/workflows/push.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ jobs:
8080
target: testapps-qt
8181
steps:
8282
- name: Checkout python-for-android
83-
uses: actions/checkout@v4
83+
uses: actions/checkout@v5
8484
- name: Build python-for-android docker image
8585
run: |
8686
docker build --tag=kivy/python-for-android .
@@ -164,6 +164,26 @@ jobs:
164164
name: ${{ matrix.runs_on }}-${{ matrix.bootstrap.name }}-artifacts
165165
path: dist
166166

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