From 44d47d662e28b45c51d24c5f301d7cd5049d8deb Mon Sep 17 00:00:00 2001 From: Ivan Sorokoletov Date: Thu, 27 Jul 2023 10:24:57 +0300 Subject: [PATCH] Added selection certificate and key by ENV MATCH_CERTIFICATE_ID --- match/lib/match/options.rb | 6 ++++++ match/lib/match/runner.rb | 12 +++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/match/lib/match/options.rb b/match/lib/match/options.rb index 8a95cbe5785..a0ed2763042 100644 --- a/match/lib/match/options.rb +++ b/match/lib/match/options.rb @@ -4,6 +4,7 @@ require_relative 'module' module Match + # rubocop:disable Metrics/ClassLength class Options # This is match specific, as users can append storage specific options def self.append_option(option) @@ -268,6 +269,11 @@ def self.available_options description: "Include all matching certificates in the provisioning profile. Works only for the 'development' provisioning profile type", type: Boolean, default_value: false), + FastlaneCore::ConfigItem.new(key: :certificate_id, + env_name: "MATCH_CERTIFICATE_ID", + description: "Selects needed certificate by id. Useful if multiple certificates are stored in one place", + type: String, + optional: true), FastlaneCore::ConfigItem.new(key: :force_for_new_certificates, env_name: "MATCH_FORCE_FOR_NEW_CERTIFICATES", description: "Renew the provisioning profiles if the certificate count on the developer portal has changed. Works only for the 'development' provisioning profile type. Requires 'include_all_certificates' option to be 'true'", diff --git a/match/lib/match/runner.rb b/match/lib/match/runner.rb index 91f022fc700..76e473c20ce 100644 --- a/match/lib/match/runner.rb +++ b/match/lib/match/runner.rb @@ -175,7 +175,7 @@ def fetch_certificate(params: nil, working_directory: nil, specific_cert_type: n self.files_to_commit << cert_path self.files_to_commit << private_key_path else - cert_path = certs.last + cert_path = select_cert_or_key(paths: certs) # Check validity of certificate if Utils.is_cert_valid?(cert_path) @@ -199,7 +199,7 @@ def fetch_certificate(params: nil, working_directory: nil, specific_cert_type: n # Import the private key # there seems to be no good way to check if it's already installed - so just install it # Key will only be added to the partition list if it isn't already installed - Utils.import(keys.last, params[:keychain_name], password: params[:keychain_password]) + Utils.import(select_cert_or_key(paths: keys), params[:keychain_name], password: params[:keychain_password]) end else UI.message("Skipping installation of certificate as it would not work on this operating system.") @@ -207,7 +207,7 @@ def fetch_certificate(params: nil, working_directory: nil, specific_cert_type: n if params[:output_path] FileUtils.cp(cert_path, params[:output_path]) - FileUtils.cp(keys.last, params[:output_path]) + FileUtils.cp(select_cert_or_key(paths: keys), params[:output_path]) end # Get and print info of certificate @@ -218,6 +218,12 @@ def fetch_certificate(params: nil, working_directory: nil, specific_cert_type: n return File.basename(cert_path).gsub(".cer", "") # Certificate ID end + # @return [String] Path to certificate or P12 key + def select_cert_or_key(paths:) + matching_path = ENV['MATCH_CERTIFICATE_ID'] ? paths.find { |path| path.include?(ENV['MATCH_CERTIFICATE_ID']) } : nil + matching_path || paths.last + end + # rubocop:disable Metrics/PerceivedComplexity # @return [String] The UUID of the provisioning profile so we can verify it with the Apple Developer Portal def fetch_provisioning_profile(params: nil, certificate_id: nil, app_identifier: nil, working_directory: nil)