Skip to content

Commit 8c7ad14

Browse files
committed
Update Fastlane code on prototype builds
1 parent 20ca36d commit 8c7ad14

File tree

1 file changed

+61
-80
lines changed

1 file changed

+61
-80
lines changed

fastlane/lanes/build.rb

+61-80
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
# frozen_string_literal: true
22

3+
# Sentry
34
SENTRY_ORG_SLUG = 'a8c'
45
SENTRY_PROJECT_SLUG_WORDPRESS = 'wordpress-ios'
56
SENTRY_PROJECT_SLUG_JETPACK = 'jetpack-ios'
6-
APPCENTER_OWNER_NAME = 'automattic'
7-
APPCENTER_OWNER_TYPE = 'organization'
7+
8+
# Prototype Builds in Firebase App Distribution
9+
PROTOTYPE_BUILD_XCODE_CONFIGURATION = 'Release-Alpha'
10+
FIREBASE_APP_CONFIG_WORDPRESS = {
11+
app_name: 'WordPress',
12+
app_icon: ':wordpress:', # Use Buildkite emoji
13+
app_id: '1:124902176124:ios:ff9714d0b53aac821620f9',
14+
testers_group: 'wordpress-ios---prototype-builds'
15+
}.freeze
16+
FIREBASE_APP_CONFIG_JETPACK = {
17+
app_name: 'Jetpack',
18+
app_icon: ':jetpack:', # Use Buildkite emoji
19+
app_id: '1:124902176124:ios:121c494b82f283ec1620f9',
20+
testers_group: 'jetpack-ios---prototype-builds'
21+
}.freeze
22+
823
CONCURRENT_SIMULATORS = 2
924

1025
# Shared options to use when invoking `build_app` (`gym`).
@@ -251,7 +266,7 @@
251266
)
252267
end
253268

254-
# Builds the WordPress app for a Prototype Build ("WordPress Alpha" scheme), and uploads it to App Center
269+
# Builds the WordPress app for a Prototype Build ("WordPress Alpha" scheme), and uploads it to Firebase App Distribution
255270
#
256271
# @called_by CI
257272
#
@@ -264,14 +279,13 @@
264279
build_and_upload_prototype_build(
265280
scheme: 'WordPress Alpha',
266281
output_app_name: 'WordPress Alpha',
267-
appcenter_app_name: 'WPiOS-One-Offs',
268-
app_icon: ':wordpress:', # Use Buildkite emoji
282+
firebase_app_config: FIREBASE_APP_CONFIG_WORDPRESS,
269283
sentry_project_slug: SENTRY_PROJECT_SLUG_WORDPRESS,
270284
app_identifier: 'org.wordpress.alpha'
271285
)
272286
end
273287

274-
# Builds the Jetpack app for a Prototype Build ("Jetpack" scheme), and uploads it to App Center
288+
# Builds the Jetpack app for a Prototype Build ("Jetpack" scheme), and uploads it to Firebase App Distribution
275289
#
276290
# @called_by CI
277291
#
@@ -284,8 +298,7 @@
284298
build_and_upload_prototype_build(
285299
scheme: 'Jetpack',
286300
output_app_name: 'Jetpack Alpha',
287-
appcenter_app_name: 'jetpack-installable-builds',
288-
app_icon: ':jetpack:', # Use Buildkite emoji
301+
firebase_app_config: FIREBASE_APP_CONFIG_JETPACK,
289302
sentry_project_slug: SENTRY_PROJECT_SLUG_JETPACK,
290303
app_identifier: 'com.jetpack.alpha'
291304
)
@@ -327,28 +340,19 @@ def generate_prototype_build_number
327340
end
328341
end
329342

330-
# Builds a Prototype Build for WordPress or Jetpack, then uploads it to App Center and comment with a link to it on the PR.
343+
# 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.
331344
#
332-
# rubocop:disable Metrics/AbcSize
333-
# rubocop:disable Metrics/ParameterLists
334-
def build_and_upload_prototype_build(scheme:, output_app_name:, appcenter_app_name:, app_icon:, sentry_project_slug:, app_identifier:)
335-
configuration = 'Release-Alpha'
336-
337-
# Get the current build version, and update it if needed
338-
version_config_path = File.join(PROJECT_ROOT_FOLDER, 'config', 'Version.public.xcconfig')
339-
versions = Xcodeproj::Config.new(File.new(version_config_path)).to_hash
340-
build_number = generate_prototype_build_number
341-
UI.message("Updating build version to #{build_number}")
342-
versions['VERSION_LONG'] = build_number
343-
new_config = Xcodeproj::Config.new(versions)
344-
new_config.save_as(Pathname.new(version_config_path))
345+
def build_and_upload_prototype_build(scheme:, output_app_name:, firebase_app_config:, sentry_project_slug:, app_identifier:)
346+
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)
345348

346349
# Build
347350
build_app(
348351
scheme: scheme,
349352
workspace: WORKSPACE_PATH,
350-
configuration: configuration,
353+
configuration: PROTOTYPE_BUILD_XCODE_CONFIGURATION,
351354
clean: true,
355+
xcargs: { VERSION_LONG: build_number, VERSION_SHORT: pr_or_branch }.compact,
352356
output_directory: BUILD_PRODUCTS_PATH,
353357
output_name: output_app_name,
354358
derived_data_path: DERIVED_DATA_PATH,
@@ -357,21 +361,8 @@ def build_and_upload_prototype_build(scheme:, output_app_name:, appcenter_app_na
357361
export_options: { **COMMON_EXPORT_OPTIONS, method: 'enterprise' }
358362
)
359363

360-
# Upload to App Center
361-
commit = ENV.fetch('BUILDKITE_COMMIT', 'Unknown')
362-
pr = ENV.fetch('BUILDKITE_PULL_REQUEST', nil)
363-
release_notes = <<~NOTES
364-
- Branch: `#{ENV.fetch('BUILDKITE_BRANCH', 'Unknown')}`\n
365-
- Commit: [#{commit[0...7]}](https://github.com/#{GITHUB_REPO}/commit/#{commit})\n
366-
- Pull Request: [##{pr}](https://github.com/#{GITHUB_REPO}/pull/#{pr})\n
367-
NOTES
368-
369-
upload_build_to_app_center(
370-
name: appcenter_app_name,
371-
file: lane_context[SharedValues::IPA_OUTPUT_PATH],
372-
dsym: lane_context[SharedValues::DSYM_OUTPUT_PATH],
373-
release_notes: release_notes,
374-
distribute_to_everyone: false
364+
upload_build_to_firebase_app_distribution(
365+
firebase_app_config: firebase_app_config
375366
)
376367

377368
# Upload dSYMs to Sentry
@@ -388,33 +379,7 @@ def build_and_upload_prototype_build(scheme:, output_app_name:, appcenter_app_na
388379
build_version: build_number,
389380
app_identifier: app_identifier
390381
)
391-
392-
# Post PR Comment
393-
comment_body = prototype_build_details_comment(
394-
app_display_name: output_app_name,
395-
app_icon: app_icon,
396-
app_center_org_name: APPCENTER_OWNER_NAME,
397-
metadata: { Configuration: configuration },
398-
fold: true
399-
)
400-
401-
comment_on_pr(
402-
project: GITHUB_REPO,
403-
pr_number: Integer(ENV.fetch('BUILDKITE_PULL_REQUEST', nil)),
404-
reuse_identifier: "prototype-build-link-#{appcenter_app_name}",
405-
body: comment_body
406-
)
407-
408-
# Attach version information as Buildkite metadata and annotation
409-
appcenter_id = lane_context.dig(SharedValues::APPCENTER_BUILD_INFORMATION, 'id')
410-
metadata = versions.merge(build_type: 'Prototype', 'appcenter:id': appcenter_id)
411-
buildkite_metadata(set: metadata)
412-
appcenter_install_url = "https://install.appcenter.ms/orgs/#{APPCENTER_OWNER_NAME}/apps/#{appcenter_app_name}/releases/#{appcenter_id}"
413-
list = metadata.map { |k, v| " - **#{k}**: #{v}" }.join("\n")
414-
buildkite_annotate(context: "appcenter-info-#{output_app_name}", style: 'info', message: "#{output_app_name} [App Center Build](#{appcenter_install_url}) Info:\n\n#{list}")
415382
end
416-
# rubocop:enable Metrics/AbcSize
417-
# rubocop:enable Metrics/ParameterLists
418383

419384
def inject_buildkite_analytics_environment(xctestrun_path:)
420385
require 'plist'
@@ -467,23 +432,39 @@ def send_slack_message(message:, channel: '#build-and-ship')
467432
)
468433
end
469434

470-
def upload_build_to_app_center(
471-
name:,
472-
file:,
473-
dsym:,
474-
release_notes:,
475-
distribute_to_everyone:
476-
)
477-
appcenter_upload(
478-
api_token: get_required_env('APPCENTER_API_TOKEN'),
479-
owner_name: APPCENTER_OWNER_NAME,
480-
owner_type: APPCENTER_OWNER_TYPE,
481-
app_name: name,
482-
file: file,
483-
dsym: dsym,
435+
# Uploads a build to Firebase App Distribution and post the corresponding PR comment
436+
#
437+
# @param [Hash<Symbol, String>] firebase_app_config A hash with the app name as the key and the Firebase app ID and testers group as the value
438+
# Typically one of FIREBASE_APP_CONFIG_WORDPRESS or FIREBASE_APP_CONFIG_JETPACK
439+
#
440+
def upload_build_to_firebase_app_distribution(firebase_app_config:)
441+
release_notes = <<~NOTES
442+
Pull Request: ##{ENV.fetch('BUILDKITE_PULL_REQUEST', 'N/A')}
443+
Branch: `#{ENV.fetch('BUILDKITE_BRANCH', 'N/A')}`
444+
Commit: #{ENV.fetch('BUILDKITE_COMMIT', 'N/A')[0...7]}
445+
NOTES
446+
447+
firebase_app_distribution(
448+
app: firebase_app_config[:app_id],
449+
service_credentials_json_data: get_required_env('FIREBASE_APP_DISTRIBUTION_ACCOUNT_KEY'),
484450
release_notes: release_notes,
485-
destinations: distribute_to_everyone ? '*' : 'Collaborators',
486-
notify_testers: false
451+
groups: firebase_app_config[:testers_group]
452+
)
453+
454+
return if ENV['BUILDKITE_PULL_REQUEST'].nil?
455+
456+
# PR Comment
457+
comment_body = prototype_build_details_comment(
458+
app_display_name: firebase_app_config[:app_name],
459+
app_icon: firebase_app_config[:app_icon],
460+
metadata: { Configuration: PROTOTYPE_BUILD_XCODE_CONFIGURATION },
461+
fold: true
462+
)
463+
comment_on_pr(
464+
project: GITHUB_REPO,
465+
pr_number: Integer(ENV.fetch('BUILDKITE_PULL_REQUEST', nil)),
466+
reuse_identifier: "prototype-build-link-#{firebase_app_config[:app_id]}",
467+
body: comment_body
487468
)
488469
end
489470

0 commit comments

Comments
 (0)