forked from MetaMask/metamask-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-android-upload-to-browserstack.yml
More file actions
617 lines (530 loc) · 27.4 KB
/
build-android-upload-to-browserstack.yml
File metadata and controls
617 lines (530 loc) · 27.4 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
# This workflow creates two non E2E Android Builds and uploads to BrowserStack
# Build 1: With ADDITIONAL_SRP_1 and PREDEFINED_PASSWORD (pre-imported wallet) using build_android_main_rc
# Build 2: Without these environment variables (fresh wallet) using build_android_main_rc
name: Build Android Dual Versions and Upload to BrowserStack
on:
workflow_call:
inputs:
browserstack_app_url_android_onboarding:
required: false
type: string
description: 'BrowserStack Android Onboarding App URL (bs://...)'
browserstack_app_url_android_imported_wallet:
required: false
type: string
description: 'BrowserStack Android Imported Wallet App URL (bs://...)'
outputs:
with-srp-browserstack-url:
description: 'BrowserStack URL for with-SRP version'
value: ${{ jobs.download-and-upload-to-browserstack.outputs.with-srp-browserstack-url }}
without-srp-browserstack-url:
description: 'BrowserStack URL for without-SRP version'
value: ${{ jobs.download-and-upload-to-browserstack.outputs.without-srp-browserstack-url }}
with-srp-app-id:
description: 'BrowserStack App ID for with-SRP version'
value: ${{ jobs.download-and-upload-to-browserstack.outputs.with-srp-app-id }}
without-srp-app-id:
description: 'BrowserStack App ID for without-SRP version'
value: ${{ jobs.download-and-upload-to-browserstack.outputs.without-srp-app-id }}
with-srp-version:
description: 'App version for with-SRP build'
value: ${{ jobs.download-and-upload-to-browserstack.outputs.with-srp-version }}
without-srp-version:
description: 'App version for without-SRP build'
value: ${{ jobs.download-and-upload-to-browserstack.outputs.without-srp-version }}
workflow_dispatch:
inputs:
description:
description: 'Optional description for this build run'
required: false
type: string
permissions:
contents: read
id-token: write
env:
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
BITRISE_APP_ID: ${{ secrets.BITRISE_APP_ID }}
BITRISE_BUILD_TRIGGER_TOKEN: ${{ secrets.BITRISE_BUILD_TRIGGER_TOKEN }}
BITRISE_API_TOKEN: ${{ secrets.BITRISE_API_TOKEN }}
jobs:
check-builds-needed:
name: Check if Android builds are needed
runs-on: ubuntu-latest
outputs:
builds-needed: ${{ steps.check-builds.outputs.builds-needed }}
steps:
- name: Check if builds are needed
id: check-builds
run: |
# Check if any BS URLs are provided via workflow inputs
if [ -n "${{ inputs.browserstack_app_url_android_onboarding }}" ] || [ -n "${{ inputs.browserstack_app_url_android_imported_wallet }}" ]; then
echo "builds-needed=false" >> "$GITHUB_OUTPUT"
echo "Skipping Android builds - BS URLs provided via workflow inputs"
else
echo "builds-needed=true" >> "$GITHUB_OUTPUT"
echo "Android builds needed - no BS URLs provided"
fi
trigger-android-with-srp-build:
name: Trigger Android with-SRP Build on Bitrise
runs-on: ubuntu-latest
needs: [check-builds-needed]
env:
METAMASK_WORKFLOW: build_android_main_rc
outputs:
build-id: ${{ steps.trigger-build.outputs.build-id }}
build-slug: ${{ steps.trigger-build.outputs.build-slug }}
steps:
- name: Trigger Android with-SRP Build on Bitrise
id: trigger-build
if: needs.check-builds-needed.outputs.builds-needed == 'true'
run: |
echo "Triggering Android with-SRP build on Bitrise..."
echo "Workflow: $METAMASK_WORKFLOW"
echo "BITRISE_APP_ID: $BITRISE_APP_ID"
echo "Current branch: ${{ github.ref_name }}"
# Validate required environment variables
if [[ -z "$BITRISE_APP_ID" ]]; then
echo "Error: BITRISE_APP_ID is not set"
exit 1
fi
if [[ -z "$BITRISE_BUILD_TRIGGER_TOKEN" ]]; then
echo "Error: BITRISE_BUILD_TRIGGER_TOKEN is not set"
exit 1
fi
if [[ -z "$BITRISE_API_TOKEN" ]]; then
echo "Error: BITRISE_API_TOKEN is not set"
exit 1
fi
# Set environment variables for with-SRP build
ENV_VARS='[
{
"mapped_to": "ADDITIONAL_SRP_1",
"value": "'"${{ secrets.IN_BUILD_SRP }}"'",
"is_expand": true
},
{
"mapped_to": "PREDEFINED_PASSWORD",
"value": "'"${{ secrets.E2E_PASSWORD }}"'",
"is_expand": true
},
{
"mapped_to": "DISABLE_NOTIFICATION_PROMPT",
"value": "true",
"is_expand": true
}
]'
CUSTOM_ID="MetaMask-Android-With-SRP-${{ github.run_id }}"
# Trigger Android workflow
BUILD_RESPONSE=$(curl -s -X POST \
"https://app.bitrise.io/app/$BITRISE_APP_ID/build/start.json" \
-H "Content-Type: application/json" \
-d '{
"build_params": {
"branch": "${{ github.ref_name }}",
"workflow_id": "${{ env.METAMASK_WORKFLOW }}",
"commit_message": "Triggered by Android Dual Versions workflow - Build with Predefined-SRP",
"environments": '"$ENV_VARS"',
"custom_id": "'"$CUSTOM_ID"'"
},
"hook_info": {
"type": "bitrise",
"build_trigger_token": "'"$BITRISE_BUILD_TRIGGER_TOKEN"'"
},
"triggered_by": "GitHub Actions Android Dual Versions - Build with Predefined-SRP"
}')
echo "Build response: $BUILD_RESPONSE"
BUILD_SLUG=$(echo "$BUILD_RESPONSE" | jq -r '.build_slug')
echo "Build slug: $BUILD_SLUG"
if [[ -z "$BUILD_SLUG" || "$BUILD_SLUG" == "null" ]]; then
echo "Error: Failed to get build slug"
echo "Full response: $BUILD_RESPONSE"
exit 1
fi
# Wait for the workflow to complete
echo "Waiting for $METAMASK_WORKFLOW to complete..."
TIMEOUT=1800 # 30 minutes
ELAPSED=0
while [ $ELAPSED -lt $TIMEOUT ]; do
BUILD_RESPONSE=$(curl -s -H "Authorization: $BITRISE_API_TOKEN" \
"https://api.bitrise.io/v0.1/apps/$BITRISE_APP_ID/builds/$BUILD_SLUG")
BUILD_STATUS=$(echo "$BUILD_RESPONSE" | jq -r '.data.status')
echo "Build status: $BUILD_STATUS (elapsed: ${ELAPSED}s)"
# Check for successful completion (status 1 or success/succeeded)
if [ "$BUILD_STATUS" = "1" ] || [ "$BUILD_STATUS" = "success" ] || [ "$BUILD_STATUS" = "succeeded" ]; then
echo "Build completed successfully"
break
elif [ "$BUILD_STATUS" = "0" ] || [ "$BUILD_STATUS" = "in_progress" ] || [ "$BUILD_STATUS" = "running" ]; then
echo "Build is in progress..."
elif [ "$BUILD_STATUS" = "2" ] || [ "$BUILD_STATUS" = "failed" ] || [ "$BUILD_STATUS" = "aborted" ]; then
echo "Build failed with status: $BUILD_STATUS"
exit 1
else
echo "Unknown build status: $BUILD_STATUS"
fi
sleep 30
ELAPSED=$((ELAPSED + 30))
done
if [ "$ELAPSED" -ge "$TIMEOUT" ]; then
echo "Timeout waiting for build to complete"
echo "Final build status: $BUILD_STATUS"
echo "Build slug: $BUILD_SLUG"
exit 1
fi
# Get the build ID from the completed build
BUILD_ID=$(echo "$BUILD_RESPONSE" | jq -r '.data.slug')
if [[ -z "$BUILD_ID" || "$BUILD_ID" == "null" ]]; then
echo "Error: Failed to get build ID"
exit 1
fi
echo "Build ID: $BUILD_ID"
echo "Build Slug: $BUILD_SLUG"
# Set outputs
{
echo "build-id=$BUILD_ID"
echo "build-slug=$BUILD_SLUG"
} >> "$GITHUB_OUTPUT"
trigger-android-without-srp-build:
name: Trigger Android without-SRP Build on Bitrise
runs-on: ubuntu-latest
needs: [check-builds-needed]
env:
METAMASK_WORKFLOW: build_android_main_rc
outputs:
build-id: ${{ steps.trigger-build.outputs.build-id }}
build-slug: ${{ steps.trigger-build.outputs.build-slug }}
steps:
- name: Trigger Android without-SRP Build on Bitrise
id: trigger-build
if: needs.check-builds-needed.outputs.builds-needed == 'true'
run: |
echo "Triggering Android without-SRP build on Bitrise..."
echo "Workflow: $METAMASK_WORKFLOW"
echo "BITRISE_APP_ID: $BITRISE_APP_ID"
echo "Current branch: ${{ github.ref_name }}"
# Validate required environment variables
if [[ -z "$BITRISE_APP_ID" ]]; then
echo "Error: BITRISE_APP_ID is not set"
exit 1
fi
if [[ -z "$BITRISE_BUILD_TRIGGER_TOKEN" ]]; then
echo "Error: BITRISE_BUILD_TRIGGER_TOKEN is not set"
exit 1
fi
if [[ -z "$BITRISE_API_TOKEN" ]]; then
echo "Error: BITRISE_API_TOKEN is not set"
exit 1
fi
# Set environment variables for without-SRP build
ENV_VARS='[
{
"mapped_to": "DISABLE_NOTIFICATION_PROMPT",
"value": "true",
"is_expand": true
}
]'
CUSTOM_ID="MetaMask-Android-Without-SRP-${{ github.run_id }}"
# Trigger Android workflow
BUILD_RESPONSE=$(curl -s -X POST \
"https://app.bitrise.io/app/$BITRISE_APP_ID/build/start.json" \
-H "Content-Type: application/json" \
-d '{
"build_params": {
"branch": "${{ github.ref_name }}",
"workflow_id": "${{ env.METAMASK_WORKFLOW }}",
"commit_message": "Triggered by Android Dual Versions workflow - Build without Predefined-SRP",
"environments": '"$ENV_VARS"',
"custom_id": "'"$CUSTOM_ID"'"
},
"hook_info": {
"type": "bitrise",
"build_trigger_token": "'"$BITRISE_BUILD_TRIGGER_TOKEN"'"
},
"triggered_by": "GitHub Actions Android Dual Versions - Build without Predefined-SRP"
}')
echo "Build response: $BUILD_RESPONSE"
BUILD_SLUG=$(echo "$BUILD_RESPONSE" | jq -r '.build_slug')
echo "Build slug: $BUILD_SLUG"
if [[ -z "$BUILD_SLUG" || "$BUILD_SLUG" == "null" ]]; then
echo "Error: Failed to get build slug"
echo "Full response: $BUILD_RESPONSE"
exit 1
fi
# Wait for the workflow to complete
echo "Waiting for $METAMASK_WORKFLOW to complete..."
TIMEOUT=1800 # 30 minutes
ELAPSED=0
while [ $ELAPSED -lt $TIMEOUT ]; do
BUILD_RESPONSE=$(curl -s -H "Authorization: $BITRISE_API_TOKEN" \
"https://api.bitrise.io/v0.1/apps/$BITRISE_APP_ID/builds/$BUILD_SLUG")
BUILD_STATUS=$(echo "$BUILD_RESPONSE" | jq -r '.data.status')
echo "Build status: $BUILD_STATUS (elapsed: ${ELAPSED}s)"
# Check for successful completion (status 1 or success/succeeded)
if [ "$BUILD_STATUS" = "1" ] || [ "$BUILD_STATUS" = "success" ] || [ "$BUILD_STATUS" = "succeeded" ]; then
echo "Build completed successfully"
break
elif [ "$BUILD_STATUS" = "0" ] || [ "$BUILD_STATUS" = "in_progress" ] || [ "$BUILD_STATUS" = "running" ]; then
echo "Build is in progress..."
elif [ "$BUILD_STATUS" = "2" ] || [ "$BUILD_STATUS" = "failed" ] || [ "$BUILD_STATUS" = "aborted" ]; then
echo "Build failed with status: $BUILD_STATUS"
exit 1
else
echo "Unknown build status: $BUILD_STATUS"
fi
sleep 30
ELAPSED=$((ELAPSED + 30))
done
if [ "$ELAPSED" -ge "$TIMEOUT" ]; then
echo "Timeout waiting for build to complete"
echo "Final build status: $BUILD_STATUS"
echo "Build slug: $BUILD_SLUG"
exit 1
fi
# Get the build ID from the completed build
BUILD_ID=$(echo "$BUILD_RESPONSE" | jq -r '.data.slug')
if [[ -z "$BUILD_ID" || "$BUILD_ID" == "null" ]]; then
echo "Error: Failed to get build ID"
exit 1
fi
echo "Build ID: $BUILD_ID"
echo "Build Slug: $BUILD_SLUG"
# Set outputs
{
echo "build-id=$BUILD_ID"
echo "build-slug=$BUILD_SLUG"
} >> "$GITHUB_OUTPUT"
download-and-upload-to-browserstack:
name: Download APKs and Upload to BrowserStack
runs-on: ubuntu-latest
needs: [check-builds-needed, trigger-android-with-srp-build, trigger-android-without-srp-build]
if: (needs.trigger-android-with-srp-build.result == 'success' || needs.trigger-android-with-srp-build.result == 'partial_success') && (needs.trigger-android-without-srp-build.result == 'success' || needs.trigger-android-without-srp-build.result == 'partial_success')
outputs:
with-srp-browserstack-url: ${{ steps.browserstack-upload.outputs.with-srp-browserstack-url }}
without-srp-browserstack-url: ${{ steps.browserstack-upload.outputs.without-srp-browserstack-url }}
with-srp-app-id: ${{ steps.browserstack-upload.outputs.with-srp-app-id }}
without-srp-app-id: ${{ steps.browserstack-upload.outputs.without-srp-app-id }}
with-srp-version: ${{ steps.browserstack-upload.outputs.with-srp-version }}
without-srp-version: ${{ steps.browserstack-upload.outputs.without-srp-version }}
steps:
- name: Checkout code
if: needs.check-builds-needed.outputs.builds-needed == 'true'
uses: actions/checkout@v4
- name: Download and Upload APKs to BrowserStack
if: needs.check-builds-needed.outputs.builds-needed == 'true'
id: browserstack-upload
env:
BITRISE_APP_ID: ${{ env.BITRISE_APP_ID }}
BITRISE_API_TOKEN: ${{ env.BITRISE_API_TOKEN }}
BROWSERSTACK_USERNAME: ${{ env.BROWSERSTACK_USERNAME }}
BROWSERSTACK_ACCESS_KEY: ${{ env.BROWSERSTACK_ACCESS_KEY }}
run: |
set +e # Don't exit on error - continue to try both APKs
echo "Downloading APKs from Bitrise and uploading to BrowserStack..."
# Initialize variables to avoid undefined references
WITH_SRP_APP_URL=""
WITHOUT_SRP_APP_URL=""
# Initialize upload status outputs
{
echo "with-srp-apk-uploaded=false"
echo "without-srp-apk-uploaded=false"
} >> "$GITHUB_OUTPUT"
# Get build IDs from job outputs
WITH_SRP_BUILD_ID="${{ needs.trigger-android-with-srp-build.outputs.build-id }}"
WITHOUT_SRP_BUILD_ID="${{ needs.trigger-android-without-srp-build.outputs.build-id }}"
echo "With-SRP build ID: $WITH_SRP_BUILD_ID"
echo "Without-SRP build ID: $WITHOUT_SRP_BUILD_ID"
# Download with-SRP APK
if [ -n "$WITH_SRP_BUILD_ID" ]; then
echo "Downloading with-SRP APK..."
echo "Build ID: $WITH_SRP_BUILD_ID"
echo "App ID: $BITRISE_APP_ID"
WITH_SRP_ARTIFACTS=$(curl -s -w "\nHTTP_STATUS:%{http_code}" -H "Authorization: $BITRISE_API_TOKEN" \
"https://api.bitrise.io/v0.1/apps/$BITRISE_APP_ID/builds/$WITH_SRP_BUILD_ID/artifacts")
# Extract HTTP status code
HTTP_STATUS=$(echo "$WITH_SRP_ARTIFACTS" | grep "HTTP_STATUS:" | cut -d: -f2)
WITH_SRP_ARTIFACTS=$(echo "$WITH_SRP_ARTIFACTS" | sed '/HTTP_STATUS:/d')
echo "HTTP Status: $HTTP_STATUS"
# Validate JSON response
if ! echo "$WITH_SRP_ARTIFACTS" | jq empty 2>/dev/null; then
echo "Error: Invalid JSON response from Bitrise API (HTTP $HTTP_STATUS)"
echo "Response (first 500 chars): ${WITH_SRP_ARTIFACTS:0:500}"
exit 1
fi
# Debug: Show all artifact titles for troubleshooting
echo "All artifact titles:"
echo "$WITH_SRP_ARTIFACTS" | jq -r '.data[]?.title // empty' 2>/dev/null || echo "Could not extract titles"
# Find the APK artifact - matches metamask-main-rc-[number].apk
# Pattern matches reference script: filter by artifact_type if available, then by title pattern
# Note: Without -r flag, this returns JSON object which we can parse again
WITH_SRP_APK_ARTIFACT=$(echo "$WITH_SRP_ARTIFACTS" | jq '.data[] |
select((.artifact_type == "android-apk") or (.artifact_type | not)) |
select(.title | endswith(".apk")) |
select(.title | test("metamask-main-rc-[0-9]+\\.apk"))')
if [[ -n "$WITH_SRP_APK_ARTIFACT" && "$WITH_SRP_APK_ARTIFACT" != "null" && "$WITH_SRP_APK_ARTIFACT" != "" ]]; then
WITH_SRP_APK_SLUG=$(echo "$WITH_SRP_APK_ARTIFACT" | jq -r '.slug')
if [[ -z "$WITH_SRP_APK_SLUG" || "$WITH_SRP_APK_SLUG" == "null" ]]; then
echo "Error: Failed to extract APK slug from artifact"
echo "Artifact: $WITH_SRP_APK_ARTIFACT"
exit 1
fi
WITH_SRP_DOWNLOAD_RESPONSE=$(curl -s -H "Authorization: $BITRISE_API_TOKEN" \
"https://api.bitrise.io/v0.1/apps/$BITRISE_APP_ID/builds/$WITH_SRP_BUILD_ID/artifacts/$WITH_SRP_APK_SLUG")
# Validate JSON response
if ! echo "$WITH_SRP_DOWNLOAD_RESPONSE" | jq empty 2>/dev/null; then
echo "Error: Invalid JSON response from Bitrise API for download URL"
echo "Response: $WITH_SRP_DOWNLOAD_RESPONSE"
exit 1
fi
WITH_SRP_DOWNLOAD_URL=$(echo "$WITH_SRP_DOWNLOAD_RESPONSE" | jq -r '.data.expiring_download_url // empty')
if [[ -n "$WITH_SRP_DOWNLOAD_URL" && "$WITH_SRP_DOWNLOAD_URL" != "null" ]]; then
echo "Downloading with-SRP APK..."
DOWNLOAD_SUCCESS=false
if command -v wget >/dev/null 2>&1; then
if wget -O "metamask-android-with-srp.apk" "$WITH_SRP_DOWNLOAD_URL" 2>&1; then
DOWNLOAD_SUCCESS=true
else
echo "wget failed, trying curl..."
if curl -L -f -o "metamask-android-with-srp.apk" "$WITH_SRP_DOWNLOAD_URL" 2>&1; then
DOWNLOAD_SUCCESS=true
fi
fi
else
echo "Using curl to download APK..."
if curl -L -f -o "metamask-android-with-srp.apk" "$WITH_SRP_DOWNLOAD_URL" 2>&1; then
DOWNLOAD_SUCCESS=true
fi
fi
if [[ "$DOWNLOAD_SUCCESS" != "true" ]] || [[ ! -f "metamask-android-with-srp.apk" ]]; then
echo "Error: Failed to download with-SRP APK"
exit 1
fi
echo "APK downloaded successfully. File size: $(du -h metamask-android-with-srp.apk | cut -f1)"
# Upload to BrowserStack
echo "Uploading with-SRP APK to BrowserStack..."
WITH_SRP_RESPONSE=$(curl -u "$BROWSERSTACK_USERNAME:$BROWSERSTACK_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
-F "file=@metamask-android-with-srp.apk" \
-F "custom_id=MetaMask-Android-With-SRP-${{ github.run_id }}")
WITH_SRP_APP_URL=$(echo "$WITH_SRP_RESPONSE" | jq -r '.app_url')
WITH_SRP_APP_ID=$(echo "$WITH_SRP_RESPONSE" | jq -r '.app_id')
echo "With-SRP APK uploaded successfully"
echo " App URL: $WITH_SRP_APP_URL"
echo " App ID: $WITH_SRP_APP_ID"
{
echo "with-srp-browserstack-url=$WITH_SRP_APP_URL"
echo "with-srp-app-id=$WITH_SRP_APP_ID"
echo "with-srp-version=Bitrise-Build"
echo "with-srp-apk-uploaded=true"
} >> "$GITHUB_OUTPUT"
else
echo "Failed to get with-SRP APK download URL"
fi
else
echo "With-SRP APK artifact not found (looking for metamask-main-rc-*.apk)"
fi
else
echo "With-SRP build ID not available"
fi
# Download without-SRP APK
if [ -n "$WITHOUT_SRP_BUILD_ID" ]; then
echo "Downloading without-SRP APK..."
echo "Build ID: $WITHOUT_SRP_BUILD_ID"
echo "App ID: $BITRISE_APP_ID"
WITHOUT_SRP_ARTIFACTS=$(curl -s -w "\nHTTP_STATUS:%{http_code}" -H "Authorization: $BITRISE_API_TOKEN" \
"https://api.bitrise.io/v0.1/apps/$BITRISE_APP_ID/builds/$WITHOUT_SRP_BUILD_ID/artifacts")
# Extract HTTP status code
HTTP_STATUS=$(echo "$WITHOUT_SRP_ARTIFACTS" | grep "HTTP_STATUS:" | cut -d: -f2)
WITHOUT_SRP_ARTIFACTS=$(echo "$WITHOUT_SRP_ARTIFACTS" | sed '/HTTP_STATUS:/d')
echo "HTTP Status: $HTTP_STATUS"
# Validate JSON response
if ! echo "$WITHOUT_SRP_ARTIFACTS" | jq empty 2>/dev/null; then
echo "Error: Invalid JSON response from Bitrise API (HTTP $HTTP_STATUS)"
echo "Response (first 500 chars): ${WITHOUT_SRP_ARTIFACTS:0:500}"
exit 1
fi
# Debug: Show all artifact titles for troubleshooting
echo "All artifact titles:"
echo "$WITHOUT_SRP_ARTIFACTS" | jq -r '.data[]?.title // empty' 2>/dev/null || echo "Could not extract titles"
# Find the APK artifact - matches metamask-main-rc-[number].apk
# Pattern matches reference script: filter by artifact_type if available, then by title pattern
# Note: Without -r flag, this returns JSON object which we can parse again
WITHOUT_SRP_APK_ARTIFACT=$(echo "$WITHOUT_SRP_ARTIFACTS" | jq '.data[] |
select((.artifact_type == "android-apk") or (.artifact_type | not)) |
select(.title | endswith(".apk")) |
select(.title | test("metamask-main-rc-[0-9]+\\.apk"))')
if [[ -n "$WITHOUT_SRP_APK_ARTIFACT" && "$WITHOUT_SRP_APK_ARTIFACT" != "null" && "$WITHOUT_SRP_APK_ARTIFACT" != "" ]]; then
WITHOUT_SRP_APK_SLUG=$(echo "$WITHOUT_SRP_APK_ARTIFACT" | jq -r '.slug')
if [[ -z "$WITHOUT_SRP_APK_SLUG" || "$WITHOUT_SRP_APK_SLUG" == "null" ]]; then
echo "Error: Failed to extract APK slug from artifact"
echo "Artifact: $WITHOUT_SRP_APK_ARTIFACT"
exit 1
fi
WITHOUT_SRP_DOWNLOAD_RESPONSE=$(curl -s -H "Authorization: $BITRISE_API_TOKEN" \
"https://api.bitrise.io/v0.1/apps/$BITRISE_APP_ID/builds/$WITHOUT_SRP_BUILD_ID/artifacts/$WITHOUT_SRP_APK_SLUG")
# Validate JSON response
if ! echo "$WITHOUT_SRP_DOWNLOAD_RESPONSE" | jq empty 2>/dev/null; then
echo "Error: Invalid JSON response from Bitrise API for download URL"
echo "Response: $WITHOUT_SRP_DOWNLOAD_RESPONSE"
exit 1
fi
WITHOUT_SRP_DOWNLOAD_URL=$(echo "$WITHOUT_SRP_DOWNLOAD_RESPONSE" | jq -r '.data.expiring_download_url // empty')
if [[ -n "$WITHOUT_SRP_DOWNLOAD_URL" && "$WITHOUT_SRP_DOWNLOAD_URL" != "null" ]]; then
echo "Downloading without-SRP APK..."
DOWNLOAD_SUCCESS=false
if command -v wget >/dev/null 2>&1; then
if wget -O "metamask-android-without-srp.apk" "$WITHOUT_SRP_DOWNLOAD_URL" 2>&1; then
DOWNLOAD_SUCCESS=true
else
echo "wget failed, trying curl..."
if curl -L -f -o "metamask-android-without-srp.apk" "$WITHOUT_SRP_DOWNLOAD_URL" 2>&1; then
DOWNLOAD_SUCCESS=true
fi
fi
else
echo "Using curl to download APK..."
if curl -L -f -o "metamask-android-without-srp.apk" "$WITHOUT_SRP_DOWNLOAD_URL" 2>&1; then
DOWNLOAD_SUCCESS=true
fi
fi
if [[ "$DOWNLOAD_SUCCESS" != "true" ]] || [[ ! -f "metamask-android-without-srp.apk" ]]; then
echo "Error: Failed to download without-SRP APK"
exit 1
fi
echo "APK downloaded successfully. File size: $(du -h metamask-android-without-srp.apk | cut -f1)"
# Upload to BrowserStack
echo "Uploading without-SRP APK to BrowserStack..."
WITHOUT_SRP_RESPONSE=$(curl -u "$BROWSERSTACK_USERNAME:$BROWSERSTACK_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
-F "file=@metamask-android-without-srp.apk" \
-F "custom_id=MetaMask-Android-Without-SRP-${{ github.run_id }}")
WITHOUT_SRP_APP_URL=$(echo "$WITHOUT_SRP_RESPONSE" | jq -r '.app_url')
WITHOUT_SRP_APP_ID=$(echo "$WITHOUT_SRP_RESPONSE" | jq -r '.app_id')
echo "Without-SRP APK uploaded successfully"
echo "App URL: $WITHOUT_SRP_APP_URL"
echo "App ID: $WITHOUT_SRP_APP_ID"
{
echo "without-srp-browserstack-url=$WITHOUT_SRP_APP_URL"
echo "without-srp-app-id=$WITHOUT_SRP_APP_ID"
echo "without-srp-version=Bitrise-Build"
echo "without-srp-apk-uploaded=true"
} >> "$GITHUB_OUTPUT"
else
echo "Failed to get without-SRP APK download URL"
fi
else
echo "Without-SRP APK artifact not found (looking for metamask-main-rc-*.apk)"
fi
else
echo "Without-SRP build ID not available"
fi
echo "BrowserStack upload process completed!"
if [[ -n "$WITH_SRP_APP_URL" ]]; then
echo "With-SRP URL: $WITH_SRP_APP_URL"
else
echo "With-SRP URL: (not uploaded)"
fi
if [[ -n "$WITHOUT_SRP_APP_URL" ]]; then
echo "Without-SRP URL: $WITHOUT_SRP_APP_URL"
else
echo "Without-SRP URL: (not uploaded)"
fi