Class: Fastlane::Actions::TestfairyAction

Inherits:
Fastlane::Action show all
Defined in:
fastlane/lib/fastlane/actions/testfairy.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, return_type, return_value, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorsObject



276
277
278
# File 'fastlane/lib/fastlane/actions/testfairy.rb', line 276

def self.authors
  ["taka0125", "tcurdt", "vijaysharm", "cdm2012"]
end

.available_optionsObject



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'fastlane/lib/fastlane/actions/testfairy.rb', line 151

def self.available_options
  [
    # required
    FastlaneCore::ConfigItem.new(key: :api_key,
                                 env_name: "FL_TESTFAIRY_API_KEY", # The name of the environment variable
                                 description: "API Key for TestFairy", # a short description of this parameter
                                 sensitive: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("No API key for TestFairy given, pass using `api_key: 'key'`") unless value.to_s.length > 0
                                 end),
    FastlaneCore::ConfigItem.new(key: :ipa,
                                 env_name: 'TESTFAIRY_IPA_PATH',
                                 description: 'Path to your IPA file for iOS',
                                 default_value: Actions.lane_context[SharedValues::IPA_OUTPUT_PATH],
                                 default_value_dynamic: true,
                                 optional: true,
                                 conflicting_options: [:apk],
                                 verify_block: proc do |value|
                                   UI.user_error!("Couldn't find ipa file at path '#{value}'") unless File.exist?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :apk,
                                 env_name: 'TESTFAIRY_APK_PATH',
                                 description: 'Path to your APK file for Android',
                                 default_value: Actions.lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH],
                                 default_value_dynamic: true,
                                 optional: true,
                                 conflicting_options: [:ipa],
                                 verify_block: proc do |value|
                                   UI.user_error!("Couldn't find apk file at path '#{value}'") unless File.exist?(value)
                                 end),
    # optional
    FastlaneCore::ConfigItem.new(key: :symbols_file,
                                 optional: true,
                                 env_name: "FL_TESTFAIRY_SYMBOLS_FILE",
                                 description: "Symbols mapping file",
                                 default_value: Actions.lane_context[SharedValues::DSYM_OUTPUT_PATH],
                                 default_value_dynamic: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("Couldn't find dSYM file at path '#{value}'") unless File.exist?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :upload_url,
                                 env_name: "FL_TESTFAIRY_UPLOAD_URL", # The name of the environment variable
                                 description: "API URL for TestFairy", # a short description of this parameter
                                 default_value: "https://upload.testfairy.com",
                                 is_string: true,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :testers_groups,
                                 optional: true,
                                 type: Array,
                                 short_option: '-g',
                                 env_name: "FL_TESTFAIRY_TESTERS_GROUPS",
                                 description: "Array of tester groups to be notified",
                                 default_value: []), # the default value is an empty list
    FastlaneCore::ConfigItem.new(key: :metrics,
                                 optional: true,
                                 type: Array,
                                 env_name: "FL_TESTFAIRY_METRICS",
                                 description: "Array of metrics to record (cpu,memory,network,phone_signal,gps,battery,mic,wifi)",
                                 default_value: []),
    # max-duration
    # video
    # video-quality
    # video-rate
    FastlaneCore::ConfigItem.new(key: :comment,
                                 optional: true,
                                 env_name: "FL_TESTFAIRY_COMMENT",
                                 description: "Additional release notes for this upload. This text will be added to email notifications",
                                 default_value: 'No comment provided'), # the default value if the user didn't provide one
    FastlaneCore::ConfigItem.new(key: :auto_update,
                                 optional: true,
                                 env_name: "FL_TESTFAIRY_AUTO_UPDATE",
                                 description: "Allows an easy upgrade of all users to the current version. To enable set to 'on'",
                                 default_value: 'off'),
    # not well documented
    FastlaneCore::ConfigItem.new(key: :notify,
                                 optional: true,
                                 env_name: "FL_TESTFAIRY_NOTIFY",
                                 description: "Send email to testers",
                                 default_value: 'off'),
    FastlaneCore::ConfigItem.new(key: :options,
                                 optional: true,
                                 type: Array,
                                 env_name: "FL_TESTFAIRY_OPTIONS",
                                 description: "Array of options (shake,video_only_wifi,anonymous)",
                                 default_value: []),
    FastlaneCore::ConfigItem.new(key: :custom,
                                 optional: true,
                                 env_name: "FL_TESTFAIRY_CUSTOM",
                                 description: "Array of custom options. Contact [email protected] for more information",
                                 default_value: ''),
    FastlaneCore::ConfigItem.new(key: :timeout,
                                 env_name: "FL_TESTFAIRY_TIMEOUT",
                                 description: "Request timeout in seconds",
                                 type: Integer,
                                 optional: true)
  ]
end

.categoryObject



264
265
266
# File 'fastlane/lib/fastlane/actions/testfairy.rb', line 264

def self.category
  :beta
end

.descriptionObject



143
144
145
# File 'fastlane/lib/fastlane/actions/testfairy.rb', line 143

def self.description
  'Upload a new build to [TestFairy](https://www.testfairy.com/)'
end

.detailsObject



147
148
149
# File 'fastlane/lib/fastlane/actions/testfairy.rb', line 147

def self.details
  "You can retrieve your API key on [your settings page](https://free.testfairy.com/settings/)"
end

.example_codeObject



249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'fastlane/lib/fastlane/actions/testfairy.rb', line 249

def self.example_code
  [
    'testfairy(
      api_key: "...",
      ipa: "./ipa_file.ipa",
      comment: "Build #{lane_context[SharedValues::BUILD_NUMBER]}",
    )',
    'testfairy(
      api_key: "...",
      apk: "../build/app/outputs/apk/qa/release/app-qa-release.apk",
      comment: "Build #{lane_context[SharedValues::BUILD_NUMBER]}",
     )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



280
281
282
# File 'fastlane/lib/fastlane/actions/testfairy.rb', line 280

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

.outputObject



268
269
270
271
272
273
274
# File 'fastlane/lib/fastlane/actions/testfairy.rb', line 268

def self.output
  [
    ['TESTFAIRY_BUILD_URL', 'URL for the sessions of the newly uploaded build'],
    ['TESTFAIRY_DOWNLOAD_URL', 'URL directly to the newly uploaded build'],
    ['TESTFAIRY_LANDING_PAGE', 'URL of the build\'s landing page']
  ]
end

.run(params) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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
# File 'fastlane/lib/fastlane/actions/testfairy.rb', line 43

def self.run(params)
  UI.success('Starting with ipa upload to TestFairy...')

  metrics_to_client = lambda do |metrics|
    metrics.map do |metric|
      case metric
      when :cpu, :memory, :network, :gps, :battery, :mic, :wifi
        metric.to_s
      when :phone_signal
        'phone-signal'
      else
        UI.user_error!("Unknown metric: #{metric}")
      end
    end
  end

  options_to_client = lambda do |options|
    options.map do |option|
      case option.to_sym
      when :shake, :anonymous
        option.to_s
      when :video_only_wifi
        'video-only-wifi'
      else
        UI.user_error!("Unknown option: #{option}")
      end
    end
  end

  # Rejecting key `upload_url` and `timeout` as we don't need it in options
  client_options = Hash[params.values.reject do |key, value|
    [:upload_url, :timeout].include?(key)
  end.map do |key, value|
    case key
    when :api_key
      [key, value]
    when :ipa
      [key, value]
    when :apk
      [key, value]
    when :symbols_file
      [key, value]
    when :testers_groups
      [key, value.join(',')]
    when :metrics
      [key, metrics_to_client.call(value).join(',')]
    when :comment
      [key, value]
    when :auto_update
      ['auto-update', value]
    when :notify
      [key, value]
    when :options
      [key, options_to_client.call(value).join(',')]
    when :custom
      [key, value]
    else
      UI.user_error!("Unknown parameter: #{key}")
    end
  end]

  path = params[:ipa] || params[:apk]
  UI.user_error!("No ipa or apk were given") unless path

  return path if Helper.test?

  response = self.upload_build(params[:upload_url], path, client_options, params[:timeout])
  if parse_response(response)
    UI.success("Build URL: #{Actions.lane_context[SharedValues::TESTFAIRY_BUILD_URL]}")
    UI.success("Download URL: #{Actions.lane_context[SharedValues::TESTFAIRY_DOWNLOAD_URL]}")
    UI.success("Landing Page URL: #{Actions.lane_context[SharedValues::TESTFAIRY_LANDING_PAGE]}")
    UI.success("Build successfully uploaded to TestFairy.")
  else
    UI.user_error!("Error when trying to upload ipa to TestFairy")
  end
end

.upload_build(upload_url, ipa, options, timeout) ⇒ Object



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
# File 'fastlane/lib/fastlane/actions/testfairy.rb', line 10

def self.upload_build(upload_url, ipa, options, timeout)
  require 'faraday'
  require 'faraday_middleware'

  UI.success("Uploading to #{upload_url}...")

  connection = Faraday.new(url: upload_url) do |builder|
    builder.request(:multipart)
    builder.request(:url_encoded)
    builder.request(:retry, max: 3, interval: 5)
    builder.response(:json, content_type: /\bjson$/)
    builder.use(FaradayMiddleware::FollowRedirects)
    builder.adapter(:net_http)
  end

  options[:file] = Faraday::UploadIO.new(ipa, 'application/octet-stream') if ipa && File.exist?(ipa)

  symbols_file = options.delete(:symbols_file)
  if symbols_file
    options[:symbols_file] = Faraday::UploadIO.new(symbols_file, 'application/octet-stream')
  end

  begin
    connection.post do |req|
      req.options.timeout = timeout
      req.url("/api/upload/")
      req.body = options
    end
  rescue Faraday::TimeoutError
    UI.crash!("Uploading build to TestFairy timed out ⏳")
  end
end