-
-
Notifications
You must be signed in to change notification settings - Fork 259
272 lines (231 loc) · 10.1 KB
/
test-suite-native-e2e-android.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
name: "[Test] suite-native Android E2E"
permissions:
id-token: write # for fetching the OIDC token (needed for aws s3 actions)
on:
schedule:
- cron: "0 0 * * *"
pull_request:
paths:
- "suite-native/**"
- "suite-common/**"
- "packages/connect/**"
- ".github/workflows/test-suite-native-e2e-android.yml"
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
NODE_ENV: "test"
jobs:
prepare_android_test_app:
if: github.repository == 'trezor/trezor-suite'
runs-on: ubuntu-latest
steps:
- name: Checkout project
uses: actions/checkout@v4
with:
submodules: "true"
- name: Free Disk Space
uses: jlumbroso/free-disk-space@main
with:
# The free GH runner has limited disk space, so we need to uninstall some preinstalled tools.
dotnet: true
haskell: true
tool-cache: false
android: false
swap-storage: false
large-packages: false
- name: Install node and yarn
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: yarn
- name: Setup node_modules cache
uses: actions/cache@v4
with:
path: node_modules
key: node_modules/${{ github.ref }}/${{github.run_id}}
- name: Install Yarn dependencies
run: |
echo -e "\nenableScripts: false" >> .yarnrc.yml
echo -e "\nenableHardenedMode: false" >> .yarnrc.yml
yarn install
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- name: Prebuild native expo project
working-directory: ./suite-native/app
run: yarn prebuild --platform android --clean
- name: Sign message system config
working-directory: ./suite-common/message-system
run: yarn sign-config
- name: get Expo app fingerprint
id: expo-fingerprint
working-directory: ./suite-native/app
run: npx @expo/fingerprint ./ > expo-fingerprint.json && node -e "console.log('HASH=' + require('./expo-fingerprint.json').hash)" >> $GITHUB_OUTPUT
- name: Configure aws credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::538326561891:role/gh_actions_trezor_suite_dev_deploy
aws-region: eu-central-1
- name: Check if native build exists in AWS bucket
id: s3_build_cache
run: |
if aws s3 ls s3://dev.suite.sldev.cz/suite-mobile/${{ steps.expo-fingerprint.outputs.HASH }} --summarize;
then
echo "hit=true" >> $GITHUB_OUTPUT;
else
echo "hit=false" >> $GITHUB_OUTPUT;
fi
################ CACHE HIT - REPLACE JS BUNDLE ONLY ##############
- name: Setup Android SDK
if: steps.s3_build_cache.outputs.hit == 'true'
uses: android-actions/setup-android@v3
- name: Download Apktool
if: steps.s3_build_cache.outputs.hit == 'true'
run: |
wget https://github.com/iBotPeaches/Apktool/releases/download/v2.8.1/apktool_2.8.1.jar -O apktool.jar
wget https://raw.githubusercontent.com/iBotPeaches/Apktool/master/scripts/linux/apktool -O apktool
chmod +x apktool
sudo mv apktool.jar /usr/local/bin/apktool.jar
sudo mv apktool /usr/local/bin/apktool
- name: Download build from aws bucket
if: steps.s3_build_cache.outputs.hit == 'true'
working-directory: ./suite-native/app
run: aws s3 cp s3://dev.suite.sldev.cz/suite-mobile/${{ steps.expo-fingerprint.outputs.HASH }}/ ./android/app/build/outputs --recursive
- name: decompile .apk build
if: steps.s3_build_cache.outputs.hit == 'true'
working-directory: ./suite-native/app/android/app/build/outputs/apk/release
run: apktool d app-release.apk -o unpacked
- name: replace JS bundle
if: steps.s3_build_cache.outputs.hit == 'true'
working-directory: "./suite-native/app"
env:
JS_BUNDLE_PATH: ./android/app/build/outputs/apk/release/unpacked/assets/index.android.bundle
ASSETS_DEST_PATH: ./android/app/build/outputs/apk/release/unpacked/res/
ENTRY_FILE_PATH: ./suite-native/app/index.js
EXPO_PUBLIC_IS_DETOX_BUILD: true
EXPO_PUBLIC_ENVIRONMENT: debug
run: npx react-native bundle --platform android --dev false --entry-file $ENTRY_FILE_PATH --bundle-output $JS_BUNDLE_PATH --assets-dest $ASSETS_DEST_PATH
- name: fix native library bundling (extractNativeLibs=true)
if: steps.s3_build_cache.outputs.hit == 'true'
working-directory: "./suite-native/app/android/app/build/outputs/apk/release/unpacked"
run: sed -i 's/android:extractNativeLibs=\"false\"/android:extractNativeLibs=\"true\"/g' AndroidManifest.xml
- name: compile .apk back
if: steps.s3_build_cache.outputs.hit == 'true'
working-directory: ./suite-native/app/android/app/build/outputs/apk/release
run: apktool b unpacked -o app-release.apk
- name: sign re-bundled .apk
if: steps.s3_build_cache.outputs.hit == 'true'
working-directory: ./suite-native/app/android/app/build/outputs/apk/release
env:
KEYSTORE_PATH: ../../../../debug.keystore
KEYSTORE_PASSWORD: pass:android
run: $ANDROID_HOME/build-tools/35.0.0/apksigner sign --ks $KEYSTORE_PATH --ks-pass $KEYSTORE_PASSWORD --out app-release.apk app-release.apk
############# CACHE MISS - COMPILE A FRESH .APK FILE #############
- name: Build a new Detox test .apk
if: steps.s3_build_cache.outputs.hit == 'false'
working-directory: ./suite-native/app
run: ../../node_modules/.bin/detox build -PreactNativeArchitectures=x86_64 --configuration android.emu.release
- name: save .apk to the aws s3 bucket
if: steps.s3_build_cache.outputs.hit == 'false'
working-directory: ./suite-native/app/android/app/build/outputs
run: aws s3 cp . s3://dev.suite.sldev.cz/suite-mobile/${{ steps.expo-fingerprint.outputs.HASH }}/ --recursive
- name: Save build to cache
uses: actions/cache/save@v4
with:
path: |
suite-native/app/android/app/build/
key: android_test_build/${{ github.ref }}/${{github.run_id}}
###################################################################
run_android_e2e_tests:
if: github.repository == 'trezor/trezor-suite'
runs-on: ubuntu-latest
needs: prepare_android_test_app
steps:
- name: Checkout project
uses: actions/checkout@v4
with:
submodules: "true"
- name: Free Disk Space
uses: jlumbroso/free-disk-space@main
with:
# Combination of android emulator and trezor-user-env is using a too much disk space
# of a free tier GH action runner, some preinstalled packages have to be removed.
dotnet: true
haskell: true
tool-cache: false
android: false
swap-storage: false
large-packages: false
- name: Install node and yarn
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: yarn
- name: Load node modules cache
uses: actions/cache@v4
with:
path: node_modules
key: node_modules/${{ github.ref }}/${{github.run_id}}
- name: Install Yarn dependencies
run: |
echo -e "\nenableScripts: false" >> .yarnrc.yml
echo -e "\nenableHardenedMode: false" >> .yarnrc.yml
yarn install
- name: Get device name from detox config file
id: device
run: node -e "console.log('AVD_NAME=' + require('./suite-native/app/.detoxrc').devices.emulator.device.avdName)" >> $GITHUB_OUTPUT
- name: Run trezor-user-env
env:
COMPOSE_FILE: ./docker/docker-compose.suite-native-ci.yml
run: |
docker compose pull trezor-user-env-unix trezor-user-env-regtest
docker compose up --detach trezor-user-env-unix trezor-user-env-regtest
- name: Read test .apk from cache
uses: actions/cache/restore@v4
with:
path: |
suite-native/app/android/app/build/
key: android_test_build/${{ github.ref }}/${{github.run_id}}
- name: Enable Android emulator KVM optimalization
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Run Detox E2E Android tests
uses: reactivecircus/android-emulator-runner@v2
env:
RUNNER_TEMP: /tmp
with:
api-level: 31
profile: pixel_3a
arch: x86_64
working-directory: suite-native/app
ram-size: 4096M
force-avd-creation: true
avd-name: ${{ steps.device.outputs.AVD_NAME }}
emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim -grpc 8554
script: yarn test:e2e android.emu.release --headless --take-screenshots failing --record-videos failing
- name: Upload results to Currents.dev
if: ${{ ! cancelled() }}
env:
CURRENTS_PROJECT_ID: iUe1Y4
CURRENTS_RECORD_KEY: ${{ secrets.CURRENTS_RECORD_KEY }}
working-directory: ./suite-native/app
run: |
npx currents convert \
--input-format=junit \
--input-file=./reports/junit-report.xml \
--output-dir=./currents \
--framework=postman \
--framework-version=v11.2.0
npx currents upload --project-id=${CURRENTS_PROJECT_ID} --key=${CURRENTS_RECORD_KEY} --report-dir ./currents
- name: "Store failed test screenshot artifacts"
if: ${{failure()}}
uses: actions/upload-artifact@v4
with:
name: failed-android-tests
path: suite-native/app/artifacts