-
Notifications
You must be signed in to change notification settings - Fork 352
281 lines (251 loc) · 8.63 KB
/
android-app.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
---
name: Android - Build and test
on:
pull_request:
paths:
- '**'
- '!.github/workflows/**'
- '.github/workflows/android-app.yml'
- '!audits/**'
- '!ci/**'
- '!dist-assets/**'
- '!docs/**'
- '!graphics/**'
- '!gui/**'
- '!ios/**'
- '!scripts/**'
- '!windows/**'
- '!**/**.md'
workflow_dispatch:
inputs:
override_container_image:
description: Override container image
type: string
required: false
# Build if main is updated to ensure up-to-date caches are available
push:
branches: [main]
jobs:
prepare:
name: Prepare
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Use custom container image if specified
if: ${{ github.event.inputs.override_container_image != '' }}
run: echo "inner_container_image=${{ github.event.inputs.override_container_image }}"
>> $GITHUB_ENV
- name: Use default container image and resolve digest
if: ${{ github.event.inputs.override_container_image == '' }}
run: |
echo "inner_container_image=$(cat ./building/android-container-image.txt)" >> $GITHUB_ENV
outputs:
container_image: ${{ env.inner_container_image }}
generate-relay-list:
name: Generate relay list
needs: prepare
runs-on: ubuntu-latest
container:
image: ${{ needs.prepare.outputs.container_image }}
steps:
# Fix for HOME path overridden by GH runners when building in containers, see:
# https://github.com/actions/runner/issues/863
- name: Fix HOME path
run: echo "HOME=/root" >> $GITHUB_ENV
- name: Get date
id: get-date
shell: bash
run: |
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
- name: Cache
uses: actions/cache@v3
id: cache-relay-list
with:
path: build/relays.json
key: relay-list-${{ steps.get-date.outputs.date }}
- name: Checkout repository
if: steps.cache-relay-list.outputs.cache-hit != 'true'
uses: actions/checkout@v3
- name: Generate
if: steps.cache-relay-list.outputs.cache-hit != 'true'
env:
RUSTFLAGS: --deny warnings
run: |
mkdir -p build
cargo run --bin relay_list > build/relays.json
- name: Upload
uses: actions/upload-artifact@v3
with:
name: relay-list
path: build/relays.json
if-no-files-found: error
retention-days: 1
build-native:
name: Build native
needs: prepare
runs-on: ubuntu-latest
container:
image: "${{ needs.prepare.outputs.container_image }}"
strategy:
matrix:
include:
- arch: "x86_64"
abi: "x86_64"
target: "x86_64-linux-android"
- arch: "i686"
abi: "x86"
target: "i686-linux-android"
- arch: "aarch64"
abi: "arm64-v8a"
target: "aarch64-linux-android"
- arch: "armv7"
abi: "armeabi-v7a"
target: "armv7-linux-androideabi"
steps:
# Fix for HOME path overridden by GH runners when building in containers, see:
# https://github.com/actions/runner/issues/863
- name: Fix HOME path
run: echo "HOME=/root" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v3
- name: Calculate native lib cache hash
id: native-lib-cache-hash
shell: bash
run: |
git config --global --add safe.directory $(pwd)
non_android_hash="$(git grep --cached -l '' -- ':!android/' \
| xargs -d '\n' sha1sum \
| sha1sum \
| awk '{print $1}')"
echo "native_lib_hash=$non_android_hash" >> $GITHUB_OUTPUT
- name: Cache native libraries
uses: actions/cache@v3
id: cache-native-libs
env:
cache_hash: ${{ steps.native-lib-cache-hash.outputs.native_lib_hash }}
with:
path: ./android/app/build/extraJni
key: android-native-libs-${{ runner.os }}-${{ matrix.abi }}-${{ env.cache_hash }}
- name: Build native libraries
if: steps.cache-native-libs.outputs.cache-hit != 'true'
env:
RUSTFLAGS: --deny warnings
BUILD_TYPE: debug
run: |
ARCHITECTURES="${{ matrix.abi }}"
UNSTRIPPED_LIB_PATH="$CARGO_TARGET_DIR/${{ matrix.target }}/$BUILD_TYPE/libmullvad_jni.so"
STRIPPED_LIB_PATH="./android/app/build/extraJni/${{ matrix.abi }}/libmullvad_jni.so"
NDK_TOOLCHAIN_STRIP_TOOL="$NDK_TOOLCHAIN_DIR/llvm-strip"
./wireguard/build-wireguard-go.sh --android --no-docker
cargo build --target ${{ matrix.target }} --verbose --package mullvad-jni --features api-override
$NDK_TOOLCHAIN_STRIP_TOOL --strip-debug --strip-unneeded -o "$STRIPPED_LIB_PATH" "$UNSTRIPPED_LIB_PATH"
- name: Upload native libs
uses: actions/upload-artifact@v3
with:
name: native-libs
path: android/app/build/extraJni
if-no-files-found: error
retention-days: 1
build-app:
name: Build app and run unit tests
needs: [prepare, build-native, generate-relay-list]
runs-on: ubuntu-latest
container:
image: ${{ needs.prepare.outputs.container_image }}
steps:
# Fix for HOME path overridden by GH runners when building in containers, see:
# https://github.com/actions/runner/issues/863
- name: Fix HOME path
run: echo "HOME=/root" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: native-libs
path: android/app/build/extraJni
- uses: actions/download-artifact@v3
with:
name: relay-list
path: build
- name: Build Android app
uses: burrunan/gradle-cache-action@v1
with:
job-id: jdk17
arguments: assembleOssProdDebug
gradle-version: wrapper
build-root-directory: android
- name: Run unit tests
uses: burrunan/gradle-cache-action@v1
with:
job-id: jdk17
arguments: testDebugUnitTest
gradle-version: wrapper
build-root-directory: android
execution-only-caches: true
# Running the AGP lint here rather than in the separate lint workflow
# (android-kotlin-format-check.yml) since it's easier to make use of the running container,
# cache and previously ran tasks.
- name: Run AGP lint
uses: burrunan/gradle-cache-action@v1
with:
job-id: jdk17
arguments: lint
gradle-version: wrapper
build-root-directory: android
execution-only-caches: true
- name: Assemble instrumented test apk (app)
uses: burrunan/gradle-cache-action@v1
with:
job-id: jdk17
arguments: assembleOssProdAndroidTest
gradle-version: wrapper
build-root-directory: android
execution-only-caches: true
- name: Assemble instrumented test apk (mockapi)
uses: burrunan/gradle-cache-action@v1
with:
job-id: jdk17
arguments: :test:mockapi:assemble
gradle-version: wrapper
build-root-directory: android
execution-only-caches: true
- name: Upload apks
uses: actions/upload-artifact@v3
with:
name: apks
path: |
android/app/build/outputs/apk
android/test/mockapi/build/outputs/apk
if-no-files-found: error
retention-days: 1
instrumented-tests:
name: Run instrumented tests
runs-on: [self-hosted, android-emulator]
timeout-minutes: 30
needs: [build-app]
strategy:
fail-fast: false
matrix:
test-type: [app, mockapi]
steps:
- name: Checkout repository
uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: apks
path: android
- name: Run instrumented test script
shell: bash -ieo pipefail {0}
env:
AUTO_FETCH_TEST_HELPER_APKS: true
run: |
./android/scripts/run-instrumented-tests.sh ${{ matrix.test-type }}
- name: Upload instrumentation report (${{ matrix.test-type }})
uses: actions/upload-artifact@v3
if: always()
with:
name: ${{ matrix.test-type }}-instrumentation-report
path: /tmp/mullvad-${{ matrix.test-type }}-instrumentation-report
if-no-files-found: ignore
retention-days: 1