|
| 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: Verify Android config |
| 24 | + shell: bash |
| 25 | + run: | |
| 26 | + CONFIG='${{ steps.load-config.outputs.config }}' |
| 27 | + if [ -z "$CONFIG.config.device.avd" ] || [ "$CONFIG.config.device.avd" = "null" ]; then |
| 28 | + echo "Error: AVD config is required for Android emulators" |
| 29 | + echo "Please define the 'avd' property in the runner config" |
| 30 | + exit 1 |
| 31 | + fi |
| 32 | + - name: Get architecture of the runner |
| 33 | + id: arch |
| 34 | + shell: bash |
| 35 | + run: | |
| 36 | + case "${{ runner.arch }}" in |
| 37 | + X64) |
| 38 | + echo "arch=x86_64" >> $GITHUB_OUTPUT |
| 39 | + ;; |
| 40 | + ARM64) |
| 41 | + echo "arch=arm64-v8a" >> $GITHUB_OUTPUT |
| 42 | + ;; |
| 43 | + ARM32) |
| 44 | + echo "arch=armeabi-v7a" >> $GITHUB_OUTPUT |
| 45 | + ;; |
| 46 | + *) |
| 47 | + echo "arch=x86_64" >> $GITHUB_OUTPUT |
| 48 | + ;; |
| 49 | + esac |
| 50 | + - name: Enable KVM group perms |
| 51 | + shell: bash |
| 52 | + run: | |
| 53 | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules |
| 54 | + sudo udevadm control --reload-rules |
| 55 | + sudo udevadm trigger --name-match=kvm |
| 56 | + ls /dev/kvm |
| 57 | + - name: Compute AVD cache key |
| 58 | + id: avd-key |
| 59 | + shell: bash |
| 60 | + run: | |
| 61 | + CONFIG='${{ steps.load-config.outputs.config }}' |
| 62 | + AVD_CONFIG=$(echo "$CONFIG" | jq -c '.config.device.avd') |
| 63 | + AVD_CONFIG_HASH=$(echo "$AVD_CONFIG" | sha256sum | cut -d' ' -f1) |
| 64 | + ARCH="${{ steps.arch.outputs.arch }}" |
| 65 | + CACHE_KEY="avd-$ARCH-$AVD_CONFIG_HASH" |
| 66 | + echo "key=$CACHE_KEY" >> $GITHUB_OUTPUT |
| 67 | + - name: Restore AVD cache |
| 68 | + uses: actions/cache/restore@v4 |
| 69 | + id: avd-cache |
| 70 | + with: |
| 71 | + path: | |
| 72 | + ~/.android/avd |
| 73 | + ~/.android/adb* |
| 74 | + key: ${{ steps.avd-key.outputs.key }} |
| 75 | + - name: Create AVD and generate snapshot for caching |
| 76 | + if: steps.avd-cache.outputs.cache-hit != 'true' |
| 77 | + uses: reactivecircus/android-emulator-runner@v2 |
| 78 | + with: |
| 79 | + api-level: ${{ fromJson(steps.load-config.outputs.config).config.device.avd.apiLevel }} |
| 80 | + arch: ${{ steps.arch.outputs.arch }} |
| 81 | + profile: ${{ fromJson(steps.load-config.outputs.config).config.device.avd.profile }} |
| 82 | + disk-size: ${{ fromJson(steps.load-config.outputs.config).config.device.avd.diskSize }} |
| 83 | + heap-size: ${{ fromJson(steps.load-config.outputs.config).config.device.avd.heapSize }} |
| 84 | + force-avd-creation: false |
| 85 | + avd-name: ${{ fromJson(steps.load-config.outputs.config).config.device.name }} |
| 86 | + disable-animations: true |
| 87 | + emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none |
| 88 | + script: echo "Generated AVD snapshot for caching." |
| 89 | + - name: Save AVD cache |
| 90 | + if: steps.avd-cache.outputs.cache-hit != 'true' |
| 91 | + uses: actions/cache/save@v4 |
| 92 | + with: |
| 93 | + path: | |
| 94 | + ~/.android/avd |
| 95 | + ~/.android/adb* |
| 96 | + key: ${{ steps.avd-key.outputs.key }} |
| 97 | + - name: Run E2E tests |
| 98 | + id: run-tests |
| 99 | + uses: reactivecircus/android-emulator-runner@v2 |
| 100 | + with: |
| 101 | + working-directory: ${{ inputs.projectRoot }} |
| 102 | + api-level: ${{ fromJson(steps.load-config.outputs.config).config.device.avd.apiLevel }} |
| 103 | + arch: ${{ steps.arch.outputs.arch }} |
| 104 | + force-avd-creation: false |
| 105 | + avd-name: ${{ fromJson(steps.load-config.outputs.config).config.device.name }} |
| 106 | + disable-animations: true |
| 107 | + emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none |
| 108 | + script: | |
| 109 | + echo $(pwd) |
| 110 | + adb install -r ${{ inputs.app }} |
| 111 | + pnpm react-native-harness --harnessRunner ${{ inputs.runner }} |
0 commit comments