Skip to content

Commit 47f1fdd

Browse files
committed
build: run E2E tests for pull requests
1 parent 2f7c1ac commit 47f1fdd

1 file changed

Lines changed: 39 additions & 74 deletions

File tree

.github/workflows/e2e-tests.yml

Lines changed: 39 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ name: E2E Tests
33
on:
44
workflow_dispatch:
55
inputs:
6-
app:
7-
description: 'Specific app to test (leave empty for all apps)'
8-
required: false
9-
type: string
106
platform:
117
description: 'Platform to test'
128
required: false
@@ -16,44 +12,29 @@ on:
1612
- all
1713
- android
1814
- ios
15+
pull_request:
16+
types: [ready_for_review]
17+
branches:
18+
- main
1919

20-
jobs:
21-
discover-apps:
22-
name: Discover Apps
23-
runs-on: ubuntu-22.04
24-
outputs:
25-
apps: ${{ steps.set-apps.outputs.apps }}
26-
steps:
27-
- name: Checkout code
28-
uses: actions/checkout@v4
29-
30-
- name: Discover apps
31-
id: set-apps
32-
run: |
33-
if [ -n "${{ github.event.inputs.app }}" ]; then
34-
apps='["${{ github.event.inputs.app }}"]'
35-
else
36-
# Dynamically discover apps in the /apps directory
37-
apps=$(find apps -maxdepth 1 -mindepth 1 -type d -exec basename {} \; | jq -R . | jq -sc .)
38-
fi
39-
echo "apps=$apps" >> $GITHUB_OUTPUT
40-
echo "Discovered apps: $apps"
20+
permissions:
21+
contents: read
22+
pull-requests: read
4123

24+
jobs:
4225
e2e-android:
43-
name: E2E Android - ${{ matrix.app }}
26+
name: E2E Android
4427
runs-on: ubuntu-22.04
45-
needs: discover-apps
46-
if: ${{ github.event.inputs.platform == 'all' || github.event.inputs.platform == 'android' }}
28+
if: ${{ (github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'main') || (github.event_name == 'workflow_dispatch' && (github.event.inputs.platform == 'all' || github.event.inputs.platform == 'android')) }}
4729
env:
4830
HARNESS_DEBUG: true
49-
strategy:
50-
fail-fast: false
51-
matrix:
52-
app: ${{ fromJson(needs.discover-apps.outputs.apps) }}
5331

5432
steps:
5533
- name: Checkout code
5634
uses: actions/checkout@v4
35+
with:
36+
ref: ${{ github.event.pull_request.head.sha || github.ref }}
37+
fetch-depth: 0
5738

5839
- name: Install pnpm
5940
uses: pnpm/action-setup@v2
@@ -69,8 +50,8 @@ jobs:
6950
- name: Metro cache
7051
uses: actions/cache@v4
7152
with:
72-
path: apps/${{ matrix.app }}/node_modules/.cache/rn-harness/metro-cache
73-
key: metro-cache-${{ hashFiles('apps/${{ matrix.app }}/node_modules/.cache/rn-harness/metro-cache/**/*') }}
53+
path: apps/playground/node_modules/.cache/rn-harness/metro-cache
54+
key: metro-cache-${{ hashFiles('apps/playground/node_modules/.cache/rn-harness/metro-cache/**/*') }}
7455
restore-keys: |
7556
metro-cache
7657
@@ -92,41 +73,39 @@ jobs:
9273
id: cache-apk-restore
9374
uses: actions/cache/restore@v4
9475
with:
95-
path: apps/${{ matrix.app }}/android/app/build/outputs/apk/debug/app-debug.apk
96-
key: apk-${{ matrix.app }}
76+
path: apps/playground/android/app/build/outputs/apk/debug/app-debug.apk
77+
key: apk-playground
9778

9879
- name: Build Android app
9980
if: steps.cache-apk-restore.outputs.cache-hit != 'true'
100-
working-directory: apps/${{ matrix.app }}
81+
working-directory: apps/playground
10182
run: |
102-
pnpm nx run @react-native-harness/${{ matrix.app }}:build-android --tasks=assembleDebug
83+
pnpm nx run @react-native-harness/playground:build-android --tasks=assembleDebug
10384
10485
- name: Save APK to cache
10586
if: steps.cache-apk-restore.outputs.cache-hit != 'true' && success()
10687
uses: actions/cache/save@v4
10788
with:
108-
path: apps/${{ matrix.app }}/android/app/build/outputs/apk/debug/app-debug.apk
109-
key: apk-${{ matrix.app }}
89+
path: apps/playground/android/app/build/outputs/apk/debug/app-debug.apk
90+
key: apk-playground
11091

11192
- name: Run React Native Harness
11293
uses: ./actions/android
11394
with:
11495
app: android/app/build/outputs/apk/debug/app-debug.apk
11596
runner: android
116-
projectRoot: apps/${{ matrix.app }}
97+
projectRoot: apps/playground
11798

11899
e2e-ios:
119-
name: E2E iOS - ${{ matrix.app }}
100+
name: E2E iOS
120101
runs-on: macos-latest
121-
needs: discover-apps
122-
if: ${{ github.event.inputs.platform == 'all' || github.event.inputs.platform == 'ios' }}
123-
strategy:
124-
fail-fast: false
125-
matrix:
126-
app: ${{ fromJson(needs.discover-apps.outputs.apps) }}
102+
if: ${{ (github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'main') || (github.event_name == 'workflow_dispatch' && (github.event.inputs.platform == 'all' || github.event.inputs.platform == 'ios')) }}
127103
steps:
128104
- name: Checkout code
129105
uses: actions/checkout@v4
106+
with:
107+
ref: ${{ github.event.pull_request.head.sha || github.ref }}
108+
fetch-depth: 0
130109

131110
- name: Install pnpm
132111
uses: pnpm/action-setup@v2
@@ -142,8 +121,8 @@ jobs:
142121
- name: Metro cache
143122
uses: actions/cache@v4
144123
with:
145-
path: apps/${{ matrix.app }}/node_modules/.cache/rn-harness/metro-cache
146-
key: metro-cache-${{ hashFiles('apps/${{ matrix.app }}/node_modules/.cache/rn-harness/metro-cache/**/*') }}
124+
path: apps/playground/node_modules/.cache/rn-harness/metro-cache
125+
key: metro-cache-${{ hashFiles('apps/playground/node_modules/.cache/rn-harness/metro-cache/**/*') }}
147126
restore-keys: |
148127
metro-cache
149128
@@ -162,57 +141,43 @@ jobs:
162141
id: cache-app-restore
163142
uses: actions/cache/restore@v4
164143
with:
165-
path: ./apps/${{ matrix.app }}/ios/build/Build/Products/Debug-iphonesimulator/HarnessPlayground.app
166-
key: ios-app-${{ matrix.app }}
144+
path: ./apps/playground/ios/build/Build/Products/Debug-iphonesimulator/HarnessPlayground.app
145+
key: ios-app-playground
167146

168147
- name: CocoaPods cache
169148
if: steps.cache-app-restore.outputs.cache-hit != 'true'
170149
uses: actions/cache@v4
171150
with:
172151
path: |
173-
./apps/${{ matrix.app }}/ios/Pods
152+
./apps/playground/ios/Pods
174153
~/Library/Caches/CocoaPods
175154
~/.cocoapods
176-
key: ${{ matrix.app }}-${{ runner.os }}-pods-${{ hashFiles('./apps/${{ matrix.app }}/ios/Podfile.lock') }}
155+
key: playground-${{ runner.os }}-pods-${{ hashFiles('./apps/playground/ios/Podfile.lock') }}
177156
restore-keys: |
178-
${{ matrix.app }}-${{ runner.os }}-pods-
157+
playground-${{ runner.os }}-pods-
179158
180159
- name: Install CocoaPods
181160
if: steps.cache-app-restore.outputs.cache-hit != 'true'
182-
working-directory: apps/${{ matrix.app }}/ios
161+
working-directory: apps/playground/ios
183162
run: |
184163
pod install
185164
186165
- name: Build iOS app
187166
if: steps.cache-app-restore.outputs.cache-hit != 'true'
188-
working-directory: apps/${{ matrix.app }}
167+
working-directory: apps/playground
189168
run: |
190169
pnpm react-native build-ios --buildFolder ./build --verbose
191170
192171
- name: Save app to cache
193172
if: steps.cache-app-restore.outputs.cache-hit != 'true' && success()
194173
uses: actions/cache/save@v4
195174
with:
196-
path: ./apps/${{ matrix.app }}/ios/build/Build/Products/Debug-iphonesimulator/HarnessPlayground.app
197-
key: ios-app-${{ matrix.app }}
175+
path: ./apps/playground/ios/build/Build/Products/Debug-iphonesimulator/HarnessPlayground.app
176+
key: ios-app-playground
198177

199178
- name: Run React Native Harness
200179
uses: ./actions/ios
201180
with:
202181
app: ios/build/Build/Products/Debug-iphonesimulator/HarnessPlayground.app
203182
runner: ios
204-
projectRoot: apps/${{ matrix.app }}
205-
206-
- name: Take screenshot after E2E tests
207-
if: failure()
208-
run: |
209-
mkdir -p screenshots
210-
xcrun simctl io booted screenshot screenshots/ios-${{ matrix.app }}-after.png
211-
212-
- name: Upload iOS screenshots
213-
if: failure()
214-
uses: actions/upload-artifact@v4
215-
with:
216-
name: ios-screenshots-${{ matrix.app }}
217-
path: screenshots/ios-${{ matrix.app }}-*.png
218-
retention-days: 7
183+
projectRoot: apps/playground

0 commit comments

Comments
 (0)