Class: Fastlane::Actions::DownloadDsymsAction

Inherits:
Fastlane::Action show all
Defined in:
fastlane/lib/fastlane/actions/download_dsyms.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



245
246
247
# File 'fastlane/lib/fastlane/actions/download_dsyms.rb', line 245

def self.authors
  ["KrauseFx"]
end

.available_optionsObject



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

def self.available_options
  user = CredentialsManager::AppfileConfig.try_fetch_value(:itunes_connect_id)
  user ||= CredentialsManager::AppfileConfig.try_fetch_value(:apple_id)

  [
    FastlaneCore::ConfigItem.new(key: :username,
                                 short_option: "-u",
                                 env_name: "DOWNLOAD_DSYMS_USERNAME",
                                 description: "Your Apple ID Username for App Store Connect",
                                 default_value: user,
                                 default_value_dynamic: true),
    FastlaneCore::ConfigItem.new(key: :app_identifier,
                                 short_option: "-a",
                                 env_name: "DOWNLOAD_DSYMS_APP_IDENTIFIER",
                                 description: "The bundle identifier of your app",
                                 optional: false,
                                 code_gen_sensitive: true,
                                 default_value: CredentialsManager::AppfileConfig.try_fetch_value(:app_identifier),
                                 default_value_dynamic: true),
    FastlaneCore::ConfigItem.new(key: :team_id,
                                 short_option: "-k",
                                 env_name: "DOWNLOAD_DSYMS_TEAM_ID",
                                 description: "The ID of your App Store Connect team if you're in multiple teams",
                                 optional: true,
                                 is_string: false, # as we also allow integers, which we convert to strings anyway
                                 code_gen_sensitive: true,
                                 default_value: CredentialsManager::AppfileConfig.try_fetch_value(:itc_team_id),
                                 default_value_dynamic: true,
                                 verify_block: proc do |value|
                                   ENV["FASTLANE_ITC_TEAM_ID"] = value.to_s
                                 end),
    FastlaneCore::ConfigItem.new(key: :team_name,
                                 short_option: "-e",
                                 env_name: "DOWNLOAD_DSYMS_TEAM_NAME",
                                 description: "The name of your App Store Connect team if you're in multiple teams",
                                 optional: true,
                                 code_gen_sensitive: true,
                                 default_value: CredentialsManager::AppfileConfig.try_fetch_value(:itc_team_name),
                                 default_value_dynamic: true,
                                 verify_block: proc do |value|
                                   ENV["FASTLANE_ITC_TEAM_NAME"] = value.to_s
                                 end),
    FastlaneCore::ConfigItem.new(key: :platform,
                                 short_option: "-p",
                                 env_name: "DOWNLOAD_DSYMS_PLATFORM",
                                 description: "The app platform for dSYMs you wish to download (ios, appletvos)",
                                 optional: true,
                                 default_value: :ios),
    FastlaneCore::ConfigItem.new(key: :version,
                                 short_option: "-v",
                                 env_name: "DOWNLOAD_DSYMS_VERSION",
                                 description: "The app version for dSYMs you wish to download, pass in 'latest' to download only the latest build's dSYMs",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :build_number,
                                 short_option: "-b",
                                 env_name: "DOWNLOAD_DSYMS_BUILD_NUMBER",
                                 description: "The app build_number for dSYMs you wish to download",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :min_version,
                                 short_option: "-m",
                                 env_name: "DOWNLOAD_DSYMS_MIN_VERSION",
                                 description: "The minimum app version for dSYMs you wish to download",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :output_directory,
                                 short_option: "-s",
                                 env_name: "DOWNLOAD_DSYMS_OUTPUT_DIRECTORY",
                                 description: "Where to save the download dSYMs, defaults to the current path",
                                 optional: true)
  ]
end

.categoryObject



261
262
263
# File 'fastlane/lib/fastlane/actions/download_dsyms.rb', line 261

def self.category
  :app_store_connect
end

.descriptionObject



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

def self.description
  "Download dSYM files from App Store Connect for Bitcode apps"
end

.detailsObject



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'fastlane/lib/fastlane/actions/download_dsyms.rb', line 147

def self.details
  sample = <<-SAMPLE.markdown_sample
    ```ruby
    lane :refresh_dsyms do
      download_dsyms                  # Download dSYM files from iTC
      upload_symbols_to_crashlytics   # Upload them to Crashlytics
      clean_build_artifacts           # Delete the local dSYM files
    end
    ```
  SAMPLE

  [
    "This action downloads dSYM files from App Store Connect after the ipa gets re-compiled by Apple. Useful if you have Bitcode enabled.".markdown_preserve_newlines,
    sample
  ].join("\n")
end

.download(download_url, bundle_id, train_number, build_version, output_directory) ⇒ Object

rubocop:enable Metrics/PerceivedComplexity



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

def self.download(download_url, bundle_id, train_number, build_version, output_directory)
  result = self.download_file(download_url)
  path   = write_dsym(result, bundle_id, train_number, build_version, output_directory)
  UI.success("🔑  Successfully downloaded dSYM file for #{train_number} - #{build_version} to '#{path}'")

  Actions.lane_context[SharedValues::DSYM_PATHS] ||= []
  Actions.lane_context[SharedValues::DSYM_PATHS] << File.expand_path(path)
end

.download_file(url) ⇒ Object



131
132
133
134
135
136
137
# File 'fastlane/lib/fastlane/actions/download_dsyms.rb', line 131

def self.download_file(url)
  uri = URI.parse(url)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = (uri.scheme == "https")
  res = http.get(uri.request_uri)
  res.body
end

.example_codeObject



253
254
255
256
257
258
259
# File 'fastlane/lib/fastlane/actions/download_dsyms.rb', line 253

def self.example_code
  [
    'download_dsyms',
    'download_dsyms(version: "1.0.0", build_number: "345")',
    'download_dsyms(min_version: "1.2.3")'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



249
250
251
# File 'fastlane/lib/fastlane/actions/download_dsyms.rb', line 249

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

.outputObject



235
236
237
238
239
# File 'fastlane/lib/fastlane/actions/download_dsyms.rb', line 235

def self.output
  [
    ['DSYM_PATHS', 'An array to all the zipped dSYM files']
  ]
end

.return_valueObject



241
242
243
# File 'fastlane/lib/fastlane/actions/download_dsyms.rb', line 241

def self.return_value
  nil
end

.run(params) ⇒ Object

rubocop:disable Metrics/PerceivedComplexity



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

def self.run(params)
  require 'spaceship'
  require 'net/http'

  UI.message("Login to App Store Connect (#{params[:username]})")
  Spaceship::Tunes.(params[:username])
  Spaceship::Tunes.select_team
  UI.message("Login successful")

  # Get App
  app = Spaceship::Application.find(params[:app_identifier])
  unless app
    UI.user_error!("Could not find app with bundle identifier '#{params[:app_identifier]}' on account #{params[:username]}")
  end

  # Process options
  version = params[:version]
  build_number = params[:build_number]
  platform = params[:platform]
  output_directory = params[:output_directory]
  min_version = Gem::Version.new(params[:min_version]) if params[:min_version]

  # Set version if it is latest
  if version == 'latest'
    # Try to grab the edit version first, else fallback to live version
    UI.message("Looking for latest version...")
    latest_version = app.edit_version(platform: platform) || app.live_version(platform: platform)

    UI.user_error!("Could not find latest version for your app, please try setting a specific version") if latest_version.version.nil?

    latest_candidate_build = latest_version.candidate_builds.max_by(&:upload_date)
    if latest_candidate_build.nil?
      version = latest_version.version
      build_number = latest_version.build_version
    else
      # The build_version of a candidate build does not always match the one in latest_version so get the version and build number from the same place.
      version = latest_candidate_build.train_version
      build_number = latest_candidate_build.build_version
    end
  end

  # Make sure output_directory has a slash on the end
  if output_directory && !output_directory.end_with?('/')
    output_directory += '/'
  end

  # Write a nice message
  message = []
  message << "Looking for dSYM files for '#{params[:app_identifier]}' on platform #{platform}"
  message << "v#{version}" if version
  message << "(#{build_number})" if build_number
  UI.message(message.join(" "))

  app.tunes_all_build_trains(platform: platform).each do |train|
    message = []
    message << "Found train (version): #{train.version_string}"
    message << ", comparing to supplied version: #{version}" if version
    UI.verbose(message.join(" "))

    if version && version != train.version_string
      UI.verbose("Version #{version} doesn't match: #{train.version_string}")
      next
    end

    if min_version && min_version > Gem::Version.new(train.version_string)
      UI.verbose("Min version #{min_version} not reached: #{train.version_string}")
      next
    end

    app.tunes_all_builds_for_train(train: train.version_string, platform: platform).each do |build|
      message = []
      message << "Found build version: #{build.build_version}"
      message << ", comparing to supplied build_number: #{build_number}" if build_number
      UI.verbose(message.join(" "))

      if build_number && build.build_version != build_number
        UI.verbose("build_version: #{build.build_version} doesn't match: #{build_number}")
        next
      end

      begin
        UI.verbose("Build_version: #{build.build_version} matches #{build_number}, grabbing dsym_url") if build_number

        build_details = app.tunes_build_details(train: train.version_string, build_number: build.build_version, platform: platform)
        download_url = build_details.dsym_url
        UI.verbose("dsym_url: #{download_url}")
      rescue Spaceship::TunesClient::ITunesConnectError => ex
        UI.error("Error accessing dSYM file for build\n\n#{build}\n\nException: #{ex}")
      end

      if download_url
        self.download(download_url, app.bundle_id, train.version_string, build.build_version, output_directory)
        break if build_number
      else
        UI.message("No dSYM URL for #{build.build_version} (#{train.version_string})")
      end
    end
  end

  if (Actions.lane_context[SharedValues::DSYM_PATHS] || []).count == 0
    UI.error("No dSYM files found on App Store Connect - this usually happens when no recompiling has happened yet")
  end
end

.write_dsym(data, bundle_id, train_number, build_number, output_directory) ⇒ Object



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

def self.write_dsym(data, bundle_id, train_number, build_number, output_directory)
  file_name = "#{bundle_id}-#{train_number}-#{build_number}.dSYM.zip"
  if output_directory
    file_name = output_directory + file_name
  end
  File.binwrite(file_name, data)
  file_name
end