forked from ankidroid/Anki-Android
-
Notifications
You must be signed in to change notification settings - Fork 0
162 lines (145 loc) · 5.63 KB
/
tests_emulator.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: Emulator Tests
on:
workflow_dispatch:
pull_request:
branches:
- '**'
paths:
- '.github/workflows/**'
- 'AnkiDroid/**'
- 'api/**'
- 'lint-rules/**'
- 'annotations/**'
- '**/*.gradle'
- 'gradle/**'
push:
branches:
- main
- i18n_sync
- dependency-updates
- 'release**'
paths:
- '.github/workflows/**'
- 'AnkiDroid/**'
- 'api/**'
- 'lint-rules/**'
- 'annotations/**'
- '**/*.gradle'
- 'gradle/**'
jobs:
emulator_test:
name: Android Emulator Test
runs-on: macos-latest
timeout-minutes: 60
env:
EMULATOR_COMMAND: "-avd TestingAVD -noaudio -gpu swiftshader_indirect -camera-back none -no-snapshot -no-window -no-boot-anim -nojni -memory 2048 -timezone 'Europe/London' -cores 2"
EMULATOR_EXECUTABLE: qemu-system-x86_64-headless
steps:
- uses: styfle/cancel-workflow-action@0.9.1
with:
all_but_latest: true
- uses: actions/checkout@v3
with:
fetch-depth: 50
- name: Gradle Cache
uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}-v1
- name: Configure JDK 1.11
uses: actions/setup-java@v2
with:
distribution: "adopt"
java-version: "11" # ubuntu-latest is about to default to 11, force it everywhere
- name: Verify JDK11
# Default JDK varies depending on different runner flavors, make sure we are on 11
# Run a check that exits with error unless it is 11 version to future-proof against unexpected upgrades
run: java -fullversion 2>&1 | grep '11.0'
shell: bash
- name: Warm Gradle Cache
# This makes sure we fetch gradle network resources with a retry
uses: nick-invision/retry@v2
with:
timeout_minutes: 10
retry_wait_seconds: 60
max_attempts: 3
command: ./gradlew assembleDebug assembleAndroidTest robolectricSdkDownload
- name: Download Emulator Image
# This can fail on network request, wrap with retry
uses: nick-invision/retry@v2
with:
timeout_minutes: 10
retry_wait_seconds: 60
max_attempts: 3
command: echo "y" | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --install "system-images;android-30;google_apis;x86_64"
- name: Create Emulator
run: echo "no" | $ANDROID_HOME/cmdline-tools/latest/bin//avdmanager create avd --force --name TestingAVD --device "Nexus 5X" -k 'system-images;android-30;google_apis;x86_64' -g google_apis
# These Emulator start steps are the current best practice to do retries on multi-line commands with persistent (nohup) processes
- name: Start Android Emulator
id: emu1
timeout-minutes: 5
continue-on-error: true
run: |
echo "Starting emulator"
nohup $ANDROID_HOME/emulator/emulator $EMULATOR_COMMAND &
$ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 1; done'
- name: Start Android Emulator Retry 1
id: emu2
if: steps.emu1.outcome=='failure'
timeout-minutes: 5
continue-on-error: true
run: |
echo "Starting emulator, second attempt"
$ANDROID_HOME/platform-tools/adb devices
sudo killall -9 $EMULATOR_EXECUTABLE || true
sleep 2
nohup $ANDROID_HOME/emulator/emulator $EMULATOR_COMMAND &
$ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 1; done'
- name: Start Android Emulator Retry 2
id: emu3
if: steps.emu2.outcome=='failure'
timeout-minutes: 5
continue-on-error: true
run: |
echo "Starting emulator, third attempt"
$ANDROID_HOME/platform-tools/adb devices
sudo killall -9 $EMULATOR_EXECUTABLE || true
sleep 2
nohup $ANDROID_HOME/emulator/emulator $EMULATOR_COMMAND &
$ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 1; done'
- name: Emulator Status
if: always()
run: |
if ${{ steps.emu1.outcome=='success' || steps.emu2.outcome=='success' || steps.emu3.outcome=='success' }}; then
echo "Emulator Started"
else
exit 1
fi
- name: Emulator Test
timeout-minutes: 40
run: |
$ANDROID_HOME/platform-tools/adb devices
$ANDROID_HOME/platform-tools/adb shell settings put global window_animation_scale 0.0
$ANDROID_HOME/platform-tools/adb shell settings put global transition_animation_scale 0.0
$ANDROID_HOME/platform-tools/adb shell settings put global animator_duration_scale 0.0
nohup sh -c "$ANDROID_HOME/platform-tools/adb logcat '*:D' > adb-log.txt" &
./gradlew jacocoAndroidTestReport
shell: bash
- name: Compress Emulator Log
if: always()
run: gzip -9 adb-log.txt
shell: bash
- name: Upload Emulator Log
uses: actions/upload-artifact@v2
if: always()
with:
name: adb_logs
path: adb-log.txt.gz
- name: Submit Coverage
# This can fail on timeouts etc, wrap with retry
uses: nick-invision/retry@v2
with:
timeout_minutes: 10
retry_wait_seconds: 60
max_attempts: 3
command: curl https://codecov.io/bash -o codecov.sh && bash ./codecov.sh