Class: Fastlane::Actions::CrashlyticsAction

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/actions/crashlytics.rb

Class Method Summary collapse

Class Method Details

.assert_valid_api_token!(token) ⇒ Object



54
55
56
57
# File 'lib/fastlane/actions/crashlytics.rb', line 54

def self.assert_valid_api_token!(token)
  return unless token.nil? || token.empty?
  raise "No API token for Crashlytics given, pass using `api_token: 'token'`".red
end

.assert_valid_build_secret!(build_secret) ⇒ Object



59
60
61
62
# File 'lib/fastlane/actions/crashlytics.rb', line 59

def self.assert_valid_build_secret!(build_secret)
  return unless build_secret.nil? || build_secret.empty?
  raise "No build secret for Crashlytics given, pass using `build_secret: 'secret'`".red
end

.assert_valid_crashlytics_path!(crashlytics_path) ⇒ Object



49
50
51
52
# File 'lib/fastlane/actions/crashlytics.rb', line 49

def self.assert_valid_crashlytics_path!(crashlytics_path)
  return if crashlytics_path && File.exists?(crashlytics_path)
  raise "No Crashlytics path given or found, pass using `crashlytics_path: 'path'`".red
end

.assert_valid_ipa_path!(ipa_path) ⇒ Object



64
65
66
67
# File 'lib/fastlane/actions/crashlytics.rb', line 64

def self.assert_valid_ipa_path!(ipa_path)
  return if ipa_path && File.exists?(ipa_path)
  raise "No IPA file given or found, pass using `ipa_path: 'path/app.ipa'`".red
end

.assert_valid_params!(crashlytics_path, api_token, build_secret, ipa_path) ⇒ Object



42
43
44
45
46
47
# File 'lib/fastlane/actions/crashlytics.rb', line 42

def self.assert_valid_params!(crashlytics_path, api_token, build_secret, ipa_path)
  assert_valid_crashlytics_path!(crashlytics_path)
  assert_valid_api_token!(api_token)
  assert_valid_build_secret!(build_secret)
  assert_valid_ipa_path!(ipa_path)
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
# File 'lib/fastlane/actions/crashlytics.rb', line 8

def self.run(params)
  require "shenzhen"
  require "shenzhen/plugins/crashlytics"

  params = params.first

  raise "You have to pass Crashlytics parameters to the Crashlytics action, take a look at https://github.com/KrauseFx/fastlane#crashlytics".red unless params

  crashlytics_path = params[:crashlytics_path]
  api_token        = params[:api_token]
  build_secret     = params[:build_secret]
  ipa_path         = params[:ipa_path]
  notes_path       = params[:notes_path]
  emails           = params[:emails]
  groups           = params[:groups]

  assert_valid_params!(crashlytics_path, api_token, build_secret, ipa_path)

  Helper.log.info "Uploading the IPA to Crashlytics. Go for a coffee ☕️.".green

  return if Helper.is_test?

  client = Shenzhen::Plugins::Crashlytics::Client.new(crashlytics_path, api_token, build_secret)

  response = client.upload_build(ipa_path, file: ipa_path, notes: notes_path, emails: emails, groups: groups)

  if response
    Helper.log.info "Build successfully uploaded to Crashlytics".green
  else
    Helper.log.fatal "Error uploading to Crashlytics."
    raise "Error when trying to upload ipa to Crashlytics".red
  end
end