Class: Fastlane::Actions::UploadSymbolsToCrashlyticsAction

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

Class Method Details

.authorsObject



240
241
242
# File 'fastlane/lib/fastlane/actions/upload_symbols_to_crashlytics.rb', line 240

def self.authors
  ["KrauseFx"]
end

.available_optionsObject



145
146
147
148
149
150
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
# File 'fastlane/lib/fastlane/actions/upload_symbols_to_crashlytics.rb', line 145

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :dsym_path,
                                 env_name: "FL_UPLOAD_SYMBOLS_TO_CRASHLYTICS_DSYM_PATH",
                                 description: "Path to the DSYM file or zip to upload",
                                 default_value: ENV[SharedValues::DSYM_OUTPUT_PATH.to_s] || (Dir["./**/*.dSYM"] + Dir["./**/*.dSYM.zip"]).sort_by { |f| File.mtime(f) }.last,
                                 default_value_dynamic: true,
                                 optional: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("Couldn't find file at path '#{File.expand_path(value)}'") unless File.exist?(value)
                                   UI.user_error!("Symbolication file needs to be dSYM or zip") unless value.end_with?(".zip", ".dSYM")
                                 end),
    FastlaneCore::ConfigItem.new(key: :dsym_paths,
                                 env_name: "FL_UPLOAD_SYMBOLS_TO_CRASHLYTICS_DSYM_PATHS",
                                 description: "Paths to the DSYM files or zips to upload",
                                 optional: true,
                                 type: Array,
                                 verify_block: proc do |values|
                                   values.each do |value|
                                     UI.user_error!("Couldn't find file at path '#{File.expand_path(value)}'") unless File.exist?(value)
                                     UI.user_error!("Symbolication file needs to be dSYM or zip") unless value.end_with?(".zip", ".dSYM")
                                   end
                                 end),
    FastlaneCore::ConfigItem.new(key: :api_token,
                                 env_name: "CRASHLYTICS_API_TOKEN",
                                 sensitive: true,
                                 optional: true,
                                 description: "Crashlytics API Key",
                                 verify_block: proc do |value|
                                   UI.user_error!("No API token for Crashlytics given, pass using `api_token: 'token'`") if value.to_s.length == 0
                                 end),
    FastlaneCore::ConfigItem.new(key: :gsp_path,
                                 env_name: "GOOGLE_SERVICES_INFO_PLIST_PATH",
                                 code_gen_sensitive: true,
                                 optional: true,
                                 description: "Path to GoogleService-Info.plist",
                                 verify_block: proc do |value|
                                   UI.user_error!("Couldn't find file at path '#{File.expand_path(value)}'") unless File.exist?(value)
                                   UI.user_error!("No Path to GoogleService-Info.plist for Firebase Crashlytics given, pass using `gsp_path: 'path'`") if value.to_s.length == 0
                                 end),
    FastlaneCore::ConfigItem.new(key: :app_id,
                                 env_name: "CRASHLYTICS_APP_ID",
                                 sensitive: true,
                                 optional: true,
                                 description: "Firebase Crashlytics APP ID",
                                 verify_block: proc do |value|
                                   UI.user_error!("No App ID for Firebase Crashlytics given, pass using `app_id: 'appId'`") if value.to_s.length == 0
                                 end),
    FastlaneCore::ConfigItem.new(key: :binary_path,
                                 env_name: "FL_UPLOAD_SYMBOLS_TO_CRASHLYTICS_BINARY_PATH",
                                 description: "The path to the upload-symbols file of the Fabric app",
                                 optional: true,
                                 verify_block: proc do |value|
                                   value = File.expand_path(value)
                                   UI.user_error!("Couldn't find file at path '#{value}'") unless File.exist?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :platform,
                                 env_name: "FL_UPLOAD_SYMBOLS_TO_CRASHLYTICS_PLATFORM",
                                 description: "The platform of the app (ios, appletvos, mac)",
                                 default_value: "ios",
                                 verify_block: proc do |value|
                                   available = ['ios', 'appletvos', 'mac']
                                   UI.user_error!("Invalid platform '#{value}', must be #{available.join(', ')}") unless available.include?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :dsym_worker_threads,
                                 env_name: "FL_UPLOAD_SYMBOLS_TO_CRASHLYTICS_DSYM_WORKER_THREADS",
                                 type: Integer,
                                 default_value: 1,
                                 optional: true,
                                 description: "The number of threads to use for simultaneous dSYM upload",
                                 verify_block: proc do |value|
                                   min_threads = 1
                                   UI.user_error!("Too few threads (#{value}) minimum number of threads: #{min_threads}") unless value >= min_threads
                                 end),
    FastlaneCore::ConfigItem.new(key: :fail_on_error,
                                 env_name: "FL_UPLOAD_SYMBOLS_TO_CRASHLYTICS_FAIL_ON_ERROR",
                                 description: "Should the action fail when an upload fails?",
                                 type: Boolean,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :debug,
                                 env_name: "FL_UPLOAD_SYMBOLS_TO_CRASHLYTICS_DEBUG",
                                 description: "Enable debug mode for upload-symbols",
                                 type: Boolean,
                                 default_value: false)
  ]
end

.categoryObject



254
255
256
# File 'fastlane/lib/fastlane/actions/upload_symbols_to_crashlytics.rb', line 254

def self.category
  :misc
end

.descriptionObject



134
135
136
# File 'fastlane/lib/fastlane/actions/upload_symbols_to_crashlytics.rb', line 134

def self.description
  "Upload dSYM symbolication files to Crashlytics"
end

.detailsObject



138
139
140
141
142
143
# File 'fastlane/lib/fastlane/actions/upload_symbols_to_crashlytics.rb', line 138

def self.details
  [
    "This action allows you to upload symbolication files to Crashlytics. It's extra useful if you use it to download the latest dSYM files from Apple when you use Bitcode. This action will not fail the build if one of the uploads failed by default.",
    "The reason for that is that sometimes some of dSYM files are invalid, and we don't want them to fail the complete build. However, fail_on_build parameter can be used to prevent this behavior."
  ].join("\n")
end

.example_codeObject



248
249
250
251
252
# File 'fastlane/lib/fastlane/actions/upload_symbols_to_crashlytics.rb', line 248

def self.example_code
  [
    'upload_symbols_to_crashlytics(dsym_path: "./App.dSYM.zip")'
  ]
end

.find_api_token(params) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
# File 'fastlane/lib/fastlane/actions/upload_symbols_to_crashlytics.rb', line 99

def self.find_api_token(params)
  return if params[:gsp_path]
  unless params[:api_token].to_s.length > 0
    Dir["./**/Info.plist"].each do |current|
      result = Actions::GetInfoPlistValueAction.run(path: current, key: "Fabric")
      next unless result
      next unless result.kind_of?(Hash)
      params[:api_token] ||= result["APIKey"]
      UI.verbose("found an APIKey in #{current}")
    end
  end
end

.find_binary_path(params) ⇒ Object



123
124
125
126
127
128
# File 'fastlane/lib/fastlane/actions/upload_symbols_to_crashlytics.rb', line 123

def self.find_binary_path(params)
  params[:binary_path] ||= (Dir["/Applications/Fabric.app/**/upload-symbols"] + Dir["./Pods/Fabric/upload-symbols"] + Dir["./scripts/upload-symbols"] + Dir["./Pods/FirebaseCrashlytics/upload-symbols"]).last
  UI.user_error!("Failed to find Fabric's upload_symbols binary at /Applications/Fabric.app/**/upload-symbols or ./Pods/**/upload-symbols. Please specify the location of the binary explicitly by using the binary_path option") unless params[:binary_path]

  params[:binary_path] = File.expand_path(params[:binary_path])
end

.find_gsp_path(params) ⇒ Object



112
113
114
115
116
117
118
119
120
121
# File 'fastlane/lib/fastlane/actions/upload_symbols_to_crashlytics.rb', line 112

def self.find_gsp_path(params)
  return if params[:api_token] && params[:gsp_path].nil?

  if params[:gsp_path].to_s.length > 0
    params[:gsp_path] = File.expand_path(params[:gsp_path])
  else
    gsp_path = Dir["./**/GoogleService-Info.plist"].first
    params[:gsp_path] = File.expand_path(gsp_path) unless gsp_path.nil?
  end
end

.handle_dsym(params, current_path) ⇒ Object

Parameters:

  • current_path

    this is a path to either a dSYM or a zipped dSYM this might also be either nested or not, we're flexible



56
57
58
59
60
61
62
63
# File 'fastlane/lib/fastlane/actions/upload_symbols_to_crashlytics.rb', line 56

def self.handle_dsym(params, current_path)
  if current_path.end_with?(".dSYM", ".zip")
    return upload_dsym(params, current_path)
  else
    UI.error("Don't know how to handle '#{current_path}'")
    return false
  end
end

.is_supported?(platform) ⇒ Boolean

Returns:



244
245
246
# File 'fastlane/lib/fastlane/actions/upload_symbols_to_crashlytics.rb', line 244

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

.outputObject



232
233
234
# File 'fastlane/lib/fastlane/actions/upload_symbols_to_crashlytics.rb', line 232

def self.output
  nil
end

.return_valueObject



236
237
238
# File 'fastlane/lib/fastlane/actions/upload_symbols_to_crashlytics.rb', line 236

def self.return_value
  nil
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
# File 'fastlane/lib/fastlane/actions/upload_symbols_to_crashlytics.rb', line 4

def self.run(params)
  require 'tmpdir'

  find_binary_path(params)
  unless params[:app_id]
    find_gsp_path(params)
    find_api_token(params)
  end

  if !params[:app_id] && !params[:gsp_path] && !params[:api_token]
    UI.user_error!('Either Firebase Crashlytics App ID, path to GoogleService-Info.plist or legacy Fabric API key must be given.')
  end

  dsym_paths = []
  dsym_paths << params[:dsym_path] if params[:dsym_path]
  dsym_paths += Actions.lane_context[SharedValues::DSYM_PATHS] if Actions.lane_context[SharedValues::DSYM_PATHS]

  # Allows adding of additional multiple dsym_paths since :dsym_path can be autoset by other actions
  dsym_paths += params[:dsym_paths] if params[:dsym_paths]

  if dsym_paths.count == 0
    UI.error("Couldn't find any dSYMs, please pass them using the dsym_path option")
    return nil
  end

  # Get rid of duplicates (which might occur when both passed and detected)
  dsym_paths = dsym_paths.collect { |a| File.expand_path(a) }
  dsym_paths.uniq!

  max_worker_threads = params[:dsym_worker_threads]
  if max_worker_threads > 1
    UI.message("Using #{max_worker_threads} threads for Crashlytics dSYM upload 🏎")
  end

  worker = FastlaneCore::QueueWorker.new(max_worker_threads) do |dsym_path|
    handle_dsym(params, dsym_path)
  end
  worker.batch_enqueue(dsym_paths)
  results = worker.start

  if results.all?
    UI.success("Successfully uploaded dSYM files to Crashlytics 💯")
  elsif results.any?
    UI.success("Successfully uploaded some dSYM files to Crashlytics 💯")
    UI.important("Some dSYM files failed to upload, see the errors above")
  else
    UI.user_error!("Service failed to upload any dSYM files to Crashlytics")
  end
end

.upload_dsym(params, path) ⇒ Object



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

def self.upload_dsym(params, path)
  UI.message("Uploading '#{path}'...")
  command = []
  command << File.expand_path(params[:binary_path]).shellescape
  if params[:debug]
    command << "-d"
  end
  if params[:app_id]
    command << "-ai #{params[:app_id].shellescape}"
  elsif params[:gsp_path]
    command << "-gsp #{params[:gsp_path].shellescape}"
  elsif params[:api_token]
    command << "-a #{params[:api_token]}"
  end
  command << "-p #{params[:platform] == 'appletvos' ? 'tvos' : params[:platform]}"
  command << File.expand_path(path).shellescape

  begin
    command_to_execute = command.join(" ")
    UI.verbose("upload_dsym using command: #{command_to_execute}")
    Actions.sh(command_to_execute, log: params[:debug])
    return true
  rescue => ex
    # If it fails - emit the warning, then continue (or crash) depending on "fail_on_error"
    UI.error(ex.to_s)

    if params[:fail_on_error] == true
      raise
    end

    return false
  end
end