Skip to content

Commit 024fbf8

Browse files
authored
Improve provisioning profiles update workflow from Fastlane (#8658)
2 parents bd681d4 + 9a8bb0f commit 024fbf8

File tree

2 files changed

+45
-31
lines changed

2 files changed

+45
-31
lines changed

fastlane/Fastfile

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -618,13 +618,7 @@ platform :ios do
618618
# We're about to use `add_development_certificates_to_provisioning_profiles` and `add_all_devices_to_provisioning_profiles`.
619619
# These actions use Developer Portal APIs that don't yet support authentication via API key (-.-').
620620
# Let's preemptively ask for and set the email here to avoid being asked twice for it if not set.
621-
622-
require 'credentials_manager'
623-
624-
# If Fastlane cannot instantiate a user, it will ask the caller for the email.
625-
# Once we have it, we can set it as `FASTLANE_USER` in the environment (which has lifecycle limited to this call) so that the next commands will already have access to it.
626-
# Note that if the user is already available to `AccountManager`, setting it in the environment is redundant, but Fastlane doesn't provide a way to check it so we have to do it anyway.
627-
ENV['FASTLANE_USER'] = CredentialsManager::AccountManager.new.user
621+
prompt_user_for_app_store_connect_credentials
628622

629623
# Add all development certificates to the provisioning profiles (just in case – this is an easy step to miss)
630624
add_development_certificates_to_provisioning_profiles(
@@ -930,41 +924,55 @@ platform :ios do
930924
########################################################################
931925
# Configure Lanes
932926
########################################################################
933-
#####################################################################################
934-
# update_certs_and_profiles
935-
# -----------------------------------------------------------------------------------
936-
# This lane downloads all the required certs and profiles and,
937-
# if not run on CI it creates the missing ones.
938-
# -----------------------------------------------------------------------------------
939-
# Usage:
940-
# bundle exec fastlane update_certs_and_profiles
927+
928+
# Downloads all the required certificates and profiles for both production and internal distribution builds.
929+
# Optionally, it can create any new necessary certificate or profile.
941930
#
942-
# Example:
943-
# bundle exec fastlane update_certs_and_profiles
944-
#####################################################################################
945-
lane :update_certs_and_profiles do
946-
alpha_code_signing
947-
appstore_code_signing
931+
# @option [Boolean] readonly (default: true) Whether to only fetch existing certificates and profiles, without generating new ones.
932+
lane :update_certs_and_profiles do |options|
933+
alpha_code_signing(options)
934+
appstore_code_signing(options)
948935
end
949936

950-
########################################################################
951-
# Fastlane match code signing
952-
########################################################################
953-
private_lane :alpha_code_signing do
937+
# Downloads all the required certificates and profiles the enterprise build.
938+
# Optionally, it can create any new necessary certificate or profile.
939+
#
940+
# @option [Boolean] readonly (default: true) Whether to only fetch existing certificates and profiles, without generating new ones.
941+
private_lane :alpha_code_signing do |options|
942+
readonly = options.fetch(:readonly, true)
943+
944+
if readonly
945+
# In readonly mode, we can use the API key
946+
api_key_path = ASC_KEY_PATH
947+
else
948+
# The Enterprise account APIs do not support authentication via API key.
949+
# If we want to modify data (readonly = false) we need to authenticate manually.
950+
prompt_user_for_app_store_connect_credentials
951+
# We also need to pass no API key path, otherwise Fastlane will give
952+
# precedence to that authentication mode.
953+
api_key_path = nil
954+
end
955+
954956
match(
955957
type: 'enterprise',
956958
team_id: get_required_env('INT_EXPORT_TEAM_ID'),
957959
app_identifier: ALPHA_BUNDLE_IDENTIFIERS,
958-
readonly: true
960+
readonly: readonly,
961+
api_key_path: api_key_path
959962
)
960963
end
961964

962-
private_lane :appstore_code_signing do
965+
# Downloads all the required certificates and profiles the production build.
966+
# Optionally, it can create any new necessary certificate or profile.
967+
#
968+
# @option [Boolean] readonly (default: true) Whether to only fetch existing certificates and profiles, without generating new ones.
969+
private_lane :appstore_code_signing do |options|
963970
match(
964971
type: 'appstore',
965972
team_id: get_required_env('EXT_EXPORT_TEAM_ID'),
966973
app_identifier: MAIN_BUNDLE_IDENTIFIERS,
967-
readonly: true
974+
readonly: options.fetch(:readonly, true),
975+
api_key_path: ASC_KEY_PATH
968976
)
969977
end
970978

@@ -1172,6 +1180,15 @@ def buildkite_ci?
11721180
ENV.fetch('BUILDKITE', false)
11731181
end
11741182

1183+
def prompt_user_for_app_store_connect_credentials
1184+
require 'credentials_manager'
1185+
1186+
# If Fastlane cannot instantiate a user, it will ask the caller for the email.
1187+
# Once we have it, we can set it as `FASTLANE_USER` in the environment (which has lifecycle limited to this call) so that the next commands will already have access to it.
1188+
# Note that if the user is already available to `AccountManager`, setting it in the environment is redundant, but Fastlane doesn't provide a way to check it so we have to do it anyway.
1189+
ENV['FASTLANE_USER'] = CredentialsManager::AccountManager.new.user
1190+
end
1191+
11751192
# https://buildkite.com/docs/test-analytics/ci-environments
11761193
TEST_ANALYTICS_ENVIRONMENT = %w[
11771194
BUILDKITE_ANALYTICS_TOKEN

fastlane/Matchfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,3 @@ storage_mode('google_cloud')
77
google_cloud_bucket_name('a8c-fastlane-match')
88
secrets_directory = File.join(Dir.home, '.configure', 'woocommerce-ios', 'secrets')
99
google_cloud_keys_file(File.join(secrets_directory, 'google_cloud_keys.json'))
10-
11-
# Use the decrypted API Key for authentication
12-
api_key_path(File.join(secrets_directory, 'app_store_connect_fastlane_api_key.json'))

0 commit comments

Comments
 (0)