Skip to content

Commit 95ac031

Browse files
committed
Fix BUILDKITE_PULL_REQUEST being false not nil
1 parent 6542b64 commit 95ac031

File tree

2 files changed

+10
-25
lines changed

2 files changed

+10
-25
lines changed

fastlane/Fastfile

+6
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,9 @@ end
240240
def editorial_branch_name(version: release_version_current)
241241
"release_notes/#{version}"
242242
end
243+
244+
def pull_request_number
245+
# Buildkite sets this env var to the PR number if on a PR, but to 'false' (and not nil) if not on a PR
246+
pr_num = ENV.fetch('BUILDKITE_PULL_REQUEST', 'false')
247+
pr_num == 'false' ? nil : Integer(pr_num)
248+
end

fastlane/lanes/build.rb

+4-25
Original file line numberDiff line numberDiff line change
@@ -319,32 +319,11 @@
319319
# Helper Functions
320320
#################################################
321321

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-
343322
# 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.
344323
#
345324
def build_and_upload_prototype_build(scheme:, output_app_name:, firebase_app_config:, sentry_project_slug:, app_identifier:)
346325
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)
348327

349328
# Build
350329
build_app(
@@ -439,7 +418,7 @@ def send_slack_message(message:, channel: '#build-and-ship')
439418
#
440419
def upload_build_to_firebase_app_distribution(firebase_app_config:)
441420
release_notes = <<~NOTES
442-
Pull Request: ##{ENV.fetch('BUILDKITE_PULL_REQUEST', 'N/A')}
421+
Pull Request: ##{pull_request_number || 'N/A'}
443422
Branch: `#{ENV.fetch('BUILDKITE_BRANCH', 'N/A')}`
444423
Commit: #{ENV.fetch('BUILDKITE_COMMIT', 'N/A')[0...7]}
445424
NOTES
@@ -451,7 +430,7 @@ def upload_build_to_firebase_app_distribution(firebase_app_config:)
451430
groups: firebase_app_config[:testers_group]
452431
)
453432

454-
return if ENV['BUILDKITE_PULL_REQUEST'].nil?
433+
return if pull_request_number.nil?
455434

456435
# PR Comment
457436
comment_body = prototype_build_details_comment(
@@ -462,7 +441,7 @@ def upload_build_to_firebase_app_distribution(firebase_app_config:)
462441
)
463442
comment_on_pr(
464443
project: GITHUB_REPO,
465-
pr_number: Integer(ENV.fetch('BUILDKITE_PULL_REQUEST', nil)),
444+
pr_number: pull_request_number,
466445
reuse_identifier: "prototype-build-link-#{firebase_app_config[:app_id]}",
467446
body: comment_body
468447
)

0 commit comments

Comments
 (0)