class Fastlane::Actions::EnSetupKeychainAction

Public Class Methods

authors() click to toggle source
# File lib/fastlane/plugin/ciutils/actions/en_setup_keychain.rb, line 92
def self.authors
  ["Nicolae Ghimbovschi"]
end
available_options() click to toggle source
# File lib/fastlane/plugin/ciutils/actions/en_setup_keychain.rb, line 66
def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :name,
                                 env_name: "EN_KEYCHAIN_NAME",
                                 description: "Keychain name",
                                 is_string: true, # true: verifies the input is a string, false: every kind of value
                                 default_value: "fastlane"), # the default value if the user didn't provide one
    FastlaneCore::ConfigItem.new(key: :certp12_path,
                                 env_name: "EN_CERTP12_PATH",
                                 description: "Certificate to import",
                                 is_string: true, # true: verifies the input is a string, false: every kind of value
                                 default_value: "cert.p12"), # the default value if the user didn't provide one
    FastlaneCore::ConfigItem.new(key: :certp12_password,
                                 env_name: "EN_CERTP12_PASSWORD",
                                 description: "Password of the Certificate to import. Should be relative to the fastlane folder, or full path",
                                 is_string: true, # true: verifies the input is a string, false: every kind of value
                                 default_value: "password") # the default value if the user didn't provide one
  ]
end
description() click to toggle source

@!group Documentation

# File lib/fastlane/plugin/ciutils/actions/en_setup_keychain.rb, line 56
def self.description
  "Creates the keychain, and imports the provided certificate"
end
details() click to toggle source
# File lib/fastlane/plugin/ciutils/actions/en_setup_keychain.rb, line 60
      def self.details
        "The default value for the keychain name is 'fastlane'.
It removes the keychain if exists.
The certificate path should be relative to fastlane folder or full path"
      end
is_supported?(platform) click to toggle source
# File lib/fastlane/plugin/ciutils/actions/en_setup_keychain.rb, line 96
def self.is_supported?(platform)
  true
end
output() click to toggle source
# File lib/fastlane/plugin/ciutils/actions/en_setup_keychain.rb, line 86
def self.output
  [
    ['EN_KEYCHAIN_NAME', 'The name of the created keychain']
  ]
end
remove_keychain_if_exists(keychain_name) click to toggle source
# File lib/fastlane/plugin/ciutils/actions/en_setup_keychain.rb, line 45
def self.remove_keychain_if_exists(keychain_name)    
  begin
    other_action.delete_keychain(name: keychain_name)
  rescue
  end
end
run(params) click to toggle source
# File lib/fastlane/plugin/ciutils/actions/en_setup_keychain.rb, line 8
def self.run(params)
  keychain_name = params[:name]
  keychain_password = "password"

  self.remove_keychain_if_exists(keychain_name)

  other_action.create_keychain(
    name: keychain_name,
    default_keychain: false,
    unlock: true,
    timeout: 9600,
    lock_when_sleeps: false,
    password: keychain_password
  )

  # set shared var
  current_keychain_name = Helper::CiutilsHelper.en_keychain_name(keychain_name)
  Actions.lane_context[SharedValues::EN_KEYCHAIN_NAME] = current_keychain_name
  ENV['MATCH_KEYCHAIN_NAME'] = keychain_name
  ENV['MATCH_KEYCHAIN_PASSWORD'] = keychain_password

  cert_path = params[:certp12_path]
  unless File.exist?(cert_path)
    UI.message("Skipping keychain certificate import. File doesn't exist.")
    return
  end

  cert_path = "../#{cert_path}"

  other_action.import_certificate(
    keychain_name: current_keychain_name,
    keychain_password: keychain_password,
    certificate_path: cert_path,
    certificate_password: params[:certp12_password]
  )
end