Skip to content

Commit 49cbbc2

Browse files
committed
TODO/WIP/draft 👷 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 49cbbc2

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

.github/workflows/docker.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ on:
1212
jobs:
1313
docker:
1414
runs-on: ubuntu-latest
15+
# TODO: temporarily disabled for debugging purpose
16+
if: false
1517
steps:
1618
- uses: actions/checkout@v4
1719
- uses: docker/setup-buildx-action@v3

.github/workflows/push.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ jobs:
3434
name: Pytest [Python ${{ matrix.python-version }} | ${{ matrix.os }}]
3535
needs: flake8
3636
runs-on: ${{ matrix.os }}
37+
# TODO: temporarily disabled for debugging purpose
38+
if: false
3739
strategy:
3840
matrix:
3941
python-version: ['3.8', '3.9', '3.10', '3.11']
@@ -111,6 +113,8 @@ jobs:
111113
name: Build test APP [ ${{ matrix.runs_on }} | ${{ matrix.bootstrap.name }} ]
112114
needs: [flake8]
113115
runs-on: ${{ matrix.runs_on }}
116+
# TODO: temporarily disabled for debugging purpose
117+
if: false
114118
continue-on-error: true
115119
strategy:
116120
matrix:
@@ -162,10 +166,35 @@ jobs:
162166
name: ${{ matrix.runs_on }}-${{ matrix.bootstrap.name }}-artifacts
163167
path: dist
164168

169+
test_on_emulator:
170+
name: Run App on Emulator
171+
# TODO: keep it simple and go with ubuntu_build for a start
172+
# needs: [ubuntu_build, macos_build]
173+
needs: [ubuntu_build]
174+
runs-on: ubuntu-latest
175+
176+
steps:
177+
- name: Download Artifacts
178+
uses: actions/download-artifact@v5
179+
with:
180+
# TODO: keep it simple for now, but we may iterate over more artifact in the future
181+
name: ubuntu-latest-sdl2-artifacts
182+
path: dist/
183+
184+
- name: Setup and start Android Emulator
185+
# This is the key action to run the emulator
186+
uses: reactivecircus/android-emulator-runner@v2
187+
with:
188+
api-level: 30
189+
arch: x86_64
190+
script: ci/run_emulator_tests.sh
191+
165192
ubuntu_rebuild_updated_recipes:
166193
name: Test updated recipes for arch ${{ matrix.android_arch }} [ ubuntu-latest ]
167194
needs: [flake8]
168195
runs-on: ubuntu-latest
196+
# TODO: temporarily disabled for debugging purpose
197+
if: false
169198
continue-on-error: true
170199
strategy:
171200
matrix:
@@ -197,6 +226,8 @@ jobs:
197226
name: Test updated recipes for arch ${{ matrix.android_arch }} [ ${{ matrix.runs_on }} ]
198227
needs: [flake8]
199228
runs-on: ${{ matrix.runs_on }}
229+
# TODO: temporarily disabled for debugging purpose
230+
if: false
200231
continue-on-error: true
201232
strategy:
202233
matrix:

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ testapps-generic: virtualenv
4949

5050
testapps-with-numpy: testapps-with-numpy/debug/apk testapps-with-numpy/release/aab
5151

52+
# TODO: skipping some arch temporarily to save time while debugging
5253
# testapps-with-numpy/MODE/ARTIFACT
5354
testapps-with-numpy/%: virtualenv
5455
$(eval MODE := $(word 2, $(subst /, ,$@)))
@@ -57,7 +58,7 @@ testapps-with-numpy/%: virtualenv
5758
. $(ACTIVATE) && cd testapps/on_device_unit_tests/ && \
5859
python setup.py $(ARTIFACT) --$(MODE) --sdk-dir $(ANDROID_SDK_HOME) --ndk-dir $(ANDROID_NDK_HOME) \
5960
--requirements libffi,sdl2,pyjnius,kivy,python3,openssl,requests,urllib3,chardet,idna,sqlite3,setuptools,numpy \
60-
--arch=armeabi-v7a --arch=arm64-v8a --arch=x86_64 --arch=x86 \
61+
--arch=x86_64 \
6162
--permission "(name=android.permission.WRITE_EXTERNAL_STORAGE;maxSdkVersion=18)" --permission "(name=android.permission.INTERNET)"
6263

6364
testapps-with-scipy: testapps-with-scipy/debug/apk testapps-with-scipy/release/aab

ci/run_emulator_tests.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
APP_PACKAGE=$(aapt dump badging "${APK_FILE}" | awk -F"'" '/package: name=/{print $2}' | tee /dev/tty)
17+
APP_ACTIVITY=$(aapt dump badging "${APK_FILE}" | awk -F"'" '/launchable-activity/ {print $2}' | tee /dev/tty)
18+
19+
echo "Launching $APP_PACKAGE/$APP_ACTIVITY..."
20+
adb shell am start -n "$APP_PACKAGE/$APP_ACTIVITY" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
21+
22+
# Give the app time to start, run python, and log its status
23+
sleep 15
24+
25+
# Dump the logs and search for a success string
26+
adb logcat -d -s python:I *:S > app_logs.txt
27+
28+
echo "Checking app logs..."
29+
30+
if grep --extended-regexp --quiet "I python[ ]+: Initialized python" app_logs.txt && \
31+
grep --extended-regexp --quiet "I python[ ]+: Ran 14 tests in" app_logs.txt && \
32+
grep --extended-regexp --quiet "I python[ ]+: OK" app_logs.txt; then
33+
echo "✅ SUCCESS: App launched and all unit tests passed."
34+
else
35+
echo "❌ Failure: Python runtime initialization not detected or app crashed."
36+
echo "--- Full Logs ---"
37+
cat app_logs.txt
38+
echo "-----------------"
39+
exit 1
40+
fi

0 commit comments

Comments
 (0)