Skip to content

Commit 71cb5dc

Browse files
committed
fix(ci): fetch PR info for push events to populate build names correctly
When workflows run on push events (commits pushed to PR branches), github.event.pull_request context is null, causing PR_NUMBER and PR_TITLE to be empty and falling back to generic "Build-123" format. Added logic to detect event type and fetch PR info using GitHub API for push events: - pull_request events: use github.event.pull_request directly - push events: use gh pr view to fetch PR number and title This ensures build names show "PR-185: [title] - [message]" format for both pull_request and push events on PR branches. Applied to all 10 BrowserStack workflows: - android-cpp-ci.yml - android-java-ci.yml - android-kotlin-ci.yml - dotnet-maui-ci.yml (Android + iOS sections) - flutter-ci.yml (Android + iOS sections) - java-spring-ci.yml - kotlin-multiplatform-ci.yml - react-native-ci.yml (Android + iOS sections) - react-native-expo-ci.yml (Android + iOS sections) - swift-ci.yml
1 parent 9da89e5 commit 71cb5dc

File tree

10 files changed

+161
-43
lines changed

10 files changed

+161
-43
lines changed

.github/workflows/android-cpp-ci.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,18 @@ jobs:
205205
echo "Using device: $DEVICE"
206206
207207
# Build BrowserStack project/build names with PR context
208-
PR_NUMBER="${{ github.event.pull_request.number }}"
209-
PR_TITLE="${{ github.event.pull_request.title }}"
208+
# For pull_request events, use event data directly
209+
# For push events, fetch PR info using GitHub API
210+
if [ "${{ github.event_name }}" = "pull_request" ]; then
211+
PR_NUMBER="${{ github.event.pull_request.number }}"
212+
PR_TITLE="${{ github.event.pull_request.title }}"
213+
else
214+
# Get PR number and title for push events
215+
PR_INFO=$(gh pr view "${{ github.ref_name }}" --json number,title --jq '{number:.number, title:.title}' 2>/dev/null || echo '{}')
216+
PR_NUMBER=$(echo "$PR_INFO" | jq -r '.number // empty')
217+
PR_TITLE=$(echo "$PR_INFO" | jq -r '.title // empty')
218+
fi
210219
COMMIT_MSG="${{ github.event.head_commit.message }}"
211-
212220
# Sanitize - keep only BrowserStack-allowed chars: A-Z a-z 0-9 . : - [ ] / @ & ' _
213221
PR_TITLE_CLEAN=$(echo "$PR_TITLE" | sed "s/[^A-Za-z0-9.:[\]\/@&' _-]//g")
214222
COMMIT_FIRST_LINE=$(echo "$COMMIT_MSG" | head -n1)

.github/workflows/android-java-ci.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,19 @@ jobs:
193193
DEVICES=$(yq eval -o=json -I=0 '.["android-java"].devices' .github/browserstack-devices.yml)
194194
echo "Loaded devices: $DEVICES"
195195
196-
# Build BrowserStack project/build names with PR context for better dashboard navigation
197-
PR_NUMBER="${{ github.event.pull_request.number }}"
198-
PR_TITLE="${{ github.event.pull_request.title }}"
199-
COMMIT_MSG="${{ github.event.head_commit.message }}"
200-
196+
# Build BrowserStack project/build names with PR context
197+
# For pull_request events, use event data directly
198+
# For push events, fetch PR info using GitHub API
199+
if [ "${{ github.event_name }}" = "pull_request" ]; then
200+
PR_NUMBER="${{ github.event.pull_request.number }}"
201+
PR_TITLE="${{ github.event.pull_request.title }}"
202+
else
203+
# Get PR number and title for push events
204+
PR_INFO=$(gh pr view "${{ github.ref_name }}" --json number,title --jq '{number:.number, title:.title}' 2>/dev/null || echo '{}')
205+
PR_NUMBER=$(echo "$PR_INFO" | jq -r '.number // empty')
206+
PR_TITLE=$(echo "$PR_INFO" | jq -r '.title // empty')
207+
fi
208+
COMMIT_MSG="${{ github.event.head_commit.message }}"
201209
# Sanitize - keep only BrowserStack-allowed chars: A-Z a-z 0-9 . : - [ ] / @ & ' _
202210
PR_TITLE_CLEAN=$(echo "$PR_TITLE" | sed "s/[^A-Za-z0-9.:[\]\/@&' _-]//g")
203211
COMMIT_FIRST_LINE=$(echo "$COMMIT_MSG" | head -n1)

.github/workflows/android-kotlin-ci.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,19 @@ jobs:
210210
# Load devices from centralized config
211211
DEVICES=$(yq eval -o=json -I=0 '.["android-kotlin"].devices' .github/browserstack-devices.yml)
212212
213-
# Build BrowserStack project/build names with PR context for better dashboard navigation
214-
PR_NUMBER="${{ github.event.pull_request.number }}"
215-
PR_TITLE="${{ github.event.pull_request.title }}"
213+
# Build BrowserStack project/build names with PR context
214+
# For pull_request events, use event data directly
215+
# For push events, fetch PR info using GitHub API
216+
if [ "${{ github.event_name }}" = "pull_request" ]; then
217+
PR_NUMBER="${{ github.event.pull_request.number }}"
218+
PR_TITLE="${{ github.event.pull_request.title }}"
219+
else
220+
# Get PR number and title for push events
221+
PR_INFO=$(gh pr view "${{ github.ref_name }}" --json number,title --jq '{number:.number, title:.title}' 2>/dev/null || echo '{}')
222+
PR_NUMBER=$(echo "$PR_INFO" | jq -r '.number // empty')
223+
PR_TITLE=$(echo "$PR_INFO" | jq -r '.title // empty')
224+
fi
216225
COMMIT_MSG="${{ github.event.head_commit.message }}"
217-
218226
# Sanitize - keep only BrowserStack-allowed chars: A-Z a-z 0-9 . : - [ ] / @ & ' _
219227
PR_TITLE_CLEAN=$(echo "$PR_TITLE" | sed "s/[^A-Za-z0-9.:[\]\/@&' _-]//g")
220228
COMMIT_FIRST_LINE=$(echo "$COMMIT_MSG" | head -n1)

.github/workflows/dotnet-maui-ci.yml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,18 @@ jobs:
233233
echo "Using Android device: $DEVICE"
234234
235235
# Build BrowserStack project/build names with PR context
236-
PR_NUMBER="${{ github.event.pull_request.number }}"
237-
PR_TITLE="${{ github.event.pull_request.title }}"
236+
# For pull_request events, use event data directly
237+
# For push events, fetch PR info using GitHub API
238+
if [ "${{ github.event_name }}" = "pull_request" ]; then
239+
PR_NUMBER="${{ github.event.pull_request.number }}"
240+
PR_TITLE="${{ github.event.pull_request.title }}"
241+
else
242+
# Get PR number and title for push events
243+
PR_INFO=$(gh pr view "${{ github.ref_name }}" --json number,title --jq '{number:.number, title:.title}' 2>/dev/null || echo '{}')
244+
PR_NUMBER=$(echo "$PR_INFO" | jq -r '.number // empty')
245+
PR_TITLE=$(echo "$PR_INFO" | jq -r '.title // empty')
246+
fi
238247
COMMIT_MSG="${{ github.event.head_commit.message }}"
239-
240248
# Sanitize - keep only BrowserStack-allowed chars: A-Z a-z 0-9 . : - [ ] / @ & ' _
241249
PR_TITLE_CLEAN=$(echo "$PR_TITLE" | sed "s/[^A-Za-z0-9.:[\]\/@&' _-]//g")
242250
COMMIT_FIRST_LINE=$(echo "$COMMIT_MSG" | head -n1)
@@ -356,10 +364,18 @@ jobs:
356364
echo "Using iOS device: $DEVICE"
357365
358366
# Build BrowserStack project/build names with PR context
359-
PR_NUMBER="${{ github.event.pull_request.number }}"
360-
PR_TITLE="${{ github.event.pull_request.title }}"
367+
# For pull_request events, use event data directly
368+
# For push events, fetch PR info using GitHub API
369+
if [ "${{ github.event_name }}" = "pull_request" ]; then
370+
PR_NUMBER="${{ github.event.pull_request.number }}"
371+
PR_TITLE="${{ github.event.pull_request.title }}"
372+
else
373+
# Get PR number and title for push events
374+
PR_INFO=$(gh pr view "${{ github.ref_name }}" --json number,title --jq '{number:.number, title:.title}' 2>/dev/null || echo '{}')
375+
PR_NUMBER=$(echo "$PR_INFO" | jq -r '.number // empty')
376+
PR_TITLE=$(echo "$PR_INFO" | jq -r '.title // empty')
377+
fi
361378
COMMIT_MSG="${{ github.event.head_commit.message }}"
362-
363379
# Sanitize - keep only BrowserStack-allowed chars: A-Z a-z 0-9 . : - [ ] / @ & ' _
364380
PR_TITLE_CLEAN=$(echo "$PR_TITLE" | sed "s/[^A-Za-z0-9.:[\]\/@&' _-]//g")
365381
COMMIT_FIRST_LINE=$(echo "$COMMIT_MSG" | head -n1)

.github/workflows/flutter-ci.yml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,17 @@ jobs:
509509
DEVICES=$(yq eval -o=json -I=0 '.flutter.android.devices' .github/browserstack-devices.yml)
510510
511511
# Build BrowserStack project/build names with PR context
512-
PR_NUMBER="${{ github.event.pull_request.number }}"
513-
PR_TITLE="${{ github.event.pull_request.title }}"
512+
# For pull_request events, use event data directly
513+
# For push events, fetch PR info using GitHub API
514+
if [ "${{ github.event_name }}" = "pull_request" ]; then
515+
PR_NUMBER="${{ github.event.pull_request.number }}"
516+
PR_TITLE="${{ github.event.pull_request.title }}"
517+
else
518+
# Get PR number and title for push events
519+
PR_INFO=$(gh pr view "${{ github.ref_name }}" --json number,title --jq '{number:.number, title:.title}' 2>/dev/null || echo '{}')
520+
PR_NUMBER=$(echo "$PR_INFO" | jq -r '.number // empty')
521+
PR_TITLE=$(echo "$PR_INFO" | jq -r '.title // empty')
522+
fi
514523
COMMIT_MSG="${{ github.event.head_commit.message }}"
515524
516525
# Sanitize - keep only BrowserStack-allowed chars: A-Z a-z 0-9 . : - [ ] / @ & ' _
@@ -793,8 +802,17 @@ jobs:
793802
DEVICES=$(yq eval -o=json -I=0 '.flutter.ios.devices' .github/browserstack-devices.yml)
794803
795804
# Build BrowserStack project/build names with PR context
796-
PR_NUMBER="${{ github.event.pull_request.number }}"
797-
PR_TITLE="${{ github.event.pull_request.title }}"
805+
# For pull_request events, use event data directly
806+
# For push events, fetch PR info using GitHub API
807+
if [ "${{ github.event_name }}" = "pull_request" ]; then
808+
PR_NUMBER="${{ github.event.pull_request.number }}"
809+
PR_TITLE="${{ github.event.pull_request.title }}"
810+
else
811+
# Get PR number and title for push events
812+
PR_INFO=$(gh pr view "${{ github.ref_name }}" --json number,title --jq '{number:.number, title:.title}' 2>/dev/null || echo '{}')
813+
PR_NUMBER=$(echo "$PR_INFO" | jq -r '.number // empty')
814+
PR_TITLE=$(echo "$PR_INFO" | jq -r '.title // empty')
815+
fi
798816
COMMIT_MSG="${{ github.event.head_commit.message }}"
799817
800818
# Sanitize - keep only BrowserStack-allowed chars: A-Z a-z 0-9 . : - [ ] / @ & ' _

.github/workflows/java-spring-ci.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,19 @@ jobs:
158158
# Load platforms from centralized config and convert to YAML format
159159
PLATFORMS=$(yq eval '.["java-spring"].platforms[] | " - os: \(.os)\n osVersion: \"\(.osVersion)\"\n browserName: \(.browserName)\n browserVersion: \(.browserVersion)"' ../.github/browserstack-devices.yml)
160160
161-
# Build BrowserStack project/build names with PR context
162-
PR_NUMBER="${{ github.event.pull_request.number }}"
163-
PR_TITLE="${{ github.event.pull_request.title }}"
164-
COMMIT_MSG="${{ github.event.head_commit.message }}"
165-
161+
# Build BrowserStack project/build names with PR context
162+
# For pull_request events, use event data directly
163+
# For push events, fetch PR info using GitHub API
164+
if [ "${{ github.event_name }}" = "pull_request" ]; then
165+
PR_NUMBER="${{ github.event.pull_request.number }}"
166+
PR_TITLE="${{ github.event.pull_request.title }}"
167+
else
168+
# Get PR number and title for push events
169+
PR_INFO=$(gh pr view "${{ github.ref_name }}" --json number,title --jq '{number:.number, title:.title}' 2>/dev/null || echo '{}')
170+
PR_NUMBER=$(echo "$PR_INFO" | jq -r '.number // empty')
171+
PR_TITLE=$(echo "$PR_INFO" | jq -r '.title // empty')
172+
fi
173+
COMMIT_MSG="${{ github.event.head_commit.message }}"
166174
# Sanitize - keep only BrowserStack-allowed chars: A-Z a-z 0-9 . : - [ ] / @ & ' _
167175
PR_TITLE_CLEAN=$(echo "$PR_TITLE" | sed "s/[^A-Za-z0-9.:[\]\/@&' _-]//g")
168176
COMMIT_FIRST_LINE=$(echo "$COMMIT_MSG" | head -n1)

.github/workflows/kotlin-multiplatform-ci.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,19 @@ jobs:
389389
# Load devices from centralized config
390390
DEVICES=$(yq eval -o=json -I=0 '.["kotlin-multiplatform"].android.devices' .github/browserstack-devices.yml)
391391
392-
# Build BrowserStack project/build names with PR context
393-
PR_NUMBER="${{ github.event.pull_request.number }}"
394-
PR_TITLE="${{ github.event.pull_request.title }}"
395-
COMMIT_MSG="${{ github.event.head_commit.message }}"
396-
392+
# Build BrowserStack project/build names with PR context
393+
# For pull_request events, use event data directly
394+
# For push events, fetch PR info using GitHub API
395+
if [ "${{ github.event_name }}" = "pull_request" ]; then
396+
PR_NUMBER="${{ github.event.pull_request.number }}"
397+
PR_TITLE="${{ github.event.pull_request.title }}"
398+
else
399+
# Get PR number and title for push events
400+
PR_INFO=$(gh pr view "${{ github.ref_name }}" --json number,title --jq '{number:.number, title:.title}' 2>/dev/null || echo '{}')
401+
PR_NUMBER=$(echo "$PR_INFO" | jq -r '.number // empty')
402+
PR_TITLE=$(echo "$PR_INFO" | jq -r '.title // empty')
403+
fi
404+
COMMIT_MSG="${{ github.event.head_commit.message }}"
397405
# Sanitize - keep only BrowserStack-allowed chars: A-Z a-z 0-9 . : - [ ] / @ & ' _
398406
PR_TITLE_CLEAN=$(echo "$PR_TITLE" | sed "s/[^A-Za-z0-9.:[\]\/@&' _-]//g")
399407
COMMIT_FIRST_LINE=$(echo "$COMMIT_MSG" | head -n1)

.github/workflows/react-native-ci.yml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,17 @@ jobs:
306306
echo "Loaded devices: $DEVICES"
307307
308308
# Build BrowserStack project/build names with PR context
309-
PR_NUMBER="${{ github.event.pull_request.number }}"
310-
PR_TITLE="${{ github.event.pull_request.title }}"
309+
# For pull_request events, use event data directly
310+
# For push events, fetch PR info using GitHub API
311+
if [ "${{ github.event_name }}" = "pull_request" ]; then
312+
PR_NUMBER="${{ github.event.pull_request.number }}"
313+
PR_TITLE="${{ github.event.pull_request.title }}"
314+
else
315+
# Get PR number and title for push events
316+
PR_INFO=$(gh pr view "${{ github.ref_name }}" --json number,title --jq '{number:.number, title:.title}' 2>/dev/null || echo '{}')
317+
PR_NUMBER=$(echo "$PR_INFO" | jq -r '.number // empty')
318+
PR_TITLE=$(echo "$PR_INFO" | jq -r '.title // empty')
319+
fi
311320
COMMIT_MSG="${{ github.event.head_commit.message }}"
312321
313322
# Sanitize - keep only BrowserStack-allowed chars: A-Z a-z 0-9 . : - [ ] / @ & ' _
@@ -510,8 +519,17 @@ jobs:
510519
echo "Loaded devices: $DEVICES"
511520
512521
# Build BrowserStack project/build names with PR context
513-
PR_NUMBER="${{ github.event.pull_request.number }}"
514-
PR_TITLE="${{ github.event.pull_request.title }}"
522+
# For pull_request events, use event data directly
523+
# For push events, fetch PR info using GitHub API
524+
if [ "${{ github.event_name }}" = "pull_request" ]; then
525+
PR_NUMBER="${{ github.event.pull_request.number }}"
526+
PR_TITLE="${{ github.event.pull_request.title }}"
527+
else
528+
# Get PR number and title for push events
529+
PR_INFO=$(gh pr view "${{ github.ref_name }}" --json number,title --jq '{number:.number, title:.title}' 2>/dev/null || echo '{}')
530+
PR_NUMBER=$(echo "$PR_INFO" | jq -r '.number // empty')
531+
PR_TITLE=$(echo "$PR_INFO" | jq -r '.title // empty')
532+
fi
515533
COMMIT_MSG="${{ github.event.head_commit.message }}"
516534
517535
# Sanitize - keep only BrowserStack-allowed chars: A-Z a-z 0-9 . : - [ ] / @ & ' _

.github/workflows/react-native-expo-ci.yml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,17 @@ jobs:
313313
echo "Loaded devices: $DEVICES"
314314
315315
# Build BrowserStack project/build names with PR context
316-
PR_NUMBER="${{ github.event.pull_request.number }}"
317-
PR_TITLE="${{ github.event.pull_request.title }}"
316+
# For pull_request events, use event data directly
317+
# For push events, fetch PR info using GitHub API
318+
if [ "${{ github.event_name }}" = "pull_request" ]; then
319+
PR_NUMBER="${{ github.event.pull_request.number }}"
320+
PR_TITLE="${{ github.event.pull_request.title }}"
321+
else
322+
# Get PR number and title for push events
323+
PR_INFO=$(gh pr view "${{ github.ref_name }}" --json number,title --jq '{number:.number, title:.title}' 2>/dev/null || echo '{}')
324+
PR_NUMBER=$(echo "$PR_INFO" | jq -r '.number // empty')
325+
PR_TITLE=$(echo "$PR_INFO" | jq -r '.title // empty')
326+
fi
318327
COMMIT_MSG="${{ github.event.head_commit.message }}"
319328
320329
# Sanitize - keep only BrowserStack-allowed chars: A-Z a-z 0-9 . : - [ ] / @ & ' _
@@ -517,8 +526,17 @@ jobs:
517526
echo "Loaded devices: $DEVICES"
518527
519528
# Build BrowserStack project/build names with PR context
520-
PR_NUMBER="${{ github.event.pull_request.number }}"
521-
PR_TITLE="${{ github.event.pull_request.title }}"
529+
# For pull_request events, use event data directly
530+
# For push events, fetch PR info using GitHub API
531+
if [ "${{ github.event_name }}" = "pull_request" ]; then
532+
PR_NUMBER="${{ github.event.pull_request.number }}"
533+
PR_TITLE="${{ github.event.pull_request.title }}"
534+
else
535+
# Get PR number and title for push events
536+
PR_INFO=$(gh pr view "${{ github.ref_name }}" --json number,title --jq '{number:.number, title:.title}' 2>/dev/null || echo '{}')
537+
PR_NUMBER=$(echo "$PR_INFO" | jq -r '.number // empty')
538+
PR_TITLE=$(echo "$PR_INFO" | jq -r '.title // empty')
539+
fi
522540
COMMIT_MSG="${{ github.event.head_commit.message }}"
523541
524542
# Sanitize - keep only BrowserStack-allowed chars: A-Z a-z 0-9 . : - [ ] / @ & ' _

.github/workflows/swift-ci.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,10 +437,18 @@ jobs:
437437
DEVICES=$(yq eval -o=json -I=0 '.swift.devices' .github/browserstack-devices.yml)
438438
439439
# Build BrowserStack project/build names with PR context
440-
PR_NUMBER="${{ github.event.pull_request.number }}"
441-
PR_TITLE="${{ github.event.pull_request.title }}"
440+
# For pull_request events, use event data directly
441+
# For push events, fetch PR info using GitHub API
442+
if [ "${{ github.event_name }}" = "pull_request" ]; then
443+
PR_NUMBER="${{ github.event.pull_request.number }}"
444+
PR_TITLE="${{ github.event.pull_request.title }}"
445+
else
446+
# Get PR number and title for push events
447+
PR_INFO=$(gh pr view "${{ github.ref_name }}" --json number,title --jq '{number:.number, title:.title}' 2>/dev/null || echo '{}')
448+
PR_NUMBER=$(echo "$PR_INFO" | jq -r '.number // empty')
449+
PR_TITLE=$(echo "$PR_INFO" | jq -r '.title // empty')
450+
fi
442451
COMMIT_MSG="${{ github.event.head_commit.message }}"
443-
444452
# Sanitize - keep only BrowserStack-allowed chars: A-Z a-z 0-9 . : - [ ] / @ & ' _
445453
PR_TITLE_CLEAN=$(echo "$PR_TITLE" | sed "s/[^A-Za-z0-9.:[\]\/@&' _-]//g")
446454
COMMIT_FIRST_LINE=$(echo "$COMMIT_MSG" | head -n1)

0 commit comments

Comments
 (0)