Skip to content

Commit 4e1ad5e

Browse files
committed
Improve provisioning profiles update workflow from Fastlane
The previous setup worked great in `readonly = true` mode, but would consistently fail with `readonly = false` because Apple's Enterprise portal does not support authentication via API key. Before this change, we'd hack our way through it by commenting and editing code to run the public App Store automation as usual, and the Enterprise one with manual authentication. With this change, we can call `CODE_SIGNING_READONLY=1 bundle exec fastlane update_certs_and_profiles` and be prompted for credentials when necessary. No more editing `Fastfile` and discarding changes required.
1 parent 898b82d commit 4e1ad5e

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

fastlane/Fastfile

Lines changed: 32 additions & 9 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(
@@ -951,11 +945,30 @@ platform :ios do
951945
# Fastlane match code signing
952946
########################################################################
953947
private_lane :alpha_code_signing do
948+
api_key_path = ASC_KEY_PATH
949+
950+
# We could implement a more refined ENV to boolean conversion to support
951+
# 1, yes, etc. but for the moment and given the limited scope of this tool
952+
# and feature, we can implicitly expect CODE_SIGNING_READONLY to be a
953+
# 'true' or 'false' string.
954+
readonly = ENV.fetch('CODE_SIGNING_READONLY', 'true').to_s.downcase == 'true'
955+
956+
unless readonly
957+
# The Enterprise account APIs do not support authentication via API key.
958+
# If we want to modify data (readonly = false) we need to authenticate
959+
# manually.
960+
prompt_user_for_app_store_connect_credentials
961+
# We also need to pass no API key path, otherwise Fastlane will give
962+
# precedence to that authentication mode.
963+
api_key_path = nil
964+
end
965+
954966
match(
955967
type: 'enterprise',
956968
team_id: get_required_env('INT_EXPORT_TEAM_ID'),
957969
app_identifier: ALPHA_BUNDLE_IDENTIFIERS,
958-
readonly: true
970+
readonly: readonly,
971+
api_key_path: api_key_path
959972
)
960973
end
961974

@@ -964,7 +977,8 @@ platform :ios do
964977
type: 'appstore',
965978
team_id: get_required_env('EXT_EXPORT_TEAM_ID'),
966979
app_identifier: MAIN_BUNDLE_IDENTIFIERS,
967-
readonly: true
980+
readonly: false,
981+
api_key_path: ASC_KEY_PATH
968982
)
969983
end
970984

@@ -1172,6 +1186,15 @@ def buildkite_ci?
11721186
ENV.fetch('BUILDKITE', false)
11731187
end
11741188

1189+
def prompt_user_for_app_store_connect_credentials
1190+
require 'credentials_manager'
1191+
1192+
# If Fastlane cannot instantiate a user, it will ask the caller for the email.
1193+
# 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.
1194+
# 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.
1195+
ENV['FASTLANE_USER'] = CredentialsManager::AccountManager.new.user
1196+
end
1197+
11751198
# https://buildkite.com/docs/test-analytics/ci-environments
11761199
TEST_ANALYTICS_ENVIRONMENT = %w[
11771200
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)