Class: Fastlane::Actions::EnSetupKeychainAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/ciutils/actions/en_setup_keychain.rb

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



92
93
94
# File 'lib/fastlane/plugin/ciutils/actions/en_setup_keychain.rb', line 92

def self.authors
  ["Nicolae Ghimbovschi"]
end

.available_optionsObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# 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

.descriptionObject



56
57
58
# File 'lib/fastlane/plugin/ciutils/actions/en_setup_keychain.rb', line 56

def self.description
  "Creates the keychain, and imports the provided certificate"
end

.detailsObject



60
61
62
63
64
# 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) ⇒ Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/fastlane/plugin/ciutils/actions/en_setup_keychain.rb', line 96

def self.is_supported?(platform)
  true
end

.outputObject



86
87
88
89
90
# 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) ⇒ Object



45
46
47
48
49
50
# 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) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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