Class: Fastlane::Actions::UploadSymbolsToBugsnagAction

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

Constant Summary collapse

UPLOAD_SCRIPT_PATH =
File.expand_path(
File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'bugsnag-dsym-upload'))

Class Method Summary collapse

Class Method Details

.authorsObject


46
47
48
# File 'lib/fastlane/plugin/bugsnag/actions/upload_symbols_to_bugsnag.rb', line 46

def self.authors
  ["kattrali", "xander-jones"]
end

.available_optionsObject


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
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/fastlane/plugin/bugsnag/actions/upload_symbols_to_bugsnag.rb', line 62

def self.available_options
  validate_dsym_path = proc do |value|
    value.each do |path|
      unless File.exist?(path)
        UI.user_error!("Could not find file at path '#{File.expand_path(path)}'")
      end
      unless File.directory?(path) or path.end_with?(".zip", ".dSYM")
        UI.user_error!("Symbolication file needs to be a directory containing dSYMs, a .dSYM file or a .zip file, got #{File.expand_path(path)}")
      end
    end
  end
  validate_symbol_maps = proc do |path|
    return if path.nil?
    unless File.exist?(path) and File.directory?(path)
      UI.user_error!("Symbol maps file needs to be a directory containing symbol map files")
    end
  end
  validate_api_key = proc do |key|
    return if key.nil?
    unless !key[/\H/] and key.length == 32
      UI.user_error!("API key should be a 32 character hexadecimal string")
    end
  end

  # If the Info.plist is in a default location, we'll get API key here
  # This will be overwritten if you pass in an API key parameter in your
  # Fastfile, or have an API key environment variable set.
  [
    FastlaneCore::ConfigItem.new(key: :api_key,
                                 env_name: "BUGSNAG_API_KEY",
                                 description: "Bugsnag API Key",
                                 optional: true,
                                 verify_block: validate_api_key),
    FastlaneCore::ConfigItem.new(key: :dsym_path,
                                 type: Array,
                                 env_name: "BUGSNAG_DSYM_PATH",
                                 description: "Path to the dSYM directory, file, or zip to upload",
                                 default_value: default_dsym_paths,
                                 optional: true,
                                 verify_block: validate_dsym_path),
    FastlaneCore::ConfigItem.new(key: :upload_url,
                                 env_name: "BUGSNAG_UPLOAD_URL",
                                 description: "URL of the server receiving uploaded files",
                                 default_value: nil,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :symbol_maps_path,
                                 env_name: "BUGSNAG_SYMBOL_MAPS_PATH",
                                 description: "Path to the BCSymbolMaps directory to build complete dSYM files",
                                 default_value: nil,
                                 optional: true,
                                 verify_block: validate_symbol_maps),
    FastlaneCore::ConfigItem.new(key: :project_root,
                                 env_name: "BUGSNAG_PROJECT_ROOT",
                                 description: "Root path of the project",
                                 default_value: Dir::pwd,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :ignore_missing_dwarf,
                                 env_name: "BUGSNAG_IGNORE_MISSING_DWARF",
                                 description: "Throw warnings instead of errors when a dSYM with missing DWARF data is found",
                                 optional: true,
                                 default_value: false,
                                 is_string: false),
    FastlaneCore::ConfigItem.new(key: :ignore_empty_dsym,
                                 env_name: "BUGSNAG_IGNORE_EMPTY_DSYM",
                                 description: "Throw warnings instead of errors when a *.dSYM file is found rather than the expected *.dSYM directory",
                                 optional: true,
                                 default_value: false,
                                 is_string: false),
    FastlaneCore::ConfigItem.new(key: :config_file,
                                 env_name: "BUGSNAG_CONFIG_FILE",
                                 description: "Info.plist location",
                                 optional: true,
                                 default_value: default_info_plist_path)
  ]
end

.descriptionObject


42
43
44
# File 'lib/fastlane/plugin/bugsnag/actions/upload_symbols_to_bugsnag.rb', line 42

def self.description
  "Uploads dSYM debug symbol files to Bugsnag"
end

.detailsObject


54
55
56
# File 'lib/fastlane/plugin/bugsnag/actions/upload_symbols_to_bugsnag.rb', line 54

def self.details
  "Takes debug symbol (dSYM) files from a macOS, iOS, or tvOS project and uploads them to Bugsnag to improve stacktrace quality"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)

58
59
60
# File 'lib/fastlane/plugin/bugsnag/actions/upload_symbols_to_bugsnag.rb', line 58

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

.return_valueObject


50
51
52
# File 'lib/fastlane/plugin/bugsnag/actions/upload_symbols_to_bugsnag.rb', line 50

def self.return_value
  nil
end

.run(params) ⇒ Object


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

def self.run(params)
  # If we have not explicitly set an API key through env, or parameter
  # input in Fastfile, find an API key in the Info.plist in config_file param
  api_key = params[:api_key]
  if params[:config_file] && params[:api_key] == nil
    UI.message("Using the API Key from #{params[:config_file]}")
    api_key = options_from_info_plist(params[:config_file])[:apiKey]
  end

  # If verbose flag is enabled (`--verbose`), display the plugin action debug info
  # Store the verbose flag for use in the upload arguments.
  verbose = UI.verbose("Uploading dSYMs to Bugsnag with the following parameters:")
  rjust = 30 # set justification width for keys for the list of parameters to output
  params.values.each do |param|
    UI.verbose("  #{param[0].to_s.rjust(rjust)}: #{param[1]}")
  end
  UI.verbose("  #{"SharedValues::DSYM_PATHS".to_s.rjust(rjust)}: #{gym_dsyms? ? Actions.lane_context[SharedValues::DSYM_PATHS] : "not set"}")
  UI.verbose("  #{"SharedValues::DSYM_OUTPUT_PATH".to_s.rjust(rjust)}: #{download_dsym_dsyms? ? Actions.lane_context[SharedValues::DSYM_OUTPUT_PATH] : "not set"}")

  parse_dsym_paths(params[:dsym_path]).each do |dsym_path|
    if dsym_path.end_with?(".zip") or File.directory?(dsym_path)
      args = upload_args(dsym_path, params[:symbol_maps_path], params[:upload_url], params[:project_root], api_key, verbose, params[:ignore_missing_dwarf], params[:ignore_empty_dsym])
      success = Kernel.system(UPLOAD_SCRIPT_PATH, *args)
      if success
        UI.success("Uploaded dSYMs in #{dsym_path}")
      else
        UI.user_error!("Failed uploading #{dsym_path}")
      end
    else
      UI.user_error!("The specified symbol file path cannot be used: #{dsym_path}")
    end
  end
end