319
319
# Helper Functions
320
320
#################################################
321
321
322
-
323
- # Generates a build number for Prototype Builds, based on the PR number and short commit SHA1
324
- #
325
- # @note This function uses Buildkite-specific ENV vars
326
- #
327
- def generate_prototype_build_number
328
- if ENV [ 'BUILDKITE' ]
329
- commit = ENV . fetch ( 'BUILDKITE_COMMIT' , nil ) [ 0 , 7 ]
330
- branch = ENV . fetch ( 'BUILDKITE_BRANCH' , nil )
331
- pr_num = ENV . fetch ( 'BUILDKITE_PULL_REQUEST' , nil )
332
-
333
- pr_num == 'false' ? "#{ branch } -#{ commit } " : "pr#{ pr_num } -#{ commit } "
334
- else
335
- repo = Git . open ( PROJECT_ROOT_FOLDER )
336
- commit = repo . current_branch
337
- branch = repo . revparse ( 'HEAD' ) [ 0 , 7 ]
338
-
339
- "#{ branch } -#{ commit } "
340
- end
341
- end
342
-
343
322
# Builds a Prototype Build for WordPress or Jetpack, then uploads it to Firebase App Distribution and comment with a link to it on the PR.
344
323
#
345
324
def build_and_upload_prototype_build ( scheme :, output_app_name :, firebase_app_config :, sentry_project_slug :, app_identifier :)
346
325
build_number = ENV . fetch ( 'BUILDKITE_BUILD_NUMBER' , '0' )
347
- pr_or_branch = ENV . fetch ( 'BUILDKITE_PULL_REQUEST' , nil ) &.then { |num | "PR ##{ num } " } || ENV . fetch ( 'BUILDKITE_BRANCH' , nil )
326
+ pr_or_branch = pull_request_number &.then { |num | "PR ##{ num } " } || ENV . fetch ( 'BUILDKITE_BRANCH' , nil )
348
327
349
328
# Build
350
329
build_app (
@@ -439,7 +418,7 @@ def send_slack_message(message:, channel: '#build-and-ship')
439
418
#
440
419
def upload_build_to_firebase_app_distribution ( firebase_app_config :)
441
420
release_notes = <<~NOTES
442
- Pull Request: ##{ ENV . fetch ( 'BUILDKITE_PULL_REQUEST' , 'N/A' ) }
421
+ Pull Request: ##{ pull_request_number || 'N/A' }
443
422
Branch: `#{ ENV . fetch ( 'BUILDKITE_BRANCH' , 'N/A' ) } `
444
423
Commit: #{ ENV . fetch ( 'BUILDKITE_COMMIT' , 'N/A' ) [ 0 ...7 ] }
445
424
NOTES
@@ -451,7 +430,7 @@ def upload_build_to_firebase_app_distribution(firebase_app_config:)
451
430
groups : firebase_app_config [ :testers_group ]
452
431
)
453
432
454
- return if ENV [ 'BUILDKITE_PULL_REQUEST' ] . nil?
433
+ return if pull_request_number . nil?
455
434
456
435
# PR Comment
457
436
comment_body = prototype_build_details_comment (
@@ -462,7 +441,7 @@ def upload_build_to_firebase_app_distribution(firebase_app_config:)
462
441
)
463
442
comment_on_pr (
464
443
project : GITHUB_REPO ,
465
- pr_number : Integer ( ENV . fetch ( 'BUILDKITE_PULL_REQUEST' , nil ) ) ,
444
+ pr_number : pull_request_number ,
466
445
reuse_identifier : "prototype-build-link-#{ firebase_app_config [ :app_id ] } " ,
467
446
body : comment_body
468
447
)
0 commit comments