Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[match] added selection of certificate and p12 key by certificate id #21428

Merged
merged 3 commits into from Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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: "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 @@ -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:)
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