Skip to content

Commit

Permalink
Added selection certificate and key by ENV MATCH_CERTIFICATE_ID
Browse files Browse the repository at this point in the history
  • Loading branch information
slacklab committed Jul 28, 2023
1 parent 600555c commit 44d47d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions match/lib/match/options.rb
Expand Up @@ -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)
Expand Down Expand Up @@ -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'",
Expand Down
12 changes: 9 additions & 3 deletions match/lib/match/runner.rb
Expand Up @@ -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)
Expand All @@ -199,15 +199,15 @@ 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.")
end

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
Expand All @@ -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)
Expand Down

0 comments on commit 44d47d6

Please sign in to comment.