-
-
Notifications
You must be signed in to change notification settings - Fork 28
470 lines (416 loc) · 17.2 KB
/
build.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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
name: Build
on:
push:
branches: [ master ]
tags:
- v*
pull_request:
branches: [ master ]
jobs:
build-rust:
name: Build aw-server-rust (ndk-${{ matrix.ndk_version }}, node-${{ matrix.node_version }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04]
ndk_version: ['25.2.9519653']
node_version: [16]
steps:
- uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: Set RELEASE
run: |
echo "RELEASE=${{ startsWith(github.ref_name, 'v') }}" >> $GITHUB_ENV
- name: Cache JNI libs
uses: actions/cache@v1
id: cache-jniLibs
env:
cache-name: jniLibs
with:
path: mobile/src/main/jniLibs/
key: ${{ env.cache-name }}-release-${{ env.RELEASE }}-ndk-${{ matrix.ndk_version }}-${{ hashFiles('.git/modules/aw-server-rust/HEAD') }}
- name: Display structure of downloaded files
if: steps.cache-jniLibs.outputs.cache-hit == 'true'
run: |
pushd mobile/src/main/jniLibs && ls -R && popd
# Android SDK & NDK
- name: Set up Android SDK
if: steps.cache-jniLibs.outputs.cache-hit != 'true'
uses: android-actions/setup-android@v2
- name: Install NDK
if: steps.cache-jniLibs.outputs.cache-hit != 'true'
run: |
sdkmanager "ndk;${{ matrix.ndk_version }}"
ANDROID_NDK_HOME="$ANDROID_SDK_ROOT/ndk/${{ matrix.ndk_version }}"
ls $ANDROID_NDK_HOME
echo "ANDROID_NDK_HOME=$ANDROID_NDK_HOME" >> $GITHUB_ENV
# Rust
- name: Set up Rust nightly
uses: actions-rs/toolchain@v1
if: steps.cache-jniLibs.outputs.cache-hit != 'true'
with:
profile: minimal
toolchain: nightly
override: true
- name: Set up Rust toolchain for Android NDK
if: steps.cache-jniLibs.outputs.cache-hit != 'true'
run: |
./aw-server-rust/install-ndk.sh
- name: Cache cargo build
uses: actions/cache@v1
if: steps.cache-jniLibs.outputs.cache-hit != 'true'
env:
cache-name: cargo-build-target
with:
path: aw-server-rust/target
key: ${{ env.cache-name }}-release-${{ env.RELEASE }}-${{ hashFiles('**/Cargo.lock') }}
- name: Build aw-server-rust
if: steps.cache-jniLibs.outputs.cache-hit != 'true'
run: |
make aw-server-rust
- name: Check that jniLibs present
run: |
test -e mobile/src/main/jniLibs/x86_64/libaw_server.so
- name: Upload JNI libs
uses: actions/upload-artifact@v3
with:
name: jniLibs
path: mobile/src/main/jniLibs/
build-apk:
name: Build APK (${{ matrix.os }}, java-${{ matrix.java_version }})
runs-on: ${{ matrix.os }}
needs: [build-rust]
env:
SUPPLY_TRACK: production # used by fastlane to determine track to publish to
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04]
java_version: [17]
ruby_version: ['3.0']
ndk_version: ['25.2.9519653']
steps:
- uses: actions/checkout@v2
with:
submodules: 'recursive'
# Build in release mode if on a tag/release (longer build times)
- name: Set RELEASE
run: |
echo "RELEASE=${{ startsWith(github.ref_name, 'v') }}" >> $GITHUB_ENV
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java_version }}
# Android SDK & NDK
- name: Set up Android SDK
uses: android-actions/setup-android@v2
- name: Install NDK
run: |
sdkmanager "ndk;${{ matrix.ndk_version }}"
ANDROID_NDK_HOME="$ANDROID_SDK_ROOT/ndk/${{ matrix.ndk_version }}"
ls $ANDROID_NDK_HOME
echo "ANDROID_NDK_HOME=$ANDROID_NDK_HOME" >> $GITHUB_ENV
# Ruby & Fastlane
- name: Set up Ruby
uses: actions/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby_version }}
- name: Install fastlane
run: |
gem install bundler
bundle install
- name: Install age
uses: adnsio/setup-age-action@v1.2.0
- name: Download JNI libs
uses: actions/download-artifact@v3
with:
name: jniLibs
path: mobile/src/main/jniLibs
- name: Check that jniLibs present
run: |
test -e mobile/src/main/jniLibs/x86_64/libaw_server.so
# Needed for `fastlane update_version`
- name: Load Fastlane secrets
env:
KEY_FASTLANE_API: ${{ secrets.KEY_FASTLANE_API }}
run: |
printf "$KEY_FASTLANE_API" > fastlane/api-8546008605074111507-287154-450dc77b365f.json.key
cat fastlane/api-8546008605074111507-287154-450dc77b365f.json.age \
| age -d -i fastlane/api-8546008605074111507-287154-450dc77b365f.json.key \
-o fastlane/api-8546008605074111507-287154-450dc77b365f.json
rm fastlane/api-8546008605074111507-287154-450dc77b365f.json.key
- name: Set version
if: startsWith(github.ref, 'refs/tags/v') # only on runs triggered from tag
run: |
# Sets versionName, tail used to skip "v" at start of tag name
SHORT_VERSION=$(echo "${{ github.ref_name }}" | tail -c +2 -)
sed -i "s/versionName \".*\"/versionName \"$SHORT_VERSION\"/g" \
mobile/build.gradle
- name: Update versionCode
run: bundle exec fastlane update_version
# Test
- name: Test
run: |
make test
- name: Load Android secrets
if: env.KEY_ANDROID_JKS != null
env:
KEY_ANDROID_JKS: ${{ secrets.KEY_ANDROID_JKS }}
run: |
printf "$KEY_ANDROID_JKS" > android.jks.key
cat android.jks.age | age -d -i android.jks.key -o android.jks
rm android.jks.key
- name: Assemble APK
env:
JKS_STOREPASS: ${{ secrets.KEY_ANDROID_JKS_STOREPASS }}
JKS_KEYPASS: ${{ secrets.KEY_ANDROID_JKS_KEYPASS }}
run: |
make dist/aw-android.apk
- name: Upload release APK
uses: actions/upload-artifact@v3
with:
name: aw-android
path: dist/aw-android*.apk
test-e2e:
name: Test E2E ${{ matrix.android_avd }} #-${{ matrix.os }}-eAPI-${{ matrix.android_emu_version }}-java-${{ matrix.java_version }}-node-${{ matrix.node_version }}
needs: [build-rust]
if: false # disabled
runs-on: ${{ matrix.os }}
env:
MATRIX_E_SDK: ${{ matrix.android_emu_version }}
MATRIX_AVD: ${{ matrix.android_avd }}
strategy:
fail-fast: false
max-parallel: 1
matrix:
os: [macos-12] # macOS-latest,
android_avd: [Pixel_API_27_AOSP]
java_version: [11]
ndk_version: ['25.2.9519653']
include:
- android_avd: Pixel_API_27_AOSP
android_emu_version: 27
# # # Cannot run > 27-emuLevel -_- https://github.com/actions/runner-images/issues/6527
# - android_avd: Pixel_API_32_AOSP
# android_emu_version: 32
steps:
- uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: Download JNI libs
uses: actions/download-artifact@v3
with:
name: jniLibs
path: mobile/src/main/jniLibs
- name: Display structure of downloaded files
run: |
pushd mobile/src/main/jniLibs && ls -R && popd
# # # Below code is majorly from https://github.com/actions/runner-images/issues/6152#issuecomment-1243718140
- name: Create Android emulator
run: |
brew install intel-haxm
# Install AVD files
echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install 'system-images;android-'$MATRIX_E_SDK';default;x86_64'
echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --licenses
# Create emulator
$ANDROID_HOME/tools/bin/avdmanager create avd -n $MATRIX_AVD -d pixel --package 'system-images;android-'$MATRIX_E_SDK';default;x86_64'
$ANDROID_HOME/emulator/emulator -list-avds
if false; then
emulator_config=~/.android/avd/$MATRIX_AVD.avd/config.ini
# The following madness is to support empty OR populated config.ini files,
# the state of which is dependant on the version of the emulator used (which we don't control),
# so let's be defensive to be safe.
# Replace existing config (NOTE we're on MacOS so sed works differently!)
sed -i .bak 's/hw.lcd.density=.*/hw.lcd.density=420/' "$emulator_config"
sed -i .bak 's/hw.lcd.height=.*/hw.lcd.height=1920/' "$emulator_config"
sed -i .bak 's/hw.lcd.width=.*/hw.lcd.width=1080/' "$emulator_config"
# Or, add new config
if ! grep -q "hw.lcd.density" "$emulator_config"; then
echo "hw.lcd.density=420" >> "$emulator_config"
fi
if ! grep -q "hw.lcd.height" "$emulator_config"; then
echo "hw.lcd.height=1920" >> "$emulator_config"
fi
if ! grep -q "hw.lcd.width" "$emulator_config"; then
echo "hw.lcd.width=1080" >> "$emulator_config"
fi
echo "Emulator settings ($emulator_config)"
cat "$emulator_config"
fi
- name: Start Android emulator
timeout-minutes: 30 # ~4min normal - 3x DOSafety
env:
SUFFIX: ${{ matrix.android_avd }}-eAPI-${{ matrix.android_emu_version }}-${{ matrix.os }}
HOMEBREW_NO_INSTALL_CLEANUP: 1
run: |
echo "Starting emulator and waiting for boot to complete...."
ls -la $ANDROID_HOME/emulator
nohup $ANDROID_HOME/tools/emulator -avd $MATRIX_AVD -gpu host -no-audio -no-boot-anim -camera-back none -camera-front none -qemu -m 2048 2>&1 &
$ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do echo "wait..."; sleep 1; done; input keyevent 82'
echo "Emulator has finished booting"
$ANDROID_HOME/platform-tools/adb devices
sleep 30
mkdir -p screenshots
screencapture screenshots/screenshot-$SUFFIX.jpg
$ANDROID_HOME/platform-tools/adb exec-out screencap -p > screenshots/emulator-$SUFFIX.png
# # # Have to re-setup everything since we need to run emulator for faster performance on masOS ? Other os'es emulator will not startup ?
# TODO: Optimize the steps taking into consideration all software present by default on macOS runner image
# # # Test # # reactiveCircus is giving a black screenshot not working
# # # TODO: Take a screenshot of OS to confirm if its Emulator issue or testcode/androidsdk issue - or maybe the emulator is screen off ?
# # # https://github.com/ReactiveCircus/android-emulator-runner
# - name: Test Cache
# uses: reactivecircus/android-emulator-runner@v2
# with:
# api-level: ${{ matrix.android_emu_version }}
# arch: x86_64
# profile: Nexus 6
# target: google_apis
# emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim
# script: echo Meoooow !
# - name: Test
# id: test
# uses: reactivecircus/android-emulator-runner@v2
# with:
# api-level: ${{ matrix.android_emu_version }}
# arch: x86_64
# profile: Nexus 6
# target: google_apis
# emulator-options: -gpu swiftshader_indirect -noaudio -no-boot-anim -no-snapshot-save
# # Only running specific Instrumentation tests cause others are failing right now. TODO: Fix others
# script: ./gradlew connectedCheck -Pandroid.testInstrumentationRunnerArguments.class=net.activitywatch.android.ScreenshotTest --stacktrace
# - name: Install recorder and record session
# env:
# SUFFIX: ${{ matrix.android_avd }}-eAPI-${{ matrix.android_emu_version }}-${{ matrix.os }}
# run: |
# brew install ffmpeg
# $ANDROID_HOME/tools/emulator -help-all
# # -logcat *:v
# # $ANDROID_HOME/tools/emulator -port 18725 -verbose -no-audio -gpu swiftshader_indirect -logcat *:v @$MATRIX_AVD &
# ffmpeg -f avfoundation -i 0 -t 120 out$SUFFIX.mov &
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java_version }}
# Android SDK & NDK
- name: Set up Android SDK
uses: android-actions/setup-android@v2
- name: Install NDK
run: |
sdkmanager "ndk;${{ matrix.ndk_version }}"
ANDROID_NDK_HOME="$ANDROID_SDK_ROOT/ndk/${{ matrix.ndk_version }}"
ls $ANDROID_NDK_HOME
echo "ANDROID_NDK_HOME=$ANDROID_NDK_HOME" >> $GITHUB_ENV
- name: Run E2E tests
timeout-minutes: 20
id: test
run: |
make test-e2e
- name: Output and save logcat to file
if: ${{ success() || steps.test.conclusion == 'failure'}}
run: |
mkdir -p mobile/build
adb logcat -d > mobile/build/logcat.log
adb logcat -v color &
- name: Screenshot
if: ${{ success() || steps.test.conclusion == 'failure'}}
env:
SUFFIX: ${{ matrix.android_avd }}-eAPI-${{ matrix.android_emu_version }}-${{ matrix.os }}
run: |
adb shell monkey -p net.activitywatch.android.debug 1
sleep 10
screencapture screenshots/pscreenshot-$SUFFIX.jpg
$ANDROID_HOME/platform-tools/adb exec-out screencap -p > screenshots/pemulator-$SUFFIX.png
ls -alh screenshots/
- name: Upload logcat
if: ${{ success() || steps.test.conclusion == 'failure'}}
uses: actions/upload-artifact@v3
with:
name: logcat
# mobile\build\outputs\connected_android_test_additional_output\debugAndroidTest\connected\Pixel_XL_API_32(AVD) - 12\ScreenshotTest_saveDeviceScreenBitmap.png
path: |
mobile/build/logcat.log
#mobile/build/reports/*
# - name: Upload video
# if: ${{ success() || steps.test.conclusion == 'failure'}}
# uses: actions/upload-artifact@master
# with:
# name: video
# path: ./*.mov # out.mov
- name: Upload screenshots
uses: actions/upload-artifact@v3
if: ${{ success() || steps.test.conclusion == 'failure'}}
with:
name: screenshots
path: |
screenshots/*
**/mobile/build/outputs/connected_android_test_additional_output/debugAndroidTest/connected/*
#- name: Publish Test Report
# # # uses: mikepenz/action-junit-report@v3
# # # # # TODO: Format a little ? or Use some utility to confier GITHUB_STE_SUMMARY.html below into markdown before outputting it into $GITHUB_STEP_SUMMARY?
# if: ${{ success() || steps.test.conclusion == 'failure'}}
# # # with:
# # # report_paths: '**/build/reports/*Tests/**/*.html' # '**/build/test-results/test/TEST-*.xml'
# run: |
# for file in ./mobile/build/reports/androidTests/connected/*.html; do cat $file >> GITHUB_STEP_SUMMARY.html ; done
# # echo '<style>' >> GITHUB_STEP_SUMMARY.html;for file in ./mobile/build/reports/androidTests/connected/**/*.css; do cat $file >> GITHUB_STEP_SUMMARY.html ; done; echo '</style>' >> GITHUB_STEP_SUMMARY.html;
# cat GITHUB_STEP_SUMMARY.html >> $GITHUB_STEP_SUMMARY
release-fastlane:
needs: [build-apk]
if: startsWith(github.ref, 'refs/tags/v') # only on runs triggered from tag
runs-on: ubuntu-latest
steps:
- name: Download release APK
uses: actions/download-artifact@v3
with:
name: aw-android
path: dist
- name: Display structure of downloaded files
working-directory: dist
run: ls -R
# detect if version tag is stable/beta
- uses: nowsprinting/check-version-format-action@v2
id: version
with:
prefix: 'v'
- uses: adnsio/setup-age-action@v1.2.0
- name: Load secrets
env:
KEY_FASTLANE_API: ${{ secrets.KEY_FASTLANE_API }}
run: |
printf "$KEY_FASTLANE_API" > fastlane/api-8546008605074111507-287154-450dc77b365f.json.key
cat fastlane/api-8546008605074111507-287154-450dc77b365f.json.age \
| age -d -i fastlane/api-8546008605074111507-287154-450dc77b365f.json.key \
-o fastlane/api-8546008605074111507-287154-450dc77b365f.json
rm fastlane/api-8546008605074111507-287154-450dc77b365f.json.key
- name: Release with fastlane
if: ${{ !(steps.version.outputs.is_stable == 'true') }} # must compare to true, since boolean outputs are actually just strings, and "false" is truthy since it's not empty: https://github.com/actions/runner/issues/1483#issuecomment-994986996
run: |
bundle exec fastlane supply run --apk dist/*/*.apk
release-gh:
needs: [build-apk]
if: startsWith(github.ref, 'refs/tags/v') # only on runs triggered from tag
runs-on: ubuntu-latest
steps:
# Will download all artifacts to path
- name: Download release APK
uses: actions/download-artifact@v3
with:
name: aw-android
path: dist
- name: Display structure of downloaded files
working-directory: dist
run: ls -R
# detect if version tag is stable/beta
- uses: nowsprinting/check-version-format-action@v2
id: version
with:
prefix: 'v'
# create a release
- name: Release
uses: softprops/action-gh-release@v1
with:
draft: true
prerelease: ${{ !(steps.version.outputs.is_stable == 'true') }} # must compare to true, since boolean outputs are actually just strings, and "false" is truthy since it's not empty: https://github.com/actions/runner/issues/1483#issuecomment-994986996
files: dist/*/*.apk
# body_path: dist/release_notes/release_notes.md