Class: Fastlane::Actions::SetupCiAction

Inherits:
Fastlane::Action show all
Defined in:
fastlane/lib/fastlane/actions/setup_ci.rb

Constant Summary

Constants inherited from Fastlane::Action

Fastlane::Action::AVAILABLE_CATEGORIES, Fastlane::Action::RETURN_TYPES

Documentation collapse

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, author, deprecated_notes, lane_context, method_missing, other_action, output, return_type, return_value, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorsObject



125
126
127
# File 'fastlane/lib/fastlane/actions/setup_ci.rb', line 125

def self.authors
  ["mollyIV", "svenmuennich"]
end

.available_optionsObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'fastlane/lib/fastlane/actions/setup_ci.rb', line 90

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :force,
                                 env_name: "FL_SETUP_CI_FORCE",
                                 description: "Force setup, even if not executed by CI",
                                 type: Boolean,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :provider,
                                 env_name: "FL_SETUP_CI_PROVIDER",
                                 description: "CI provider. If none is set, the provider is detected automatically",
                                 optional: true,
                                 verify_block: proc do |value|
                                   value = value.to_s
                                   # Validate both 'travis' and 'circleci' for backwards compatibility, even
                                   # though only the latter receives special treatment by this action
                                   UI.user_error!("A given CI provider '#{value}' is not supported. Available CI providers: 'travis', 'circleci'") unless ["travis", "circleci"].include?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :timeout,
                                 env_name: "FL_SETUP_CI_TIMEOUT",
                                 description: "Set a custom timeout in seconds for keychain.  Set `0` if you want to specify 'no time-out'",
                                 type: Integer,
                                 default_value: 3600),
    FastlaneCore::ConfigItem.new(key: :keychain_name,
                                 env_name: "FL_SETUP_CI_KEYCHAIN_NAME",
                                 description: "Set a custom keychain name",
                                 type: String,
                                 default_value: "fastlane_tmp_keychain"),
    FastlaneCore::ConfigItem.new(key: :set_default_keychain,
                                 env_name: "FL_SETUP_CI_SET_DEFAULT_KEYCHAIN",
                                 description: "Set the temporary keychain as the system default",
                                 type: Boolean,
                                 default_value: true)
  ]
end

.categoryObject



150
151
152
# File 'fastlane/lib/fastlane/actions/setup_ci.rb', line 150

def self.category
  :misc
end

.descriptionObject



73
74
75
# File 'fastlane/lib/fastlane/actions/setup_ci.rb', line 73

def self.description
  "Setup the keychain and match to work with CI"
end

.detailsObject



77
78
79
80
81
82
83
84
85
86
87
88
# File 'fastlane/lib/fastlane/actions/setup_ci.rb', line 77

def self.details
  list = <<-LIST.markdown_list(true)
      Creates a new temporary keychain for use with match
      Switches match to `readonly` mode to not create new profiles/cert on CI
      Sets up log and test result paths to be easily collectible
    LIST

  [
    list,
    "This action helps with CI integration. Add this to the top of your Fastfile if you use CI."
  ].join("\n")
end

.detect_provider(params) ⇒ Object



22
23
24
# File 'fastlane/lib/fastlane/actions/setup_ci.rb', line 22

def self.detect_provider(params)
  params[:provider] || (Helper.is_circle_ci? ? 'circleci' : nil) || (Helper.is_codebuild? ? 'codebuild' : nil)
end

.example_codeObject



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'fastlane/lib/fastlane/actions/setup_ci.rb', line 133

def self.example_code
  [
    'setup_ci(
      provider: "circleci"
    )',
    'setup_ci(
      provider: "circleci",
      timeout: 0
    )',
    'setup_ci(
      provider: "circleci",
      timeout: 0,
      keychain_name: "custom_keychain_name"
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



129
130
131
# File 'fastlane/lib/fastlane/actions/setup_ci.rb', line 129

def self.is_supported?(platform)
  [:ios, :mac].include?(platform)
end

.run(params) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'fastlane/lib/fastlane/actions/setup_ci.rb', line 4

def self.run(params)
  unless should_run?(params)
    UI.message("Not running on CI, skipping CI setup")
    return
  end

  case detect_provider(params)
  when 'circleci', 'codebuild'
    setup_output_paths
  end

  setup_keychain(params)
end

.setup_keychain(params) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'fastlane/lib/fastlane/actions/setup_ci.rb', line 26

def self.setup_keychain(params)
  unless Helper.mac?
    UI.message("Skipping Keychain setup on non-macOS CI Agent")
    return
  end

  unless ENV["MATCH_KEYCHAIN_NAME"].nil?
    UI.message("Skipping Keychain setup as a keychain was already specified")
    return
  end

  keychain_name = params[:keychain_name]
  ENV["MATCH_KEYCHAIN_NAME"] = keychain_name
  ENV["MATCH_KEYCHAIN_PASSWORD"] = ""

  UI.message("Creating temporary keychain: \"#{keychain_name}\".")
  Actions::CreateKeychainAction.run(
    name: keychain_name,
    default_keychain: params[:set_default_keychain],
    unlock: true,
    timeout: params[:timeout],
    lock_when_sleeps: true,
    password: "",
    add_to_search_list: true
  )

  UI.message("Enabling match readonly mode.")
  ENV["MATCH_READONLY"] = true.to_s
end

.setup_output_pathsObject



56
57
58
59
60
61
62
63
64
65
66
67
# File 'fastlane/lib/fastlane/actions/setup_ci.rb', line 56

def self.setup_output_paths
  unless ENV["FL_OUTPUT_DIR"]
    UI.message("Skipping Log Path setup as FL_OUTPUT_DIR is unset")
    return
  end

  root = Pathname.new(ENV["FL_OUTPUT_DIR"])
  ENV["SCAN_OUTPUT_DIRECTORY"] = (root + "scan").to_s
  ENV["GYM_OUTPUT_DIRECTORY"] = (root + "gym").to_s
  ENV["FL_BUILDLOG_PATH"] = (root + "buildlogs").to_s
  ENV["SCAN_INCLUDE_SIMULATOR_LOGS"] = true.to_s
end

.should_run?(params) ⇒ Boolean

Returns:



18
19
20
# File 'fastlane/lib/fastlane/actions/setup_ci.rb', line 18

def self.should_run?(params)
  Helper.ci? || params[:force]
end