Class: Fastlane::Actions::UploadSymbolsToSentryAction

Inherits:
Fastlane::Action show all
Defined in:
fastlane/lib/fastlane/actions/upload_symbols_to_sentry.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, lane_context, method_missing, other_action, output, return_type, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorsObject


133
134
135
# File 'fastlane/lib/fastlane/actions/upload_symbols_to_sentry.rb', line 133

def self.authors
  ["joshdholtz"]
end

.available_optionsObject


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

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :api_host,
                                 env_name: "SENTRY_HOST",
                                 description: "API host url for Sentry",
                                 is_string: true,
                                 default_value: "https://app.getsentry.com/api/0",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :api_key,
                                 env_name: "SENTRY_API_KEY",
                                 description: "API key for Sentry",
                                 sensitive: true,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :auth_token,
                                 env_name: "SENTRY_AUTH_TOKEN",
                                 description: "Authentication token for Sentry",
                                 sensitive: true,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :org_slug,
                                 env_name: "SENTRY_ORG_SLUG",
                                 description: "Organization slug for Sentry project",
                                 verify_block: proc do |value|
                                   UI.user_error!("No organization slug for SentryAction given, pass using `org_slug: 'org'`") unless value && !value.empty?
                                 end),
    FastlaneCore::ConfigItem.new(key: :project_slug,
                                 env_name: "SENTRY_PROJECT_SLUG",
                                 description: "Project slug for Sentry",
                                 verify_block: proc do |value|
                                   UI.user_error!("No project slug for SentryAction given, pass using `project_slug: 'project'`") unless value && !value.empty?
                                 end),
    FastlaneCore::ConfigItem.new(key: :dsym_path,
                                 env_name: "SENTRY_DSYM_PATH",
                                 description: "Path to your symbols file. For iOS and Mac provide path to app.dSYM.zip",
                                 default_value: Actions.lane_context[SharedValues::DSYM_OUTPUT_PATH],
                                 default_value_dynamic: true,
                                 optional: true,
                                 verify_block: proc do |value|
                                   # validation is done in the action
                                 end),
    FastlaneCore::ConfigItem.new(key: :dsym_paths,
                                 env_name: "SENTRY_DSYM_PATHS",
                                 description: "Path to an array of your symbols file. For iOS and Mac provide path to app.dSYM.zip",
                                 default_value: Actions.lane_context[SharedValues::DSYM_PATHS],
                                 default_value_dynamic: true,
                                 is_string: false,
                                 optional: true,
                                 verify_block: proc do |value|
                                   # validation is done in the action
                                 end)
  ]
end

.categoryObject


152
153
154
# File 'fastlane/lib/fastlane/actions/upload_symbols_to_sentry.rb', line 152

def self.category
  :deprecated
end

.deprecated_notesObject


156
157
158
159
160
161
162
# File 'fastlane/lib/fastlane/actions/upload_symbols_to_sentry.rb', line 156

def self.deprecated_notes
  [
    "Please use the `sentry` plugin instead.",
    "Install using `fastlane add_plugin sentry`.",
    "Replace `upload_symbols_to_sentry(...)` with `sentry_upload_dsym(...)`."
  ].join("\n")
end

.descriptionObject


69
70
71
# File 'fastlane/lib/fastlane/actions/upload_symbols_to_sentry.rb', line 69

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

.detailsObject


73
74
75
# File 'fastlane/lib/fastlane/actions/upload_symbols_to_sentry.rb', line 73

def self.details
  "This action allows you to upload symbolication files to Sentry. It's extra useful if you use it to download the latest dSYM files from Apple when you use Bitcode."
end

.example_codeObject


141
142
143
144
145
146
147
148
149
150
# File 'fastlane/lib/fastlane/actions/upload_symbols_to_sentry.rb', line 141

def self.example_code
  [
    'upload_symbols_to_sentry(
      auth_token: "...",
      org_slug: "...",
      project_slug: "...",
      dsym_path: "./App.dSYM.zip"
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:


137
138
139
# File 'fastlane/lib/fastlane/actions/upload_symbols_to_sentry.rb', line 137

def self.is_supported?(platform)
  platform == :ios
end

.return_valueObject


129
130
131
# File 'fastlane/lib/fastlane/actions/upload_symbols_to_sentry.rb', line 129

def self.return_value
  "The uploaded dSYM path(s)"
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
# File 'fastlane/lib/fastlane/actions/upload_symbols_to_sentry.rb', line 4

def self.run(params)
  # Warning about usinging new plugin
  UI.important("It's recommended to use the official Sentry Fastlane plugin")
  UI.important("GitHub: https://github.com/getsentry/fastlane-plugin-sentry")
  UI.important("Installation: fastlane add_plugin sentry")

  Actions.verify_gem!('rest-client')
  require 'rest-client'

  # Params - API
  host = params[:api_host]
  api_key = params[:api_key]
  auth_token = params[:auth_token]
  org = params[:org_slug]
  project = params[:project_slug]

  # Params - dSYM
  dsym_path = params[:dsym_path]
  dsym_paths = params[:dsym_paths] || []

  has_api_key = !api_key.to_s.empty?
  has_auth_token = !auth_token.to_s.empty?

  # Will fail if none or both authentication methods are provided
  if !has_api_key && !has_auth_token
    UI.user_error!("No API key or authentication token found for SentryAction given, pass using `api_key: 'key'` or `auth_token: 'token'`")
  elsif has_api_key && has_auth_token
    UI.user_error!("Both API key and authentication token found for SentryAction given, please only give one")
  end

  # Url to post dSYMs to
  url = "#{host}/projects/#{org}/#{project}/files/dsyms/"

  if has_api_key
    resource = RestClient::Resource.new(url, api_key, '')
  else
    resource = RestClient::Resource.new(url, headers: { Authorization: "Bearer #{auth_token}" })
  end

  UI.message("Will upload dSYM(s) to #{url}")

  # Upload dsym(s)
  dsym_paths += [dsym_path]
  uploaded_paths = dsym_paths.compact.map do |dsym|
    upload_dsym(resource, dsym)
  end

  # Return uplaoded dSYM paths
  uploaded_paths
end

.upload_dsym(resource, dsym) ⇒ Object


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

def self.upload_dsym(resource, dsym)
  UI.message("Uploading... #{dsym}")
  resource.post(file: File.new(dsym, 'rb')) unless Helper.test?
  UI.success('dSYM successfully uploaded to Sentry!')

  dsym
rescue
  UI.user_error!('Error while trying to upload dSYM to Sentry')
end