Skip to content

Commit 840a109

Browse files
author
yandadaFreedom
committed
add e22 yml
1 parent 3db1bdd commit 840a109

File tree

1 file changed

+207
-0
lines changed

1 file changed

+207
-0
lines changed

.github/workflows/e2e.yml

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
name: E2E Tests
2+
3+
on:
4+
push:
5+
branches: [ master, dev ]
6+
pull_request:
7+
branches: [ master, dev ]
8+
workflow_dispatch: # 允许手动触发
9+
10+
jobs:
11+
e2e-ios:
12+
name: E2E Tests (iOS)
13+
runs-on: macos-14 # 使用最新的 macOS runner
14+
timeout-minutes: 60
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: '20'
24+
cache: 'npm'
25+
26+
- name: Install dependencies
27+
run: |
28+
npm ci
29+
cd test/e2e/miniprogram-cli-project
30+
npm ci
31+
32+
- name: Setup React Native dependencies
33+
run: |
34+
cd test/e2e/miniprogram-cli-project/ReactNativeProject
35+
npm ci
36+
37+
- name: Install CocoaPods dependencies
38+
run: |
39+
cd test/e2e/miniprogram-cli-project/ReactNativeProject/ios
40+
pod install --repo-update
41+
42+
- name: Install Detox CLI
43+
run: npm install -g detox-cli
44+
45+
- name: Build Mpx bundle for iOS
46+
run: |
47+
cd test/e2e/miniprogram-cli-project
48+
npm run build:ios
49+
50+
- name: Build iOS app for Detox
51+
run: |
52+
cd test/e2e/miniprogram-cli-project/ReactNativeProject
53+
npm run e2e:build:ios
54+
55+
- name: Run iOS E2E tests
56+
run: |
57+
cd test/e2e/miniprogram-cli-project/ReactNativeProject
58+
# 启动 Metro Bundler 在后台
59+
npm start &
60+
METRO_PID=$!
61+
62+
# 等待 Metro 启动
63+
echo "Waiting for Metro Bundler to start..."
64+
npx wait-on tcp:8081 --timeout 60000
65+
66+
# 运行测试
67+
npm run e2e:test:ios -- --loglevel trace
68+
69+
# 保存退出码
70+
TEST_EXIT_CODE=$?
71+
72+
# 停止 Metro
73+
kill $METRO_PID || true
74+
75+
# 返回测试退出码
76+
exit $TEST_EXIT_CODE
77+
78+
- name: Upload test artifacts (on failure)
79+
if: failure()
80+
uses: actions/upload-artifact@v4
81+
with:
82+
name: e2e-ios-artifacts
83+
path: test/e2e/miniprogram-cli-project/ReactNativeProject/artifacts/
84+
retention-days: 7
85+
86+
e2e-android:
87+
name: E2E Tests (Android)
88+
runs-on: macos-14 # macOS 提供更好的 Android 模拟器性能
89+
timeout-minutes: 60
90+
91+
steps:
92+
- name: Checkout code
93+
uses: actions/checkout@v4
94+
95+
- name: Setup Node.js
96+
uses: actions/setup-node@v4
97+
with:
98+
node-version: '20'
99+
cache: 'npm'
100+
101+
- name: Setup Java
102+
uses: actions/setup-java@v4
103+
with:
104+
distribution: 'corretto'
105+
java-version: '17'
106+
cache: 'gradle'
107+
108+
- name: Install dependencies
109+
run: |
110+
npm ci
111+
cd test/e2e/miniprogram-cli-project
112+
npm ci
113+
114+
- name: Setup React Native dependencies
115+
run: |
116+
cd test/e2e/miniprogram-cli-project/ReactNativeProject
117+
npm ci
118+
119+
- name: Install Detox CLI
120+
run: npm install -g detox-cli
121+
122+
- name: Setup Android SDK
123+
uses: android-actions/setup-android@v3
124+
125+
- name: AVD cache
126+
uses: actions/cache@v4
127+
id: avd-cache
128+
with:
129+
path: |
130+
~/.android/avd/*
131+
~/.android/adb*
132+
key: avd-34
133+
134+
- name: Create AVD and generate snapshot for caching
135+
if: steps.avd-cache.outputs.cache-hit != 'true'
136+
uses: reactivecircus/android-emulator-runner@v2
137+
with:
138+
api-level: 34
139+
arch: x86_64
140+
target: google_apis
141+
force-avd-creation: false
142+
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
143+
disable-animations: true
144+
script: echo "Generated AVD snapshot for caching."
145+
146+
- name: Gradle cache
147+
uses: actions/cache@v4
148+
with:
149+
path: |
150+
~/.gradle/caches
151+
~/.gradle/wrapper
152+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
153+
restore-keys: |
154+
${{ runner.os }}-gradle-
155+
156+
- name: Build Mpx bundle for Android
157+
run: |
158+
cd test/e2e/miniprogram-cli-project
159+
npm run build:android
160+
161+
- name: Build Android app for Detox
162+
run: |
163+
cd test/e2e/miniprogram-cli-project/ReactNativeProject
164+
npm run e2e:build:android
165+
166+
- name: Run Android E2E tests
167+
uses: reactivecircus/android-emulator-runner@v2
168+
with:
169+
api-level: 34
170+
arch: x86_64
171+
target: google_apis
172+
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
173+
disable-animations: true
174+
script: |
175+
cd test/e2e/miniprogram-cli-project/ReactNativeProject
176+
177+
# 启动 Metro Bundler 在后台
178+
npm start &
179+
METRO_PID=$!
180+
181+
# 等待 Metro 启动
182+
echo "Waiting for Metro Bundler to start..."
183+
npx wait-on tcp:8081 --timeout 120000
184+
185+
# 配置 adb 端口转发
186+
adb reverse tcp:8081 tcp:8081
187+
adb reverse tcp:8097 tcp:8097
188+
189+
# 运行测试
190+
npm run e2e:test:android -- --loglevel trace
191+
192+
# 保存退出码
193+
TEST_EXIT_CODE=$?
194+
195+
# 停止 Metro
196+
kill $METRO_PID || true
197+
198+
# 返回测试退出码
199+
exit $TEST_EXIT_CODE
200+
201+
- name: Upload test artifacts (on failure)
202+
if: failure()
203+
uses: actions/upload-artifact@v4
204+
with:
205+
name: e2e-android-artifacts
206+
path: test/e2e/miniprogram-cli-project/ReactNativeProject/artifacts/
207+
retention-days: 7

0 commit comments

Comments
 (0)