-
-
Notifications
You must be signed in to change notification settings - Fork 0
180 lines (161 loc) · 5.88 KB
/
full_ci.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# FULL CI is currently disabled as there are no tests in androidTest (thanks to robolectric)
# if you need instrumented tests, uncomment '- main' here and comment it in short_ci
# Action to automatically (and magically) run unit and instrumentation tests on the project
# and publish the results as a comment on the PR
# main action used to make this work are:
# - eskatos/gradle-command-action@v1
# - reactivecircus/android-emulator-runner@v2
# - EnricoMi/publish-unit-test-result-action@v1
name: CI (Unit + Instrumentation Tests)
on:
# run on pull request to main (release) & develop (feature merge)
#pull_request:
# branches:
#- main
#- develop
# and manual run
workflow_dispatch:
jobs:
# run unit tests
unit_test:
name: Unit Tests
runs-on: ubuntu-latest
timeout-minutes: 10
env:
JAVA_TOOL_OPTIONS: -Xmx5g -XX:+UseParallelGC
steps:
# setup env
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: 11
- run: |
mkdir -p ~/.gradle
cp .github/gh-gradle.properties ~/.gradle/gradle.properties
chmod +x ./gradlew
# run gradle unit test task
- name: Run unit tests
uses: eskatos/gradle-command-action@v1
with:
arguments: testDebugUnitTest
wrapper-cache-enabled: true
dependencies-cache-enabled: true
configuration-cache-enabled: true
# print contents of artifact dir
- run: ls ./app/build/test-results/testDebugUnitTest
# upload results
- name: Upload Test Results
uses: actions/upload-artifact@v4
with:
name: unit-test-results
path: ./app/build/test-results/testDebugUnitTest/*.xml
# run instrumentation test
instrumentation_test:
name: Instrumentation Tests
needs: unit_test
runs-on: macos-latest
timeout-minutes: 20
env:
JAVA_TOOL_OPTIONS: -Xmx5g -XX:+UseParallelGC
strategy:
fail-fast: true
matrix:
# keep this list short, with only key versions in it
# the instrumentation tests run on macOS, which consumes 10x the minutes a linux job would
# making these test rather costly
api-level: [23, 26, 30]
steps:
# setup env
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: 11
- run: |
mkdir -p ~/.gradle
cp .github/gh-gradle.properties ~/.gradle/gradle.properties
chmod +x ./gradlew
# get avd target (API 30+ only has google api images)
- name: Get AVD Target
id: avd-target
run: echo "::set-output name=target::$(if [ ${{ matrix.api-level }} -ge 30 ]; then echo google_apis; else echo default; fi)"
# setup caches (this is based on the example given at https://github.com/marketplace/actions/android-emulator-runner#usage)
- name: Gradle cache
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('**/buildSrc/**/*.kt') }}
- name: AVD cache
uses: actions/cache@v4
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-${{ matrix.api-level }}
# generate avd for cache
- name: create AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
target: ${{ steps.avd-target.outputs.target }}
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
script: echo "Generated AVD snapshot for caching."
# run tests
- name: run tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
target: ${{ steps.avd-target.outputs.target }}
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
script: ./gradlew connectedCheck
# print contents of artifact dir
- run: ls ./app/build/outputs/androidTest-results/connected
# upload results
- name: Upload Test Results
uses: actions/upload-artifact@v4
with:
name: instrumentation-test-results
path: ./app/build/outputs/androidTest-results/connected/*.xml
# publish test results (even if tests failed)
publish_results:
name: Publish Test Results
needs: [unit_test, instrumentation_test]
if: always()
runs-on: ubuntu-latest
steps:
# download unit test results
- run: mkdir ./results/
- name: Download Unit Test Results
uses: actions/download-artifact@v4
with:
name: unit-test-results
path: ./results/
# print contents of artifact dir
- run: ls ./results
# download instrumentation test results
- name: Download Instrumentation Test Results
uses: actions/download-artifact@v4
with:
name: instrumentation-test-results
path: ./results/
# print contents of artifact dir
- run: ls ./results
# publish results
- name: Publish test results
uses: EnricoMi/publish-unit-test-result-action@v1
if: always()
with:
check_name: Test Results (Instrumented + Unit Tests)
report_individual_runs: true
github_token: ${{ secrets.GITHUB_TOKEN }}
files: |
./results/*.xml