Class: Match::Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/match/utils.rb

Class Method Summary collapse

Class Method Details

.base_environment_variable_name(app_identifier: nil, type: nil) ⇒ Object



48
49
50
# File 'lib/match/utils.rb', line 48

def self.base_environment_variable_name(app_identifier: nil, type: nil)
  ["sigh", app_identifier, type]
end

.environment_variable_name(app_identifier: nil, type: nil) ⇒ Object



36
37
38
# File 'lib/match/utils.rb', line 36

def self.environment_variable_name(app_identifier: nil, type: nil)
  base_environment_variable_name(app_identifier: app_identifier, type: type).join("_")
end

.environment_variable_name_profile_name(app_identifier: nil, type: nil) ⇒ Object



44
45
46
# File 'lib/match/utils.rb', line 44

def self.environment_variable_name_profile_name(app_identifier: nil, type: nil)
  (base_environment_variable_name(app_identifier: app_identifier, type: type) + ["profile-name"]).join("_")
end

.environment_variable_name_team_id(app_identifier: nil, type: nil) ⇒ Object



40
41
42
# File 'lib/match/utils.rb', line 40

def self.environment_variable_name_team_id(app_identifier: nil, type: nil)
  (base_environment_variable_name(app_identifier: app_identifier, type: type) + ["team-id"]).join("_")
end

.fill_environment(key, value) ⇒ Object

Fill in an environment variable, ready to be used in xcodebuild



31
32
33
34
# File 'lib/match/utils.rb', line 31

def self.fill_environment(key, value)
  UI.important "Setting environment variable '#{key}' to '#{value}'" if $verbose
  ENV[key] = value
end

.import(item_path, keychain, password: "") ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/match/utils.rb', line 3

def self.import(item_path, keychain, password: "")
  # Existing code expects that a keychain name will be expanded into a default path to Libary/Keychains
  # in the user's home directory. However, this will not allow the user to pass an absolute path
  # for the keychain value
  #
  # So, if the passed value can't be resolved as a file in Library/Keychains, just use it as-is
  # as the keychain path.
  #
  # We need to expand each path because File.exist? won't handle directories including ~ properly
  #
  # We also try to append `-db` at the end of the file path, as with Sierra the default Keychain name
  # has changed for some users: https://github.com/fastlane/fastlane/issues/5649
  #
  keychain_paths = [
    File.join(Dir.home, 'Library', 'Keychains', keychain),
    File.join(Dir.home, 'Library', 'Keychains', "#{keychain}-db"),
    keychain,
    "#{keychain}-db"
  ].map { |path| File.expand_path(path) }

  keychain_path = keychain_paths.find { |path| File.exist?(path) }

  UI.user_error!("Could not locate the provided keychain. Tried:\n\t#{keychain_paths.join("\n\t")}") unless keychain_path

  FastlaneCore::KeychainImporter.import_file(item_path, keychain_path, keychain_password: password, output: $verbose)
end