Skip to content

Commit

Permalink
ci(suite-native): build e2e apk only if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
PeKne committed Dec 4, 2024
1 parent cda066a commit fbfa575
Show file tree
Hide file tree
Showing 3 changed files with 614 additions and 21 deletions.
101 changes: 95 additions & 6 deletions .github/workflows/test-suite-native-e2e-android.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
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 * * *"
Expand All @@ -18,7 +22,7 @@ env:
NODE_ENV: "test"

jobs:
build_android_test_app:
prepare_android_test_app:
if: github.repository == 'trezor/trezor-suite'
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -62,17 +66,100 @@ jobs:
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: Prebuild native expo project
- name: get Expo app fingerprint
id: expo-fingerprint
working-directory: ./suite-native/app
run: yarn prebuild --platform android --clean
run: npx @expo/fingerprint ./ > expo-fingerprint.json && node -e "console.log('HASH=' + require('./expo-fingerprint.json').hash)" >> $GITHUB_OUTPUT

- name: Build Detox test .apk
run: ../../node_modules/.bin/detox build -PreactNativeArchitectures=x86_64 --configuration android.emu.release
- 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
run: |
source ./.env.test
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
Expand All @@ -81,10 +168,12 @@ jobs:
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: build_android_test_app
needs: prepare_android_test_app
steps:
- name: Checkout project
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions suite-native/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
"@babel/core": "^7.20.0",
"@babel/plugin-transform-export-namespace-from": "^7.23.4",
"@config-plugins/detox": "^8.0.0",
"@react-native-community/cli": "^15.1.2",
"@react-native/babel-preset": "^0.75.2",
"@suite-common/test-utils": "workspace:^",
"@trezor/connect-mobile": "workspace:^",
Expand Down
Loading

0 comments on commit fbfa575

Please sign in to comment.