Skip to content

Commit 23444f6

Browse files
authored
[Tooling] Migrate Prototype Builds to Firebase App Distribution (#15323)
2 parents 4821ba5 + e730f75 commit 23444f6

File tree

4 files changed

+42
-59
lines changed

4 files changed

+42
-59
lines changed

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ gem 'danger-dangermattic', '~> 1.2'
1212
gem 'dotenv'
1313
# 2.217.0 includes a fix for Xcode 15 test results parsing in CI
1414
gem 'fastlane', '~> 2.217'
15-
gem 'fastlane-plugin-appcenter', '~> 2.0'
15+
gem 'fastlane-plugin-firebase_app_distribution', '~> 0.10'
1616
gem 'fastlane-plugin-sentry', '~> 1.0'
1717
# This comment avoids typing to switch to a development version for testing.
1818
#
1919
# gem 'fastlane-plugin-wpmreleasetoolkit', git: '[email protected]:wordpress-mobile/release-toolkit', branch: ''
20-
gem 'fastlane-plugin-wpmreleasetoolkit', '~> 12.5'
20+
gem 'fastlane-plugin-wpmreleasetoolkit', '~> 13.0'
2121
gem 'rake', '~> 12.3'
2222
gem 'rubocop', '~> 1.65'
2323
gem 'rubocop-rake', '~> 0.6'

Gemfile.lock

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,12 @@ GEM
210210
xcodeproj (>= 1.13.0, < 2.0.0)
211211
xcpretty (~> 0.4.0)
212212
xcpretty-travis-formatter (>= 0.0.3, < 2.0.0)
213-
fastlane-plugin-appcenter (2.1.2)
213+
fastlane-plugin-firebase_app_distribution (0.10.0)
214+
google-apis-firebaseappdistribution_v1 (~> 0.3.0)
215+
google-apis-firebaseappdistribution_v1alpha (~> 0.2.0)
214216
fastlane-plugin-sentry (1.25.1)
215217
os (~> 1.1, >= 1.1.4)
216-
fastlane-plugin-wpmreleasetoolkit (12.5.0)
218+
fastlane-plugin-wpmreleasetoolkit (13.0.0)
217219
activesupport (>= 6.1.7.1)
218220
buildkit (~> 1.5)
219221
chroma (= 0.2.0)
@@ -250,6 +252,10 @@ GEM
250252
representable (~> 3.0)
251253
retriable (>= 2.0, < 4.a)
252254
rexml
255+
google-apis-firebaseappdistribution_v1 (0.3.0)
256+
google-apis-core (>= 0.11.0, < 2.a)
257+
google-apis-firebaseappdistribution_v1alpha (0.2.0)
258+
google-apis-core (>= 0.11.0, < 2.a)
253259
google-apis-iamcredentials_v1 (0.17.0)
254260
google-apis-core (>= 0.11.0, < 2.a)
255261
google-apis-playcustomapp_v1 (0.13.0)
@@ -416,9 +422,9 @@ DEPENDENCIES
416422
danger-dangermattic (~> 1.2)
417423
dotenv
418424
fastlane (~> 2.217)
419-
fastlane-plugin-appcenter (~> 2.0)
425+
fastlane-plugin-firebase_app_distribution (~> 0.10)
420426
fastlane-plugin-sentry (~> 1.0)
421-
fastlane-plugin-wpmreleasetoolkit (~> 12.5)
427+
fastlane-plugin-wpmreleasetoolkit (~> 13.0)
422428
rake (~> 12.3)
423429
rmagick (~> 4.1)
424430
rubocop (~> 1.65)

fastlane/Fastfile

Lines changed: 30 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ DERIVED_DATA_DIR = File.join(FASTLANE_DIR, 'DerivedData')
2424
SCREENSHOTS_DIR = File.join(FASTLANE_DIR, 'screenshots')
2525
FASTLANE_METADATA_FOLDER = File.join(FASTLANE_DIR, 'metadata')
2626
WORKSPACE_PATH = File.join(PROJECT_ROOT_FOLDER, 'WooCommerce.xcworkspace')
27+
28+
# Firebase App Distribution
29+
FIREBASE_APP_ID = '1:124902176124:ios:02259de1e7c42b291620f9'
30+
FIREBASE_TESTERS_GROUP = 'woocommerce-ios---prototype-builds'
31+
2732
BUILDKITE_RELEASE_PIPELINE = 'release-builds.yml'
2833
IOS_LOCALES = %w[ar-SA de-DE en-US es-ES fr-FR he id it ja ko nl-NL pt-BR ru sv tr zh-Hans zh-Hant].freeze
2934
SIMULATOR_VERSION = '18.1' # For screenshots
@@ -51,7 +56,7 @@ MAIN_BUNDLE_IDENTIFIERS = [
5156
].freeze
5257

5358
ALPHA_VERSION_BUNDLE_IDENTIFIER = 'com.automattic.alpha.woocommerce'
54-
# Registered in our Enterprise account, for App Center / Prototype Builds
59+
# Registered in our Enterprise account, for Prototype Builds
5560
ALPHA_BUNDLE_IDENTIFIERS = MAIN_BUNDLE_IDENTIFIERS.map do |id|
5661
id.gsub(APP_STORE_VERSION_BUNDLE_IDENTIFIER, ALPHA_VERSION_BUNDLE_IDENTIFIER)
5762
end.freeze
@@ -738,13 +743,17 @@ platform :ios do
738743

739744
build_for_prototype_build
740745

741-
appcenter_upload(
742-
api_token: get_required_env('APPCENTER_API_TOKEN'),
743-
owner_name: 'automattic',
744-
owner_type: 'organization',
745-
app_name: 'WooCommerce-Installable-Builds',
746-
destinations: 'Collaborators',
747-
notify_testers: false
746+
release_notes = <<~NOTES
747+
Pull Request: ##{pull_request_number || 'N/A'}
748+
Branch: `#{ENV.fetch('BUILDKITE_BRANCH', 'N/A')}`
749+
Commit: #{ENV.fetch('BUILDKITE_COMMIT', 'N/A')[0...7]}
750+
NOTES
751+
752+
firebase_app_distribution(
753+
app: FIREBASE_APP_ID,
754+
service_credentials_json_data: get_required_env('FIREBASE_APP_DISTRIBUTION_ACCOUNT_KEY'),
755+
release_notes: release_notes,
756+
groups: FIREBASE_TESTERS_GROUP
748757
)
749758

750759
sentry_upload_dsym(
@@ -754,21 +763,13 @@ platform :ios do
754763
dsym_path: './build/WooCommerce.app.dSYM.zip'
755764
)
756765

757-
# The build code used in the Enterprise build has a different format that the App Store one.
758-
# We cannot use the standard build_code_current method but have to read it directly.
759-
build_code = Xcodeproj::Config.new(File.new(PUBLIC_CONFIG_FILE)).to_hash[BUILD_CODE_KEY]
760-
UI.message("Successfully built and uploaded prototype build `#{build_code}` to App Center.")
761-
762-
return if ENV['BUILDKITE_PULL_REQUEST'].nil?
766+
next if pull_request_number.nil?
763767

764768
# PR Comment
765-
comment_body = prototype_build_details_comment(
766-
app_display_name: 'WooCommerce iOS',
767-
app_center_org_name: 'automattic'
768-
)
769+
comment_body = prototype_build_details_comment(app_display_name: 'WooCommerce iOS Prototype')
769770
comment_on_pr(
770771
project: GITHUB_REPO,
771-
pr_number: Integer(ENV.fetch('BUILDKITE_PULL_REQUEST')),
772+
pr_number: pull_request_number,
772773
reuse_identifier: 'prototype-build-link',
773774
body: comment_body
774775
)
@@ -778,19 +779,15 @@ platform :ios do
778779
lane :build_for_prototype_build do |fetch_code_signing: true|
779780
update_certs_and_profiles_enterprise if fetch_code_signing
780781

781-
# Get the current build version, and update it if needed
782-
versions = Xcodeproj::Config.new(File.new(PUBLIC_CONFIG_FILE)).to_hash
783-
build_number = generate_prototype_build_number
784-
UI.message("Updating build version to #{build_number}")
785-
versions[BUILD_CODE_KEY] = build_number
786-
new_config = Xcodeproj::Config.new(versions)
787-
new_config.save_as(Pathname.new(PUBLIC_CONFIG_FILE))
782+
build_number = ENV.fetch('BUILDKITE_BUILD_NUMBER', '0')
783+
pr_or_branch = pull_request_number&.then { |num| "PR ##{num}" } || ENV.fetch('BUILDKITE_BRANCH', nil)
788784

789785
gym(
790786
scheme: 'WooCommerce Alpha',
791787
workspace: WORKSPACE_PATH,
792788
export_method: 'enterprise',
793789
clean: true,
790+
xcargs: { BUILD_CODE_KEY => build_number, 'VERSION_SHORT' => pr_or_branch }.compact,
794791
output_directory: 'build',
795792
export_team_id: get_required_env('INT_EXPORT_TEAM_ID'),
796793
export_options: {
@@ -1329,25 +1326,6 @@ lane :test_without_building do |options|
13291326
UI.user_error!("Tests failed with #{tests_result[:number_of_failures_excluding_retries]} failures.") if tests_result[:number_of_failures_excluding_retries].positive?
13301327
end
13311328

1332-
# -----------------------------------------------------------------------------------
1333-
# Generates Prototype Build Version Numbers in a Buildkite-specific way
1334-
# -----------------------------------------------------------------------------------
1335-
def generate_prototype_build_number
1336-
if ENV.key?('BUILDKITE')
1337-
commit = ENV.fetch('BUILDKITE_COMMIT')[0, 7]
1338-
branch = ENV.fetch('BUILDKITE_BRANCH')
1339-
pr_num = ENV.fetch('BUILDKITE_PULL_REQUEST')
1340-
1341-
pr_num == 'false' ? "#{branch}-#{commit}" : "pr#{pr_num}-#{commit}"
1342-
else
1343-
repo = Git.open(PROJECT_ROOT_FOLDER)
1344-
commit = repo.current_branch
1345-
branch = repo.revparse('HEAD')[0, 7]
1346-
1347-
"#{branch}-#{commit}"
1348-
end
1349-
end
1350-
13511329
# -----------------------------------------------------------------------------------
13521330
# Raises an error if Sentry is not installed
13531331
# -----------------------------------------------------------------------------------
@@ -1495,13 +1473,6 @@ def prompt_user_for_app_store_connect_credentials
14951473
ENV['FASTLANE_USER'] = CredentialsManager::AccountManager.new.user
14961474
end
14971475

1498-
def override_default_release_branch(version)
1499-
success = Fastlane::Helper::GitHelper.checkout_and_pull(release: version)
1500-
UI.user_error!("Release branch for version #{version} doesn't exist. Abort.") unless success
1501-
1502-
UI.message("Checked out branch `#{git_branch}` as requested by user.\n")
1503-
end
1504-
15051476
# https://buildkite.com/docs/test-analytics/ci-environments
15061477
TEST_ANALYTICS_ENVIRONMENT = %w[
15071478
BUILDKITE_ANALYTICS_TOKEN
@@ -1517,6 +1488,13 @@ TEST_ANALYTICS_ENVIRONMENT = %w[
15171488
# -----------------------------------------------------------------------------------
15181489
# Release Management Utils
15191490
# -----------------------------------------------------------------------------------
1491+
1492+
def pull_request_number
1493+
# Buildkite sets this env var to the PR number if on a PR, but to 'false' (and not nil) if not on a PR
1494+
pr_num = ENV.fetch('BUILDKITE_PULL_REQUEST', 'false')
1495+
pr_num == 'false' ? nil : Integer(pr_num)
1496+
end
1497+
15201498
def create_backmerge_pr
15211499
version = release_version_current
15221500

fastlane/env/user.env.example

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
GHHELPER_ACCESS=<GitHub access token>
22
SENTRY_AUTH_TOKEN=<Sentry auth token>
33

4-
APPCENTER_API_TOKEN=<AppCenter API Token>
54
CIRCLE_CI_AUTH_TOKEN=<CircleCI Auth Token>

0 commit comments

Comments
 (0)