|
| 1 | +name: React Native Harness for Android |
| 2 | +description: Run React Native Harness tests on Android |
| 3 | +inputs: |
| 4 | + app: |
| 5 | + description: The path to the Android app (.apk) |
| 6 | + required: true |
| 7 | + runner: |
| 8 | + description: The runner to use |
| 9 | + required: true |
| 10 | + type: string |
| 11 | + projectRoot: |
| 12 | + description: The project root directory |
| 13 | + required: false |
| 14 | + type: string |
| 15 | +runs: |
| 16 | + using: 'composite' |
| 17 | + steps: |
| 18 | + - uses: 'callstackincubator/react-native-harness/packages/github-action/dist/load-config@feat/github-action' |
| 19 | + id: load-config |
| 20 | + with: |
| 21 | + runner: ${{ inputs.runner }} |
| 22 | + projectRoot: ${{ inputs.projectRoot }} |
| 23 | + - name: Get architecture of the runner |
| 24 | + id: arch |
| 25 | + shell: bash |
| 26 | + run: | |
| 27 | + case "${{ runner.arch }}" in |
| 28 | + X64) |
| 29 | + echo "arch=x86_64" >> $GITHUB_OUTPUT |
| 30 | + ;; |
| 31 | + ARM64) |
| 32 | + echo "arch=arm64-v8a" >> $GITHUB_OUTPUT |
| 33 | + ;; |
| 34 | + ARM32) |
| 35 | + echo "arch=armeabi-v7a" >> $GITHUB_OUTPUT |
| 36 | + ;; |
| 37 | + *) |
| 38 | + echo "arch=x86_64" >> $GITHUB_OUTPUT |
| 39 | + ;; |
| 40 | + esac |
| 41 | + - name: Enable KVM group perms |
| 42 | + shell: bash |
| 43 | + run: | |
| 44 | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules |
| 45 | + sudo udevadm control --reload-rules |
| 46 | + sudo udevadm trigger --name-match=kvm |
| 47 | + ls /dev/kvm |
| 48 | + - name: Compute AVD cache key |
| 49 | + id: avd-key |
| 50 | + shell: bash |
| 51 | + run: | |
| 52 | + CONFIG='${{ steps.load-config.outputs.config }}' |
| 53 | + AVD_CONFIG=$(echo "$CONFIG" | jq -c '.config.device.avd') |
| 54 | + AVD_CONFIG_HASH=$(echo "$AVD_CONFIG" | sha256sum | cut -d' ' -f1) |
| 55 | + ARCH="${{ steps.arch.outputs.arch }}" |
| 56 | + CACHE_KEY="avd-$ARCH-$AVD_CONFIG_HASH" |
| 57 | + echo "key=$CACHE_KEY" >> $GITHUB_OUTPUT |
| 58 | + - name: Restore AVD cache |
| 59 | + uses: actions/cache/restore@v4 |
| 60 | + id: avd-cache |
| 61 | + with: |
| 62 | + path: | |
| 63 | + ~/.android/avd |
| 64 | + ~/.android/adb* |
| 65 | + key: ${{ steps.avd-key.outputs.key }} |
| 66 | + - name: Create AVD and generate snapshot for caching |
| 67 | + if: steps.avd-cache.outputs.cache-hit != 'true' |
| 68 | + uses: reactivecircus/android-emulator-runner@v2 |
| 69 | + with: |
| 70 | + api-level: ${{ fromJson(steps.load-config.outputs.config).config.device.avd.apiLevel }} |
| 71 | + arch: ${{ steps.arch.outputs.arch }} |
| 72 | + profile: ${{ fromJson(steps.load-config.outputs.config).config.device.avd.profile }} |
| 73 | + disk-size: ${{ fromJson(steps.load-config.outputs.config).config.device.avd.diskSize }} |
| 74 | + heap-size: ${{ fromJson(steps.load-config.outputs.config).config.device.avd.heapSize }} |
| 75 | + force-avd-creation: false |
| 76 | + avd-name: ${{ fromJson(steps.load-config.outputs.config).config.device.name }} |
| 77 | + disable-animations: true |
| 78 | + emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none |
| 79 | + script: echo "Generated AVD snapshot for caching." |
| 80 | + - name: Save AVD cache |
| 81 | + if: steps.avd-cache.outputs.cache-hit != 'true' |
| 82 | + uses: actions/cache/save@v4 |
| 83 | + with: |
| 84 | + path: | |
| 85 | + ~/.android/avd |
| 86 | + ~/.android/adb* |
| 87 | + key: ${{ steps.avd-key.outputs.key }} |
| 88 | + - name: Run E2E tests |
| 89 | + id: run-tests |
| 90 | + uses: reactivecircus/android-emulator-runner@v2 |
| 91 | + with: |
| 92 | + working-directory: ${{ inputs.projectRoot }} |
| 93 | + api-level: ${{ fromJson(steps.load-config.outputs.config).config.device.avd.apiLevel }} |
| 94 | + arch: ${{ steps.arch.outputs.arch }} |
| 95 | + force-avd-creation: false |
| 96 | + avd-name: ${{ fromJson(steps.load-config.outputs.config).config.device.name }} |
| 97 | + disable-animations: true |
| 98 | + emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none |
| 99 | + script: | |
| 100 | + echo $(pwd) |
| 101 | + adb install -r ${{ inputs.app }} |
| 102 | + pnpm react-native-harness --harnessRunner ${{ inputs.runner }} |
0 commit comments