Skip to content

Commit 73fb69b

Browse files
committed
Update Fastlane code on prototype builds
1 parent 4855fbf commit 73fb69b

File tree

1 file changed

+58
-73
lines changed

1 file changed

+58
-73
lines changed

fastlane/lanes/build.rb

+58-73
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,21 @@
33
SENTRY_ORG_SLUG = 'a8c'
44
SENTRY_PROJECT_SLUG_WORDPRESS = 'wordpress-ios'
55
SENTRY_PROJECT_SLUG_JETPACK = 'jetpack-ios'
6-
APPCENTER_OWNER_NAME = 'automattic'
7-
APPCENTER_OWNER_TYPE = 'organization'
6+
7+
FIREBASE_APP_CONFIG_WORDPRESS = {
8+
app_name: 'WordPress',
9+
app_icon: ':wordpress:', # Use Buildkite emoji
10+
app_id: '1:124902176124:ios:ff9714d0b53aac821620f9',
11+
testers_group: 'wordpress-ios---prototype-builds'
12+
}.freeze
13+
14+
FIREBASE_APP_CONFIG_JETPACK = {
15+
app_name: 'Jetpack',
16+
app_icon: ':jetpack:', # Use Buildkite emoji
17+
app_id: '1:124902176124:ios:121c494b82f283ec1620f9',
18+
testers_group: 'jetpack-ios---prototype-builds',
19+
}.freeze
20+
821
CONCURRENT_SIMULATORS = 2
922

1023
# Shared options to use when invoking `build_app` (`gym`).
@@ -251,7 +264,7 @@
251264
)
252265
end
253266

254-
# Builds the WordPress app for a Prototype Build ("WordPress Alpha" scheme), and uploads it to App Center
267+
# Builds the WordPress app for a Prototype Build ("WordPress Alpha" scheme), and uploads it to Firebase App Distribution
255268
#
256269
# @called_by CI
257270
#
@@ -264,14 +277,13 @@
264277
build_and_upload_prototype_build(
265278
scheme: 'WordPress Alpha',
266279
output_app_name: 'WordPress Alpha',
267-
appcenter_app_name: 'WPiOS-One-Offs',
268-
app_icon: ':wordpress:', # Use Buildkite emoji
280+
firebase_app_config: FIREBASE_APP_CONFIG_WORDPRESS,
269281
sentry_project_slug: SENTRY_PROJECT_SLUG_WORDPRESS,
270282
app_identifier: 'org.wordpress.alpha'
271283
)
272284
end
273285

274-
# Builds the Jetpack app for a Prototype Build ("Jetpack" scheme), and uploads it to App Center
286+
# Builds the Jetpack app for a Prototype Build ("Jetpack" scheme), and uploads it to Firebase App Distribution
275287
#
276288
# @called_by CI
277289
#
@@ -284,8 +296,7 @@
284296
build_and_upload_prototype_build(
285297
scheme: 'Jetpack',
286298
output_app_name: 'Jetpack Alpha',
287-
appcenter_app_name: 'jetpack-installable-builds',
288-
app_icon: ':jetpack:', # Use Buildkite emoji
299+
firebase_app_config: FIREBASE_APP_CONFIG_JETPACK,
289300
sentry_project_slug: SENTRY_PROJECT_SLUG_JETPACK,
290301
app_identifier: 'com.jetpack.alpha'
291302
)
@@ -327,28 +338,23 @@ def generate_prototype_build_number
327338
end
328339
end
329340

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.
341+
# 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.
331342
#
332343
# rubocop:disable Metrics/AbcSize
333344
# 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:)
345+
def build_and_upload_prototype_build(scheme:, output_app_name:, firebase_app_config:, sentry_project_slug:, app_identifier:)
335346
configuration = 'Release-Alpha'
336347

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))
348+
build_number = ENV.fetch('BUILDKITE_BUILD_NUMBER', '0')
349+
pr_or_branch = ENV.fetch('BUILDKITE_PULL_REQUEST', nil)&.then { |num| "PR ##{num}" } || ENV.fetch('BUILDKITE_BRANCH', nil)
345350

346351
# Build
347352
build_app(
348353
scheme: scheme,
349354
workspace: WORKSPACE_PATH,
350355
configuration: configuration,
351356
clean: true,
357+
xcargs: { VERSION_LONG: build_number, VERSION_SHORT: pr_or_branch }.compact,
352358
output_directory: BUILD_PRODUCTS_PATH,
353359
output_name: output_app_name,
354360
derived_data_path: DERIVED_DATA_PATH,
@@ -357,21 +363,8 @@ def build_and_upload_prototype_build(scheme:, output_app_name:, appcenter_app_na
357363
export_options: { **COMMON_EXPORT_OPTIONS, method: 'enterprise' }
358364
)
359365

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
366+
upload_build_to_firebase_app_distribution(
367+
firebase_app_config: FIREBASE_APP_CONFIG_WORDPRESS
375368
)
376369

377370
# Upload dSYMs to Sentry
@@ -388,30 +381,6 @@ def build_and_upload_prototype_build(scheme:, output_app_name:, appcenter_app_na
388381
build_version: build_number,
389382
app_identifier: app_identifier
390383
)
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}")
415384
end
416385
# rubocop:enable Metrics/AbcSize
417386
# rubocop:enable Metrics/ParameterLists
@@ -467,23 +436,39 @@ def send_slack_message(message:, channel: '#build-and-ship')
467436
)
468437
end
469438

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,
439+
# Uploads a build to Firebase App Distribution and post the corresponding PR comment
440+
#
441+
# @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
442+
# Typically one of FIREBASE_APP_CONFIG_WORDPRESS or FIREBASE_APP_CONFIG_JETPACK
443+
#
444+
def upload_build_to_firebase_app_distribution(firebase_app_config:)
445+
release_notes = <<~NOTES
446+
Pull Request: ##{ENV.fetch('BUILDKITE_PULL_REQUEST', 'N/A')}
447+
Branch: `#{ENV.fetch('BUILDKITE_BRANCH', 'N/A')}`
448+
Commit: #{ENV.fetch('BUILDKITE_COMMIT', 'N/A')[0...7]}
449+
NOTES
450+
451+
firebase_app_distribution(
452+
app: firebase_app_config[:app_id],
453+
service_credentials_json_data: get_required_env('FIREBASE_APP_DISTRIBUTION_ACCOUNT_KEY'),
484454
release_notes: release_notes,
485-
destinations: distribute_to_everyone ? '*' : 'Collaborators',
486-
notify_testers: false
455+
groups: firebase_app_config[:testers_group]
456+
)
457+
458+
return if ENV['BUILDKITE_PULL_REQUEST'].nil?
459+
460+
# PR Comment
461+
comment_body = prototype_build_details_comment(
462+
app_display_name: firebase_app_config[:app_name],
463+
app_icon: firebase_app_config[:app_icon],
464+
metadata: { Configuration: configuration },
465+
fold: true
466+
)
467+
comment_on_pr(
468+
project: GITHUB_REPO,
469+
pr_number: Integer(ENV.fetch('BUILDKITE_PULL_REQUEST', nil)),
470+
reuse_identifier: "prototype-build-link-#{firebase_app_config[:app_id]}",
471+
body: comment_body
487472
)
488473
end
489474

0 commit comments

Comments
 (0)