Class: Fastlane::Actions::DynatraceProcessSymbolsAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/dynatrace/actions/dynatrace_action.rb

Class Method Summary collapse

Class Method Details

.authorsObject



245
246
247
# File 'lib/fastlane/plugin/dynatrace/actions/dynatrace_action.rb', line 245

def self.authors
  ["MANassar/@MohamedANassar", "cynicer"]
end

.available_optionsObject



134
135
136
137
138
139
140
141
142
143
144
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
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/fastlane/plugin/dynatrace/actions/dynatrace_action.rb', line 134

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :action,
                                 env_name: "FL_UPLOAD_TO_DYNATRACE_ACTION",
                                 description: "(iOS only) Action to be performed by DTXDssClient (\"upload\" or \"decode\")",
                                 default_value: "upload",
                                 is_string: true,
                                 verify_block: proc do |value|
                                    UI.user_error!("Action needs to either be \"upload\" or \"decode\"") unless (value and value == "upload" or value == "decode")
                                 end),

    FastlaneCore::ConfigItem.new(key: :username,
                                 env_name: "FL_UPLOAD_TO_DYNATRACE_DOWNLOAD_DSYMS_USERNAME",
                                 description: "(iOS only) The username/AppleID to use to download the dSYMs"),

    FastlaneCore::ConfigItem.new(key: :os,
                                 env_name: "FL_UPLOAD_TO_DYNATRACE_OS",
                                 description: "The type of the symbol files, either \"ios\", \"tvos\" or \"android\"",
                                 sensitive: false,
                                 optional: false,
                                 verify_block: proc do |value|
                                    UI.user_error!("Please specify the type of the symbol files. Possible values are \"ios\", \"tvos\" or \"android\".") unless (value and not value.empty? and (value == "ios" || value == "tvos" || value =="android"))
                                 end),

    FastlaneCore::ConfigItem.new(key: :apitoken,
                                 env_name: "FL_UPLOAD_TO_DYNATRACE_APITOKEN",
                                 description: "Dynatrace API token with mobile symbolication permissions",
                                 verify_block: proc do |value|
                                    UI.user_error!("No Dynatrade API token for specified, pass using `apitoken: 'token'`") unless (value and not value.empty?)
                                 end),

    FastlaneCore::ConfigItem.new(key: :appId,
                                 env_name: "FL_UPLOAD_TO_DYNATRACE_APP_ID",
                                 description: "The app ID you get from your Dynatrace environment",
                                 verify_block: proc do |value|
                                    UI.user_error!("Please provide the appID for your application. Pass using `appId: 'appId'`") unless (value and not value.empty?)
                                 end),

    FastlaneCore::ConfigItem.new(key: :bundleId,
                                 env_name: "FL_UPLOAD_TO_DYNATRACE_BUNDLE_ID",
                                 description: "The CFBundlebundleId (iOS) / package (Android) of the application",
                                 verify_block: proc do |value|
                                    UI.user_error!("Please provide the BundleID for your app. Pass using `bundleId: 'bundleId'`") unless (value and not value.empty?)
                                end),

    FastlaneCore::ConfigItem.new(key: :versionStr,
                                 env_name: "FL_UPLOAD_TO_DYNATRACE_VERSION_STRING",
                                 description: "The CFBundleShortVersionString (iOS) / versionName (Android)",
                                 verify_block: proc do |value|
                                    UI.user_error!("Please provide the CFBundleShortVersionString for your app. Pass using `versionStr: 'versionStr'`") unless (value and not value.empty?)
                                end),

    FastlaneCore::ConfigItem.new(key: :version,
                                 env_name: "FL_UPLOAD_TO_DYNATRACE_VERSION",
                                 description: "The CFBundleVersion (iOS) / versionCode (Android). Is also used for the dSYM download",
                                 verify_block: proc do |value|
                                    UI.user_error!("Please provide the version for your app. Pass using `version: 'version'`") unless (value and not value.empty?)
                                 end),

    FastlaneCore::ConfigItem.new(key: :symbolsfile,
                                 env_name: "FL_UPLOAD_TO_DYNATRACE_SYM_FILE_PATH",
                                 description: "Path to the dSYM or Android mapping file to be processed. Android only: If the file exceeds 10MiB and doesn't end with *.zip it's zipped before uploading. This can be disabled by setting `symbolsfileAutoZip` to false",
                                 verify_block: proc do |value|
                                    UI.user_error!("Please provide a value for the symbol files. Pass using `symbolsfile: 'symbolsfile'`") unless (value and not value.empty?)
                                 end),

    FastlaneCore::ConfigItem.new(key: :symbolsfileAutoZip,
                                 env_name: "FL_UPLOAD_TO_DYNATRACE_SYM_FILE_AUTO_ZIP",
                                 default_value: true,
                                 is_string: false,
                                 description: "(Android only) Automatically zip symbolsfile if it exceeds 10MiB and doesn't already end with *.zip"),

    FastlaneCore::ConfigItem.new(key: :server,
                                 env_name: "FL_UPLOAD_TO_DYNATRACE_SERVER_URL",
                                 description: "The API endpoint for the Dynatrace environment (e.g. https://environmentID.live.dynatrace.com or https://dynatrace-managed.com/e/environmentID)",
                                 verify_block: proc do |value|
                                    UI.user_error!("Please provide your environment API endpoint. Pass using `server: 'server'`") unless (value and not value.empty?)
                                 end),

    FastlaneCore::ConfigItem.new(key: :cleanBuildArtifacts,
                                 env_name: "FL_UPLOAD_TO_DYNATRACE_CLEAN_BUILD_ARTIFACTS",
                                 default_value: false,
                                 is_string: false,
                                 description: "Clean build artifacts after processing"),

    FastlaneCore::ConfigItem.new(key: :tempdir,
                                 env_name: "FL_UPLOAD_TO_DYNATRACE_TEMP_DIR",
                                 description: "(OPTIONAL) Custom temporary directory for the DTXDssClient. The plugin does not take care of cleaning this directory",
                                 optional: true),

    FastlaneCore::ConfigItem.new(key: :debugMode,
                                 env_name: "FL_UPLOAD_TO_DYNATRACE_DEBUG_MODE",
                                 description: "Enable debug logging",
                                 default_value: false,
                                 is_string: false,
                                 optional: true),

    FastlaneCore::ConfigItem.new(key: :customLLDBFrameworkPath,
                                 env_name: "FL_UPLOAD_TO_DYNATRACE_LLDB_PATH",
                                 description: "Custom path to the LLDB framework used as runtime dependency by DTXDssClient",
                                 optional: true),

    FastlaneCore::ConfigItem.new(key: :autoSymlinkLLDB,
                                 env_name: "FL_UPLOAD_TO_DYNATRACE_AUTO_LINK_LLDB",
                                 description: "Automatically find and create a symlink to the LLDB framework into the DTXDssClient's temporary folder",
                                 type: Boolean,
                                 default_value: true,
                                 optional: true)
  ]
end

.descriptionObject



126
127
128
# File 'lib/fastlane/plugin/dynatrace/actions/dynatrace_action.rb', line 126

def self.description
  "This action processes and uploads your symbol files to Dynatrace."
end

.detailsObject



130
131
132
# File 'lib/fastlane/plugin/dynatrace/actions/dynatrace_action.rb', line 130

def self.details
  "This action allows you to process and upload symbol files to Dynatrace. If you use Bitcode you can also use it to download the latest dSYM files from App Store Connect."
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


249
250
251
# File 'lib/fastlane/plugin/dynatrace/actions/dynatrace_action.rb', line 249

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

.run(params) ⇒ Object



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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/fastlane/plugin/dynatrace/actions/dynatrace_action.rb', line 14

def self.run(params)
  UI.message "Parameter API Token: #{params[:apitoken]}" if params[:debugMode] == true
  UI.message "OS: #{params[:os]}"
  UI.message "Version string: #{params[:versionStr]}"
  UI.message "Version: #{params[:version]}"
  UI.message "Server URL: #{params[:server]}"
  UI.message "Tempdir: #{params[:tempdir]}"
  UI.message "Symbols file path: #{params[:symbolsfile]}"

  UI.message "Checking AppFile for possible AppID"
  bundleId = CredentialsManager::AppfileConfig.try_fetch_value(:app_identifier)
  if bundleId
    UI.message "Using #{bundleId} from your AppFile"
  else
    bundleId = params[:bundleId]
    UI.message "BundleID: #{bundleId}"
  end

  if params[:os] == "android"
    symbols_path = Helper::DynatraceHelper.zip_if_required(params)
    response, request = Helper::DynatraceHelper.put_android_symbols(params, bundleId, symbols_path)

    # https://www.dynatrace.com/support/help/dynatrace-api/configuration-api/mobile-symbolication-api/put-files-app-version
    if response.code == '204'
      UI.success "API response: Success."
    else
      message = nil
      if response.class.body_permitted? and not response.body.nil?
        message = JSON.parse(response.body)["error"]["message"]
      end

      if message.nil?
        UI.user_error! "API response: #{response.code}. Please try again in a few minutes or contact Dynatrace support (https://support.dynatrace.com)." 
      else
        UI.user_error! "API response: #{message} (Response code: #{response.code})" 
      end
    end
    return
  end

  if params[:os] != "ios" && params[:os] != "tvos"
    UI.user_error! "Unsopported value os=#{params[:os]}"
  end

  # iOS/tvOS workflow
  unless OS.mac?
    UI.user_error! "A macOS machine is required to process iOS or tvOS symbols."
  end

  dtxDssClientPath = Helper::DynatraceHelper.get_dss_client(params)
  dtxDssClientDir = File.dirname(dtxDssClientPath)
  Helper::DynatraceSymlinkHelper.delete_existing_lldb_symlinks(dtxDssClientDir)

  customLLDBFrameworkPath = params[:customLLDBFrameworkPath]
  if customLLDBFrameworkPath.nil?
    UI.message "No custom LLDB framework path provided"
    if params[:autoSymlinkLLDB]
      UI.message "Automatic LLDB symlink creation enabled"
      Helper::DynatraceSymlinkHelper.auto_symlink_lldb(dtxDssClientDir)
    elsif
      UI.message "Automatic LLDB symlink creation disabled"
    end
  else
    if Helper::DynatraceSymlinkHelper.path_exists?(customLLDBFrameworkPath)
      UI.message "Custom LLDB framework path `#{customLLDBFrameworkPath}` exists."
      Helper::DynatraceSymlinkHelper.symlink_custom_lldb(customLLDBFrameworkPath, dtxDssClientDir)
    else
      UI.user_error! "Custom LLDB framework path `#{customLLDBFrameworkPath}` does not exist!"
    end
  end

  # start constructing the command that will trigger the DTXDssClient
  command = []
  command << "#{dtxDssClientPath}"
  command << "-#{params[:action]}"  #"-upload"
  command << "appid=\"#{params[:appId]}\""
  command << "apitoken=\"#{params[:apitoken]}\""
  command << "os=#{params[:os]}"
  command << "bundleId=\"#{bundleId}\""
  command << "versionStr=\"#{params[:versionStr]}\""
  command << "version=\"#{params[:version]}\""
  command << "symbolsfile=\"#{params[:symbolsfile]}\""
  command << "server=\"#{Helper::DynatraceHelper.without_trailing_slash(params[:server])}\""
  command << "DTXLogLevel=ALL -verbose" if params[:debugMode] == true
  command << "forced=1" # if the file already exists
  command << "tempdir=\"#{params[:tempdir]}\"" if params[:tempdir]

  # Create the full shell command to trigger the DTXDssClient
  shell_command = command.join(' ')

  UI.message "#{shell_command}" if params[:debugMode] == true

  Fastlane::Actions.sh("#{shell_command}", log: params[:debugMode] == true, error_callback: ->(result) {
    # ShAction doesn't return any reference to the return value -> parse it from the output
    result_groups = result.match /(?:ERROR: Execution failed, rc=)(-?\d*)(?:\sreason=)(.*)/
    if result_groups and result_groups.length() >= 2
      if result_groups[1] == "413" 
        UI.user_error!("DTXDssClient: #{result_groups[2]} See https://www.dynatrace.com/support/help/shortlink/mobile-symbolication#manage-the-uploaded-symbol-files for more information.")
      else
        UI.user_error!("DTXDssClient: #{result_groups[2]}")
      end
    else
      UI.user_error!("DTXDssClient finished with errors.")
    end
  })

  if params[:cleanBuildArtifacts]
    UI.message "Cleaning build artifacts"
    Fastlane::Actions::CleanBuildArtifactsAction.run(exclude_pattern: nil)
  end
end