-
Notifications
You must be signed in to change notification settings - Fork 8
647 lines (551 loc) · 25.9 KB
/
react-native-expo-ci.yml
File metadata and controls
647 lines (551 loc) · 25.9 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
name: React Native Expo CI
on:
pull_request:
paths:
- "react-native-expo/**"
- ".github/workflows/react-native-expo-ci.yml"
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "yarn"
cache-dependency-path: react-native-expo/yarn.lock
- name: Install dependencies
working-directory: react-native-expo
run: yarn install --frozen-lockfile
- name: Run linting
working-directory: react-native-expo
run: yarn lint
build-android:
name: Build Android
runs-on: ubuntu-latest
needs: lint
timeout-minutes: 150
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "yarn"
cache-dependency-path: react-native-expo/yarn.lock
- name: Install dependencies
working-directory: react-native-expo
run: yarn install --frozen-lockfile
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: "17"
- name: Setup Android SDK
uses: android-actions/setup-android@v3
- name: Create .env file (production credentials for builds)
run: |
echo "DITTO_APP_ID=${{ secrets.DITTO_APP_ID }}" > .env
echo "DITTO_PLAYGROUND_TOKEN=${{ secrets.DITTO_PLAYGROUND_TOKEN }}" >> .env
echo "DITTO_AUTH_URL=${{ secrets.DITTO_AUTH_URL }}" >> .env
echo "DITTO_WEBSOCKET_URL=${{ secrets.DITTO_WEBSOCKET_URL }}" >> .env
- name: Cache Gradle dependencies
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
react-native-expo/android/.gradle
key: gradle-expo-${{ runner.os }}-${{ hashFiles('react-native-expo/android/gradle/wrapper/gradle-wrapper.properties', 'react-native-expo/android/**/*.gradle*') }}
restore-keys: |
gradle-expo-${{ runner.os }}-
- name: Prebuild Android project
working-directory: react-native-expo
run: npx expo prebuild --platform android
- name: Build Android APK
working-directory: react-native-expo/android
# Use direct gradlew instead of yarn android to generate unsigned APK required by BrowserStack
# yarn android creates signed builds that don't work with BrowserStack real device testing
run: NODE_ENV=production ./gradlew assembleRelease --no-daemon --console=plain
- name: Upload Android APK artifact
uses: actions/upload-artifact@v4
with:
name: expo-android-apk-${{ github.run_number }}
path: react-native-expo/android/app/build/outputs/apk/release/app-release.apk
retention-days: 1
build-ios:
name: Build iOS
runs-on: macos-latest
needs: lint
timeout-minutes: 150
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "yarn"
cache-dependency-path: react-native-expo/yarn.lock
- name: Install dependencies
working-directory: react-native-expo
run: yarn install --frozen-lockfile
- name: Create .env file (production credentials for builds)
run: |
echo "DITTO_APP_ID=${{ secrets.DITTO_APP_ID }}" > .env
echo "DITTO_PLAYGROUND_TOKEN=${{ secrets.DITTO_PLAYGROUND_TOKEN }}" >> .env
echo "DITTO_AUTH_URL=${{ secrets.DITTO_AUTH_URL }}" >> .env
echo "DITTO_WEBSOCKET_URL=${{ secrets.DITTO_WEBSOCKET_URL }}" >> .env
- name: Cache CocoaPods dependencies
uses: actions/cache@v4
with:
path: |
~/Library/Caches/CocoaPods
~/.cocoapods
key: cocoapods-expo-${{ runner.os }}-${{ hashFiles('react-native-expo/ios/Podfile.lock') }}
restore-keys: |
cocoapods-expo-${{ runner.os }}-
- name: Prebuild iOS project
working-directory: react-native-expo
run: npx expo prebuild --platform ios
- name: Setup Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: "16.4"
- name: Install CocoaPods
working-directory: react-native-expo/ios
run: pod install --repo-update
- name: Build iOS Archive and IPA (for BrowserStack)
working-directory: react-native-expo
run: |
echo "🍎 Building iOS device .ipa for BrowserStack..."
# Use direct xcodebuild instead of yarn ios to generate unsigned IPA required by BrowserStack
# yarn ios creates signed builds for simulators that don't work with BrowserStack real device testing
# Build and archive iOS app for real device
xcodebuild -workspace ios/reactnativeexpo.xcworkspace \
-scheme reactnativeexpo \
-configuration Release \
-destination 'generic/platform=iOS' \
-archivePath ios/build/reactnativeexpo.xcarchive \
archive \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO
echo "📦 Creating unsigned .ipa for BrowserStack..."
# Find the .app bundle from the archive
APP_BUNDLE_PATH=$(find ios/build/reactnativeexpo.xcarchive/Products/Applications -maxdepth 1 -name "*.app" -type d | head -1)
if [ -d "$APP_BUNDLE_PATH" ]; then
echo "✅ iOS app bundle found: $APP_BUNDLE_PATH"
# Create unsigned IPA: Payload/<App>.app zipped as .ipa
mkdir -p ios/build/Payload
cp -R "$APP_BUNDLE_PATH" ios/build/Payload/
(cd ios/build && zip -qry reactnativeexpo-unsigned.ipa Payload && rm -rf Payload)
if [ -f "ios/build/reactnativeexpo-unsigned.ipa" ]; then
echo "✅ Unsigned .ipa created successfully"
ls -la ios/build/reactnativeexpo-unsigned.ipa
else
echo "❌ Failed to create .ipa file"
exit 1
fi
else
echo "❌ iOS app bundle not found in archive"
exit 1
fi
- name: Upload iOS IPA artifact
uses: actions/upload-artifact@v4
with:
name: expo-ios-ipa-${{ github.run_number }}
path: react-native-expo/ios/build/reactnativeexpo-unsigned.ipa
retention-days: 1
browserstack-android:
name: Test Android - BrowserStack Maestro
runs-on: ubuntu-latest
needs: [build-android]
timeout-minutes: 150
outputs:
build_id: ${{ steps.execute-tests.outputs.build_id }}
status: ${{ job.status }}
# TODO: BrowserStack Android Maestro API environment variables don't work (confirmed by BS staff)
# On their roadmap with estimate: Oct 2025. Will revert to setEnvVariables when ready.
# Using sed workaround to replace ${MAESTRO_DITTO_CLOUD_TASK_TITLE} with actual task name in test files
steps:
- uses: actions/checkout@v4
- name: Download Android APK
uses: actions/download-artifact@v4
with:
name: expo-android-apk-${{ github.run_number }}
path: ./artifacts/
- name: Get BrowserStack build info (Android)
id: build-info-android
uses: ./.github/actions/generate-browserstack-names
with:
platform-suffix: ' (Android)'
title-max-length: '90'
commit-max-length: '130'
- name: Seed, create test suite, upload, and execute Android Maestro tests
id: execute-tests
uses: nick-fields/retry@v3
with:
max_attempts: 5
timeout_minutes: 20
retry_wait_seconds: 900
command: |
# Seed test task to Ditto Cloud
echo "Seeding test task to Ditto Cloud..."
TIMESTAMP=$(date +%s)
INVERTED_TIMESTAMP=$((9999999999 - TIMESTAMP))
SEED_RESPONSE=$(curl -s -w "\n%{http_code}" -X POST \
-H 'Content-type: application/json' \
-H "Authorization: Bearer ${{ secrets.DITTO_API_KEY }}" \
-d "{
\"statement\": \"INSERT INTO tasks DOCUMENTS (:newTask) ON ID CONFLICT DO UPDATE\",
\"args\": {
\"newTask\": {
\"_id\": \"${INVERTED_TIMESTAMP}_react-native-expo_ci_test_${{ github.run_id }}_${{ github.run_number }}\",
\"title\": \"${INVERTED_TIMESTAMP}_react-native-expo_ci_test_${{ github.run_id }}_${{ github.run_number }}\",
\"done\": false,
\"deleted\": false
}
}
}" \
"https://${{ secrets.DITTO_API_URL }}/api/v4/store/execute")
HTTP_CODE=$(echo "$SEED_RESPONSE" | tail -n1)
BODY=$(echo "$SEED_RESPONSE" | sed '$d')
if [ "$HTTP_CODE" -eq 200 ] || [ "$HTTP_CODE" -eq 201 ]; then
TASK_TITLE="${INVERTED_TIMESTAMP}_react-native-expo_ci_test_${{ github.run_id }}_${{ github.run_number }}"
echo "Seeded task: $TASK_TITLE"
else
echo "Error: Failed to seed task. HTTP Status: $HTTP_CODE"
echo "Response: $BODY"
exit 1
fi
# Upload APK to BrowserStack
echo "Uploading APK to BrowserStack..."
response=$(curl -u "${{ secrets.BROWSERSTACK_USERNAME }}:${{ secrets.BROWSERSTACK_ACCESS_KEY }}" \
-X POST "https://api-cloud.browserstack.com/app-automate/maestro/v2/app" \
-F "file=@./artifacts/app-release.apk" \
-F "custom_id=ReactNative-Expo-Android-${{ github.run_id }}")
APP_URL=$(echo $response | yq eval -p=json '.app_url')
if [ -z "$APP_URL" ] || [ "$APP_URL" = "null" ]; then
echo "Error: Failed to upload APK"
echo "Response: $response"
exit 1
fi
echo "APK uploaded: $APP_URL"
# Create Maestro test suite ZIP with sed replacement
cd react-native-expo
rm -rf maestro-tests
mkdir maestro-tests
# Replace MAESTRO_DITTO_CLOUD_TASK_TITLE with actual seeded task name (BrowserStack Android API bug workaround)
sed "s/\${MAESTRO_DITTO_CLOUD_TASK_TITLE}/$TASK_TITLE/g" \
.maestro/flows/01-app-launch-and-seeded-tasks-android.yaml > maestro-tests/01-app-launch-and-seeded-tasks-android.yaml
# Also create flows/ subfolder for organization
mkdir maestro-tests/flows
cp maestro-tests/01-app-launch-and-seeded-tasks-android.yaml maestro-tests/flows/
# Create ZIP with proper structure
zip -r maestro-tests.zip maestro-tests -x "*.DS_Store"
cd ..
# Upload Maestro test suite to BrowserStack
echo "Uploading test suite to BrowserStack..."
response=$(curl -u "${{ secrets.BROWSERSTACK_USERNAME }}:${{ secrets.BROWSERSTACK_ACCESS_KEY }}" \
-X POST "https://api-cloud.browserstack.com/app-automate/maestro/v2/test-suite" \
-F "file=@react-native-expo/maestro-tests.zip" \
-F "custom_id=ReactNative-Expo-Tests-${{ github.run_id }}")
TEST_SUITE_URL=$(echo $response | yq eval -p=json '.test_suite_url')
if [ -z "$TEST_SUITE_URL" ] || [ "$TEST_SUITE_URL" = "null" ]; then
echo "Error: Failed to upload test suite"
echo "Response: $response"
exit 1
fi
echo "Test suite uploaded: $TEST_SUITE_URL"
# Execute tests
# Load devices from centralized config
DEVICES=$(yq eval -o=json -I=0 '.["react-native-expo"].android.devices' .github/browserstack-devices.yml)
echo "Loaded devices: $DEVICES"
response=$(curl -u "${{ secrets.BROWSERSTACK_USERNAME }}:${{ secrets.BROWSERSTACK_ACCESS_KEY }}" \
-X POST "https://api-cloud.browserstack.com/app-automate/maestro/v2/android/build" \
-H "Content-Type: application/json" \
-d "{
\"app\": \"$APP_URL\",
\"testSuite\": \"$TEST_SUITE_URL\",
\"project\": \"${{ steps.build-info-android.outputs.project-name }}\",
\"buildName\": \"${{ steps.build-info-android.outputs.build-name }}\",
\"buildTag\": \"${{ github.head_ref || github.ref_name }}\",
\"devices\": $DEVICES,
\"execute\": [\"01-app-launch-and-seeded-tasks-android.yaml\"],
\"deviceLogs\": true,
\"networkLogs\": true,
\"video\": true
}")
echo "Execution response: $response"
build_id=$(echo $response | yq eval '.build_id')
if [ "$build_id" = "null" ] || [ -z "$build_id" ]; then
echo "❌ Failed to create BrowserStack build"
echo "Response: $response"
exit 1
fi
echo "BrowserStack Build ID: $build_id"
echo "build_id=$build_id" >> $GITHUB_OUTPUT
# Wait for test completion and get results
MAX_WAIT_TIME=1080 # 18 minutes
CHECK_INTERVAL=10 # Check every 10 seconds
ELAPSED=0
echo "⏳ Waiting for test execution to complete..."
while [ $ELAPSED -lt $MAX_WAIT_TIME ]; do
response=$(curl -s -u "${{ secrets.BROWSERSTACK_USERNAME }}:${{ secrets.BROWSERSTACK_ACCESS_KEY }}" \
"https://api-cloud.browserstack.com/app-automate/maestro/v2/builds/$build_id")
status=$(echo $response | yq eval '.status')
echo "Test status: $status (${ELAPSED}s elapsed)"
if [ "$status" = "passed" ] || [ "$status" = "failed" ]; then
echo "Tests completed with status: $status"
echo $response | jq '.'
if [ "$status" = "failed" ]; then
echo "❌ Android Maestro tests failed!"
exit 1
else
echo "✅ Android Maestro tests passed!"
fi
break
elif [ "$status" = "error" ]; then
echo "❌ BrowserStack reported build error. Fetching session details..."
echo $response | jq '.'
echo $response | yq eval '.devices[]?.sessions[]?.id' 2>/dev/null | while read sid; do
if [ -n "$sid" ]; then
echo "Session $sid details:"
curl -s -u "${{ secrets.BROWSERSTACK_USERNAME }}:${{ secrets.BROWSERSTACK_ACCESS_KEY }}" \
"https://api-cloud.browserstack.com/app-automate/maestro/v2/builds/$build_id/sessions/$sid" | jq '.'
fi
done
exit 1
fi
sleep $CHECK_INTERVAL
ELAPSED=$((ELAPSED + CHECK_INTERVAL))
done
if [ $ELAPSED -ge $MAX_WAIT_TIME ]; then
echo "❌ Tests timed out after ${MAX_WAIT_TIME}s (18 minutes)"
exit 1
fi
browserstack-ios:
name: Test iOS - BrowserStack Maestro
runs-on: ubuntu-latest
needs: [build-ios]
timeout-minutes: 150
outputs:
build_id: ${{ steps.execute-tests.outputs.build_id }}
status: ${{ job.status }}
steps:
- uses: actions/checkout@v4
- name: Download iOS IPA
uses: actions/download-artifact@v4
with:
name: expo-ios-ipa-${{ github.run_number }}
path: ./artifacts/
- name: Get BrowserStack build info (iOS)
id: build-info-ios
uses: ./.github/actions/generate-browserstack-names
with:
platform-suffix: ' (iOS)'
title-max-length: '90'
commit-max-length: '130'
- name: Seed, upload, and execute iOS Maestro tests on BrowserStack
id: execute-tests
uses: nick-fields/retry@v3
with:
max_attempts: 5
timeout_minutes: 20
retry_wait_seconds: 900
command: |
# Seed test task to Ditto Cloud
echo "Seeding test task to Ditto Cloud..."
TIMESTAMP=$(date +%s)
INVERTED_TIMESTAMP=$((9999999999 - TIMESTAMP))
SEED_RESPONSE=$(curl -s -w "\n%{http_code}" -X POST \
-H 'Content-type: application/json' \
-H "Authorization: Bearer ${{ secrets.DITTO_API_KEY }}" \
-d "{
\"statement\": \"INSERT INTO tasks DOCUMENTS (:newTask) ON ID CONFLICT DO UPDATE\",
\"args\": {
\"newTask\": {
\"_id\": \"${INVERTED_TIMESTAMP}_react-native-expo_ci_test_${{ github.run_id }}_${{ github.run_number }}\",
\"title\": \"${INVERTED_TIMESTAMP}_react-native-expo_ci_test_${{ github.run_id }}_${{ github.run_number }}\",
\"done\": false,
\"deleted\": false
}
}
}" \
"https://${{ secrets.DITTO_API_URL }}/api/v4/store/execute")
HTTP_CODE=$(echo "$SEED_RESPONSE" | tail -n1)
BODY=$(echo "$SEED_RESPONSE" | sed '$d')
if [ "$HTTP_CODE" -eq 200 ] || [ "$HTTP_CODE" -eq 201 ]; then
TASK_TITLE="${INVERTED_TIMESTAMP}_react-native-expo_ci_test_${{ github.run_id }}_${{ github.run_number }}"
echo "Seeded task: $TASK_TITLE"
else
echo "Error: Failed to seed task. HTTP Status: $HTTP_CODE"
echo "Response: $BODY"
exit 1
fi
# Upload IPA to BrowserStack
echo "Uploading IPA to BrowserStack..."
response=$(curl -u "${{ secrets.BROWSERSTACK_USERNAME }}:${{ secrets.BROWSERSTACK_ACCESS_KEY }}" \
-X POST "https://api-cloud.browserstack.com/app-automate/maestro/v2/app" \
-F "file=@./artifacts/reactnativeexpo-unsigned.ipa" \
-F "custom_id=ReactNative-Expo-iOS-${{ github.run_id }}")
APP_URL=$(echo $response | yq eval -p=json '.app_url')
if [ -z "$APP_URL" ] || [ "$APP_URL" = "null" ]; then
echo "Error: Failed to upload IPA"
echo "Response: $response"
exit 1
fi
echo "IPA uploaded: $APP_URL"
# Create Maestro test suite ZIP
cd react-native-expo
rm -rf maestro-tests
mkdir maestro-tests
# Copy only iOS-specific tests to root level
cp .maestro/flows/01-app-launch-and-seeded-tasks-ios.yaml maestro-tests/
# Also create flows/ subfolder for organization
mkdir maestro-tests/flows
cp .maestro/flows/01-app-launch-and-seeded-tasks-ios.yaml maestro-tests/flows/
# Create ZIP with proper structure
zip -r maestro-tests.zip maestro-tests -x "*.DS_Store"
cd ..
# Upload Maestro test suite to BrowserStack
echo "Uploading test suite to BrowserStack..."
response=$(curl -u "${{ secrets.BROWSERSTACK_USERNAME }}:${{ secrets.BROWSERSTACK_ACCESS_KEY }}" \
-X POST "https://api-cloud.browserstack.com/app-automate/maestro/v2/test-suite" \
-F "file=@react-native-expo/maestro-tests.zip" \
-F "custom_id=ReactNative-Expo-iOS-Tests-${{ github.run_id }}")
TEST_SUITE_URL=$(echo $response | yq eval -p=json '.test_suite_url')
if [ -z "$TEST_SUITE_URL" ] || [ "$TEST_SUITE_URL" = "null" ]; then
echo "Error: Failed to upload test suite"
echo "Response: $response"
exit 1
fi
echo "Test suite uploaded: $TEST_SUITE_URL"
# Execute tests
# Load devices from centralized config
DEVICES=$(yq eval -o=json -I=0 '.["react-native-expo"].ios.devices' .github/browserstack-devices.yml)
echo "Loaded devices: $DEVICES"
response=$(curl -u "${{ secrets.BROWSERSTACK_USERNAME }}:${{ secrets.BROWSERSTACK_ACCESS_KEY }}" \
-X POST "https://api-cloud.browserstack.com/app-automate/maestro/v2/ios/build" \
-H "Content-Type: application/json" \
-d "{
\"app\": \"$APP_URL\",
\"testSuite\": \"$TEST_SUITE_URL\",
\"project\": \"${{ steps.build-info-ios.outputs.project-name }}\",
\"buildName\": \"${{ steps.build-info-ios.outputs.build-name }}\",
\"buildTag\": \"${{ github.head_ref || github.ref_name }}\",
\"devices\": $DEVICES,
\"execute\": [\"01-app-launch-and-seeded-tasks-ios.yaml\"],
\"setEnvVariables\": {
\"MAESTRO_DITTO_CLOUD_TASK_TITLE\": \"$TASK_TITLE\"
},
\"deviceLogs\": true,
\"networkLogs\": true,
\"video\": true
}")
echo "Execution response: $response"
build_id=$(echo $response | yq eval '.build_id')
if [ "$build_id" = "null" ] || [ -z "$build_id" ]; then
echo "❌ Failed to create BrowserStack build"
echo "Response: $response"
exit 1
fi
echo "BrowserStack Build ID: $build_id"
echo "build_id=$build_id" >> $GITHUB_OUTPUT
# Wait for test completion and get results
MAX_WAIT_TIME=1080 # 18 minutes
CHECK_INTERVAL=10 # Check every 10 seconds
ELAPSED=0
echo "⏳ Waiting for test execution to complete..."
while [ $ELAPSED -lt $MAX_WAIT_TIME ]; do
response=$(curl -s -u "${{ secrets.BROWSERSTACK_USERNAME }}:${{ secrets.BROWSERSTACK_ACCESS_KEY }}" \
"https://api-cloud.browserstack.com/app-automate/maestro/v2/builds/$build_id")
status=$(echo $response | yq eval '.status')
echo "Test status: $status (${ELAPSED}s elapsed)"
if [ "$status" = "passed" ] || [ "$status" = "failed" ]; then
echo "Tests completed with status: $status"
echo $response | jq '.'
if [ "$status" = "failed" ]; then
echo "❌ iOS Maestro tests failed!"
exit 1
else
echo "✅ iOS Maestro tests passed!"
fi
break
elif [ "$status" = "error" ]; then
echo "❌ BrowserStack reported build error. Fetching session details..."
echo $response | jq '.'
echo $response | yq eval '.devices[]?.sessions[]?.id' 2>/dev/null | while read sid; do
if [ -n "$sid" ]; then
echo "Session $sid details:"
curl -s -u "${{ secrets.BROWSERSTACK_USERNAME }}:${{ secrets.BROWSERSTACK_ACCESS_KEY }}" \
"https://api-cloud.browserstack.com/app-automate/maestro/v2/builds/$build_id/sessions/$sid" | jq '.'
fi
done
exit 1
fi
sleep $CHECK_INTERVAL
ELAPSED=$((ELAPSED + CHECK_INTERVAL))
done
if [ $ELAPSED -ge $MAX_WAIT_TIME ]; then
echo "❌ Tests timed out after ${MAX_WAIT_TIME}s (18 minutes)"
exit 1
fi
summary:
name: CI Report
runs-on: ubuntu-latest
needs: [browserstack-android, browserstack-ios]
if: always()
steps:
- name: Generate BrowserStack Summary
run: |
echo "## 📱 React Native Expo - BrowserStack Maestro Test Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Android results
echo "### Android Tests" >> $GITHUB_STEP_SUMMARY
ANDROID_BUILD_ID="${{ needs.browserstack-android.outputs.build_id }}"
ANDROID_RESULT="${{ needs.browserstack-android.result }}"
if [ -n "$ANDROID_BUILD_ID" ] && [ "$ANDROID_BUILD_ID" != "null" ]; then
if [ "$ANDROID_RESULT" = "success" ]; then
echo "✅ **Status:** Passed" >> $GITHUB_STEP_SUMMARY
else
echo "❌ **Status:** Failed" >> $GITHUB_STEP_SUMMARY
fi
echo "🔗 **[View Dashboard](https://app-automate.browserstack.com/dashboard/v2/builds/$ANDROID_BUILD_ID/)**" >> $GITHUB_STEP_SUMMARY
echo "Build ID: \`$ANDROID_BUILD_ID\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
else
echo "❌ **Status:** Failed (No build created)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
fi
# iOS results
echo "### iOS Tests" >> $GITHUB_STEP_SUMMARY
IOS_BUILD_ID="${{ needs.browserstack-ios.outputs.build_id }}"
IOS_RESULT="${{ needs.browserstack-ios.result }}"
if [ -n "$IOS_BUILD_ID" ] && [ "$IOS_BUILD_ID" != "null" ]; then
if [ "$IOS_RESULT" = "success" ]; then
echo "✅ **Status:** Passed" >> $GITHUB_STEP_SUMMARY
else
echo "❌ **Status:** Failed" >> $GITHUB_STEP_SUMMARY
fi
echo "🔗 **[View Dashboard](https://app-automate.browserstack.com/dashboard/v2/builds/$IOS_BUILD_ID/)**" >> $GITHUB_STEP_SUMMARY
echo "Build ID: \`$IOS_BUILD_ID\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
else
echo "❌ **Status:** Failed (No build created)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
fi
# Summary
echo "---" >> $GITHUB_STEP_SUMMARY
if [ "$ANDROID_RESULT" = "success" ] && [ "$IOS_RESULT" = "success" ]; then
echo "✅ **Overall Result:** All tests passed" >> $GITHUB_STEP_SUMMARY
else
echo "⚠️ **Overall Result:** Some tests failed" >> $GITHUB_STEP_SUMMARY
fi