forked from callstackincubator/react-native-harness
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
148 lines (148 loc) · 5.57 KB
/
action.yml
File metadata and controls
148 lines (148 loc) · 5.57 KB
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
name: React Native Harness for Android
description: Run React Native Harness tests on Android
inputs:
app:
description: The path to the Android app (.apk)
required: true
runner:
description: The runner to use
required: true
type: string
projectRoot:
description: The project root directory
required: false
type: string
uploadVisualTestArtifacts:
description: Whether to upload visual test diff and actual images as artifacts
required: false
type: boolean
default: 'true'
runs:
using: 'composite'
steps:
- name: Load React Native Harness configuration
id: load-config
shell: bash
env:
INPUT_RUNNER: ${{ inputs.runner }}
INPUT_PROJECTROOT: ${{ inputs.projectRoot }}
run: |
node ${{ github.action_path }}/../shared/index.cjs
- name: Verify Android config
shell: bash
run: |
CONFIG='${{ steps.load-config.outputs.config }}'
if [ -z "$CONFIG.config.device.avd" ] || [ "$CONFIG.config.device.avd" = "null" ]; then
echo "Error: AVD config is required for Android emulators"
echo "Please define the 'avd' property in the runner config"
exit 1
fi
- name: Get architecture of the runner
id: arch
shell: bash
run: |
case "${{ runner.arch }}" in
X64)
echo "arch=x86_64" >> $GITHUB_OUTPUT
;;
ARM64)
echo "arch=arm64-v8a" >> $GITHUB_OUTPUT
;;
ARM32)
echo "arch=armeabi-v7a" >> $GITHUB_OUTPUT
;;
*)
echo "arch=x86_64" >> $GITHUB_OUTPUT
;;
esac
- name: Enable KVM group perms
shell: bash
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
ls /dev/kvm
- name: Compute AVD cache key
id: avd-key
shell: bash
run: |
CONFIG='${{ steps.load-config.outputs.config }}'
AVD_CONFIG=$(echo "$CONFIG" | jq -c '.config.device.avd')
AVD_CONFIG_HASH=$(echo "$AVD_CONFIG" | sha256sum | cut -d' ' -f1)
ARCH="${{ steps.arch.outputs.arch }}"
CACHE_KEY="avd-$ARCH-$AVD_CONFIG_HASH"
echo "key=$CACHE_KEY" >> $GITHUB_OUTPUT
- name: Restore AVD cache
uses: actions/cache/restore@v4
id: avd-cache
with:
path: |
~/.android/avd
~/.android/adb*
key: ${{ steps.avd-key.outputs.key }}
- name: Create AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ fromJson(steps.load-config.outputs.config).config.device.avd.apiLevel }}
arch: ${{ steps.arch.outputs.arch }}
profile: ${{ fromJson(steps.load-config.outputs.config).config.device.avd.profile }}
disk-size: ${{ fromJson(steps.load-config.outputs.config).config.device.avd.diskSize }}
heap-size: ${{ fromJson(steps.load-config.outputs.config).config.device.avd.heapSize }}
force-avd-creation: false
avd-name: ${{ fromJson(steps.load-config.outputs.config).config.device.name }}
disable-animations: true
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
script: echo "Generated AVD snapshot for caching."
- name: Save AVD cache
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: |
~/.android/avd
~/.android/adb*
key: ${{ steps.avd-key.outputs.key }}
- name: Detect Package Manager
id: detect-pm
shell: bash
run: |
if [ -f "pnpm-lock.yaml" ]; then
echo "manager=pnpm" >> $GITHUB_OUTPUT
echo "runner=pnpm exec " >> $GITHUB_OUTPUT
elif [ -f "yarn.lock" ]; then
echo "manager=yarn" >> $GITHUB_OUTPUT
echo "runner=yarn " >> $GITHUB_OUTPUT
elif [ -f "bun.lockb" ]; then
echo "manager=bun" >> $GITHUB_OUTPUT
echo "runner=bunx " >> $GITHUB_OUTPUT
elif [ -f "deno.lock" ]; then
echo "manager=deno" >> $GITHUB_OUTPUT
echo "runner=deno run -A npm:" >> $GITHUB_OUTPUT
else
echo "manager=npm" >> $GITHUB_OUTPUT
echo "runner=npx " >> $GITHUB_OUTPUT
fi
- name: Run E2E tests
id: run-tests
uses: reactivecircus/android-emulator-runner@v2
with:
working-directory: ${{ inputs.projectRoot }}
api-level: ${{ fromJson(steps.load-config.outputs.config).config.device.avd.apiLevel }}
arch: ${{ steps.arch.outputs.arch }}
force-avd-creation: false
avd-name: ${{ fromJson(steps.load-config.outputs.config).config.device.name }}
disable-animations: true
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
script: |
echo $(pwd)
adb install -r ${{ inputs.app }}
${{ steps.detect-pm.outputs.runner }}react-native-harness --harnessRunner ${{ inputs.runner }}
- name: Upload visual test artifacts
if: always() && inputs.uploadVisualTestArtifacts == 'true'
uses: actions/upload-artifact@v4
with:
name: visual-test-diffs-android
path: |
${{ inputs.projectRoot }}/**/__image_snapshots__/**/*-diff.png
${{ inputs.projectRoot }}/**/__image_snapshots__/**/*-actual.png
if-no-files-found: ignore