Class: Fastlane::Actions::CrashlyticsAction

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

Constant Summary

Constants inherited from Fastlane::Action

Fastlane::Action::AVAILABLE_CATEGORIES

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, authors, lane_context, method_missing, other_action, output, return_value, sample_return_value, sh, step_text

Class Method Details

.authorObject



154
155
156
# File 'lib/fastlane/actions/crashlytics.rb', line 154

def self.author
  ["KrauseFx", "pedrogimenez"]
end

.available_optionsObject



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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/fastlane/actions/crashlytics.rb', line 64

def self.available_options
  platform = Actions.lane_context[Actions::SharedValues::PLATFORM_NAME]

  if platform == :ios or platform.nil?
    ipa_path_default = Dir["*.ipa"].last
  end

  if platform == :android
    apk_path_default = Dir["*.apk"].last || Dir[File.join("app", "build", "outputs", "apk", "app-release.apk")].last
  end

  [
    # iOS Specific
    FastlaneCore::ConfigItem.new(key: :ipa_path,
                                 env_name: "CRASHLYTICS_IPA_PATH",
                                 description: "Path to your IPA file. Optional if you use the _gym_ or _xcodebuild_ action",
                                 default_value: Actions.lane_context[SharedValues::IPA_OUTPUT_PATH] || ipa_path_default,
                                 optional: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("Couldn't find ipa file at path '#{value}'") unless File.exist?(value)
                                 end),
    # Android Specific
    FastlaneCore::ConfigItem.new(key: :apk_path,
                                 env_name: "CRASHLYTICS_APK_PATH",
                                 description: "Path to your APK file",
                                 default_value: Actions.lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH] || apk_path_default,
                                 optional: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("Couldn't find apk file at path '#{value}'") unless File.exist?(value)
                                 end),
    # General
    FastlaneCore::ConfigItem.new(key: :crashlytics_path,
                                 env_name: "CRASHLYTICS_FRAMEWORK_PATH",
                                 description: "Path to the submit binary in the Crashlytics bundle (iOS) or `crashlytics-devtools.jar` file (Android)",
                                 optional: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("Couldn't find crashlytics at path '#{File.expand_path(value)}'`") unless File.exist?(File.expand_path(value))
                                 end),
    FastlaneCore::ConfigItem.new(key: :api_token,
                                 env_name: "CRASHLYTICS_API_TOKEN",
                                 description: "Crashlytics Beta API Token",
                                 verify_block: proc do |value|
                                   UI.user_error!("No API token for Crashlytics given, pass using `api_token: 'token'`") unless value && !value.empty?
                                 end),
    FastlaneCore::ConfigItem.new(key: :build_secret,
                                 env_name: "CRASHLYTICS_BUILD_SECRET",
                                 description: "Crashlytics Build Secret",
                                 verify_block: proc do |value|
                                   UI.user_error!("No build secret for Crashlytics given, pass using `build_secret: 'secret'`") unless value && !value.empty?
                                 end),
    FastlaneCore::ConfigItem.new(key: :notes_path,
                                 env_name: "CRASHLYTICS_NOTES_PATH",
                                 description: "Path to the release notes",
                                 optional: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("Path '#{value}' not found") unless File.exist?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :notes,
                                 env_name: "CRASHLYTICS_NOTES",
                                 description: "The release notes as string - uses :notes_path under the hood",
                                 optional: true,
                                 is_string: true),
    FastlaneCore::ConfigItem.new(key: :groups,
                                 env_name: "CRASHLYTICS_GROUPS",
                                 description: "The groups used for distribution, separated by commas",
                                 optional: true,
                                 is_string: false),
    FastlaneCore::ConfigItem.new(key: :emails,
                                 env_name: "CRASHLYTICS_EMAILS",
                                 description: "Pass email addresses of testers, separated by commas",
                                 optional: true,
                                 is_string: false),
    FastlaneCore::ConfigItem.new(key: :notifications,
                                 env_name: "CRASHLYTICS_NOTIFICATIONS",
                                 description: "Crashlytics notification option (true/false)",
                                 default_value: true,
                                 is_string: false),
    FastlaneCore::ConfigItem.new(key: :debug,
                                 env_name: "CRASHLYTICS_DEBUG",
                                 description: "Crashlytics debug option (true/false)",
                                 default_value: false,
                                 is_string: false)

  ]
end

.categoryObject



177
178
179
# File 'lib/fastlane/actions/crashlytics.rb', line 177

def self.category
  :beta
end

.descriptionObject



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

def self.description
  "Upload a new build to Crashlytics Beta"
end

.detailsObject



158
159
160
161
162
163
# File 'lib/fastlane/actions/crashlytics.rb', line 158

def self.details
  [
    "Additionally you can specify `notes`, `emails`, `groups` and `notifications`.",
    "Distributing to Groups: When using the `groups` parameter, it's important to use the group **alias** names for each group you'd like to distribute to. A group's alias can be found in the web UI. If you're viewing the Beta page, you can open the groups dialog here:"
  ].join("\n")
end

.example_codeObject



165
166
167
168
169
170
171
172
173
174
175
# File 'lib/fastlane/actions/crashlytics.rb', line 165

def self.example_code
  [
    'crashlytics',
    'crashlytics(
      crashlytics_path: "./Pods/Crashlytics/", # path to your Crashlytics submit binary.
      api_token: "...",
      build_secret: "...",
      ipa_path: "./app.ipa"
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.run(params) ⇒ Object



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
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
55
56
57
58
# File 'lib/fastlane/actions/crashlytics.rb', line 4

def self.run(params)
  params[:groups] = params[:groups].join(",") if params[:groups].kind_of?(Array)
  params[:emails] = params[:emails].join(",") if params[:emails].kind_of?(Array)

  params.values # to validate all inputs before looking for the ipa/apk

  # We need to store notes in a file, because the crashlytics CLI (iOS) says so
  if params[:notes]
    UI.error("Overwriting :notes_path, because you specified :notes") if params[:notes_path]

    params[:notes_path] = Helper::CrashlyticsHelper.write_to_tempfile(params[:notes], 'changelog').path
  elsif Actions.lane_context[SharedValues::FL_CHANGELOG] && !params[:notes_path]
    UI.message("Sending FL_CHANGELOG as release notes to Beta by Crashlytics")

    params[:notes_path] = Helper::CrashlyticsHelper.write_to_tempfile(
      Actions.lane_context[SharedValues::FL_CHANGELOG], 'changelog'
    ).path
  end

  if params[:ipa_path]
    command = Helper::CrashlyticsHelper.generate_ios_command(params)
  elsif params[:apk_path]
    command = Helper::CrashlyticsHelper.generate_android_command(params)
  else
    UI.user_error!("You have to either pass an ipa or an apk file to the Crashlytics action")
  end

  UI.success('Uploading the build to Crashlytics Beta. Time for some ☕️.')

  sanitizer = proc do |message|
    message.gsub(params[:api_token], '[[API_TOKEN]]')
           .gsub(params[:build_secret], '[[BUILD_SECRET]]')
  end

  UI.verbose sanitizer.call(command.join(' ')) if $verbose

  error_callback = proc do |error|
    clean_error = sanitizer.call(error)
    UI.error(clean_error)
  end

  result = Actions.sh_control_output(
    command.join(" "),
    print_command: false,
    print_command_output: false,
    error_callback: error_callback
  )

  return command if Helper.test?

  UI.verbose sanitizer.call(result) if $verbose

  UI.success('Build successfully uploaded to Crashlytics Beta 🌷')
  UI.success('Visit https://fabric.io/_/beta to add release notes and notify testers.')
end