From d924c2a99598ae3e84cdd9b2566cb28dd49078f8 Mon Sep 17 00:00:00 2001 From: Vladimir Makarov Date: Fri, 14 Oct 2022 17:22:46 +0500 Subject: [PATCH 1/2] API key configuration with environment variable added --- xcode/commonFastfile | 45 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 0c00145..1d86cad 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -64,6 +64,7 @@ def upload_to_app_store_using_options(options) upload_to_app_store( username: options[:username] || options[:apple_id], api_key_path: options[:api_key_path], + api_key: options[:api_key], ipa: options[:ipa_path], force: true, # skip metainfo prompt skip_metadata: true, @@ -348,6 +349,7 @@ def sync_code_signing_using_options(options) app_identifier: options[:app_identifier], username: options[:username] || options[:apple_id], api_key_path: options[:api_key_path], + api_key: options[:api_key], team_id: options[:team_id], type: options[:type], readonly: options[:readonly].nil? ? true : options[:readonly], @@ -372,13 +374,48 @@ end def fill_up_options_using_configuration_type(options, configuration_type) configuration = get_configuration_for_type(configuration_type.type) + api_key_json_path = File.expand_path "../fastlane/#{configuration_type.prefix}_api_key.json" + is_api_key_file_exists = File.exists?(api_key_json_path) + + api_key_path = nil + api_key = nil + + # Check whether configuration type is required to configure one of api key parameters or not + if configuration_type.is_app_store || configuration_type.is_development - api_key_path = "fastlane/#{configuration_type.prefix}_api_key.json" - else - api_key_path = nil + + # Check whether API key JSON file exists or not + + if is_api_key_file_exists + + # If exists then fill in all required information through api_key_path parameter + + api_key_path = "fastlane/#{configuration_type.prefix}_api_key.json" + else + + require 'json' + + # If doesn't exist then build api_key parameter through app_store_connect_api_key action + + api_key_parameters = JSON.parse(ENV['API_KEY_JSON']) + + api_key = app_store_connect_api_key( + key_id: api_key_parameters['key_id'], + issuer_id: api_key_parameters['issuer_id'], + key_content: api_key_parameters['key'], + duration: api_key_parameters['duration'], + in_house: api_key_parameters['in_house'] + ) + end end - default_options = {:api_key_path => api_key_path} + # Setting required parameter depending on API key JSON file existence + + if is_api_key_file_exists + default_options = {:api_key_path => api_key_path} + else + default_options = {:api_key => api_key} + end default_options .merge(configuration.to_options) From 7c22f6e4fc2ee0908e5a9d2a36e576090dcbfa4b Mon Sep 17 00:00:00 2001 From: Vladimir Makarov Date: Mon, 17 Oct 2022 17:47:18 +0500 Subject: [PATCH 2/2] app_store_connect_api_key action calling moved to a separate method, api_key_path used directly --- xcode/commonFastfile | 45 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 1d86cad..40539c1 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -374,11 +374,8 @@ end def fill_up_options_using_configuration_type(options, configuration_type) configuration = get_configuration_for_type(configuration_type.type) - api_key_json_path = File.expand_path "../fastlane/#{configuration_type.prefix}_api_key.json" - is_api_key_file_exists = File.exists?(api_key_json_path) - - api_key_path = nil - api_key = nil + api_key_path = File.expand_path "../fastlane/#{configuration_type.prefix}_api_key.json" + is_api_key_file_exists = File.exists?(api_key_path) # Check whether configuration type is required to configure one of api key parameters or not @@ -389,40 +386,38 @@ def fill_up_options_using_configuration_type(options, configuration_type) if is_api_key_file_exists # If exists then fill in all required information through api_key_path parameter + # and set a value to an options` parameter respectively - api_key_path = "fastlane/#{configuration_type.prefix}_api_key.json" + default_options = {:api_key_path => api_key_path} else - require 'json' - # If doesn't exist then build api_key parameter through app_store_connect_api_key action + # and set a value to an options` parameter respectively also - api_key_parameters = JSON.parse(ENV['API_KEY_JSON']) - - api_key = app_store_connect_api_key( - key_id: api_key_parameters['key_id'], - issuer_id: api_key_parameters['issuer_id'], - key_content: api_key_parameters['key'], - duration: api_key_parameters['duration'], - in_house: api_key_parameters['in_house'] - ) + default_options = {:api_key => get_app_store_connect_api_key()} end end - # Setting required parameter depending on API key JSON file existence - - if is_api_key_file_exists - default_options = {:api_key_path => api_key_path} - else - default_options = {:api_key => api_key} - end - default_options .merge(configuration.to_options) .merge(get_keychain_options(options)) .merge(options) end +def get_app_store_connect_api_key() + require 'json' + + api_key_parameters = JSON.parse(ENV['API_KEY_JSON']) + + return app_store_connect_api_key( + key_id: api_key_parameters['key_id'], + issuer_id: api_key_parameters['issuer_id'], + key_content: api_key_parameters['key'], + duration: api_key_parameters['duration'], + in_house: api_key_parameters['in_house'] + ) +end + def get_keychain_options(options) keychain_name = options[:keychain_name] keychain_password = options[:keychain_password]