Skip to content

Commit 3679aaf

Browse files
committed
ci(ui): validate Android app on emulator
1 parent 89009b0 commit 3679aaf

1 file changed

Lines changed: 51 additions & 1 deletion

File tree

‎.github/workflows/ui-android-project-ci.yml‎

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
android-project:
4141
name: Generate and build Android debug APK
4242
runs-on: ubuntu-latest
43-
timeout-minutes: 30
43+
timeout-minutes: 45
4444

4545
steps:
4646
- name: Checkout ui repository
@@ -128,3 +128,53 @@ jobs:
128128
test -n "$apk"
129129
test -s "$apk"
130130
echo "Generated APK: $apk"
131+
echo "ANDROID_APK=$apk" >> "$GITHUB_ENV"
132+
133+
app_id="$(sed -n \
134+
"s/^[[:space:]]*applicationId '\([^']*\)'.*/\1/p" \
135+
android-project-ci/app/build.gradle)"
136+
activity_name="$(sed -n \
137+
's/.*android:name="\([^"]*\)".*/\1/p' \
138+
android-project-ci/app/src/main/AndroidManifest.xml | head -n 1)"
139+
test -n "$app_id"
140+
test -n "$activity_name"
141+
142+
if [[ "$activity_name" == .* ]]; then
143+
component="$app_id/$app_id$activity_name"
144+
else
145+
component="$app_id/$activity_name"
146+
fi
147+
148+
echo "ANDROID_APP_ID=$app_id" >> "$GITHUB_ENV"
149+
echo "ANDROID_COMPONENT=$component" >> "$GITHUB_ENV"
150+
151+
- name: Install and launch generated APK on Android Emulator
152+
uses: reactivecircus/android-emulator-runner@v2
153+
with:
154+
api-level: 35
155+
target: google_apis
156+
arch: x86_64
157+
profile: pixel_2
158+
disable-animations: true
159+
script: |
160+
set -euxo pipefail
161+
adb wait-for-device
162+
boot_completed="$(adb shell getprop sys.boot_completed | tr -d '\r')"
163+
test "$boot_completed" = "1"
164+
165+
adb install -r "$ANDROID_APK"
166+
adb shell am start -W -n "$ANDROID_COMPONENT" | tee activity-start.txt
167+
grep -Eq '^Status: ok$|^Warning: Activity not started' activity-start.txt
168+
169+
sleep 8
170+
171+
pid="$(adb shell pidof "$ANDROID_APP_ID" | tr -d '\r')"
172+
test -n "$pid"
173+
adb shell dumpsys activity activities | tr -d '\r' | \
174+
grep -F "$ANDROID_COMPONENT"
175+
176+
adb logcat -b crash -d -v brief > android-crash.log
177+
if grep -F "$ANDROID_APP_ID" android-crash.log; then
178+
cat android-crash.log
179+
exit 1
180+
fi

0 commit comments

Comments
 (0)