Skip to content

Commit

Permalink
[match] added selection of certificate and p12 key by certificate id (#…
Browse files Browse the repository at this point in the history
…21428)

* Added selection certificate and key by ENV MATCH_CERTIFICATE_ID

* Fixed env var description

* Renamed vars from select_cert_or_key method
  • Loading branch information
slacklab committed Oct 6, 2023
1 parent a615e60 commit e67aab8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions match/lib/match/options.rb
Expand Up @@ -282,6 +282,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: "Select 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 @@ -148,7 +148,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 @@ -172,15 +172,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 @@ -191,6 +191,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:)
cert_id_path = ENV['MATCH_CERTIFICATE_ID'] ? paths.find { |path| path.include?(ENV['MATCH_CERTIFICATE_ID']) } : nil
cert_id_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 e67aab8

Please sign in to comment.