class Fastlane::Actions::UploadSymbolsToBugsnagAction

Constants

UPLOAD_SCRIPT_PATH

Public Class Methods

authors() click to toggle source
# File lib/fastlane/plugin/bugsnag/actions/upload_symbols_to_bugsnag.rb, line 43
def self.authors
  ["kattrali"]
end
available_options() click to toggle source
# File lib/fastlane/plugin/bugsnag/actions/upload_symbols_to_bugsnag.rb, line 59
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_path,
                                 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
description() click to toggle source
# File lib/fastlane/plugin/bugsnag/actions/upload_symbols_to_bugsnag.rb, line 39
def self.description
  "Uploads dSYM debug symbol files to Bugsnag"
end
details() click to toggle source
# File lib/fastlane/plugin/bugsnag/actions/upload_symbols_to_bugsnag.rb, line 51
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) click to toggle source
# File lib/fastlane/plugin/bugsnag/actions/upload_symbols_to_bugsnag.rb, line 55
def self.is_supported?(platform)
  [:ios, :mac, :tvos].include?(platform)
end
return_value() click to toggle source
# File lib/fastlane/plugin/bugsnag/actions/upload_symbols_to_bugsnag.rb, line 47
def self.return_value
  nil
end
run(params) click to toggle source
# 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:")
  params.values.each do |param|
    UI.verbose("  #{param[0].to_s.rjust(18)}: #{param[1]}")
  end

  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

Private Class Methods

default_dsym_path() click to toggle source
# File lib/fastlane/plugin/bugsnag/actions/upload_symbols_to_bugsnag.rb, line 177
def self.default_dsym_path
  path = Dir["./**/*.dSYM.zip"] + Dir["./**/*.dSYM"]
  dsym_paths = Actions.lane_context[SharedValues::DSYM_PATHS] if defined? SharedValues::DSYM_PATHS
  dsyms_output_path = Actions.lane_context[SharedValues::DSYM_OUTPUT_PATH] if defined? SharedValues::DSYM_OUTPUT_PATH
  default_value = dsyms_output_path || dsym_paths || path
  parse_dsym_paths(default_value)
end
default_info_plist_path() click to toggle source
# File lib/fastlane/plugin/bugsnag/actions/upload_symbols_to_bugsnag.rb, line 137
def self.default_info_plist_path
  # Find first 'Info.plist' in the current working directory
  # ignoring any in 'build', or 'test' folders
  return Dir.glob("./{ios/,}*/Info.plist").reject{|path| path =~ /build|test/i }.sort.first
end
options_from_info_plist(file_path) click to toggle source
# File lib/fastlane/plugin/bugsnag/actions/upload_symbols_to_bugsnag.rb, line 143
def self.options_from_info_plist file_path
  plist_getter = Fastlane::Actions::GetInfoPlistValueAction
  bugsnag_dict = plist_getter.run(path: file_path, key: "bugsnag")
  api_key = bugsnag_dict["apiKey"] unless bugsnag_dict.nil?
  # From v6.0.0 of bugsnag-cocoa, the API key is in 'bugsnag.apiKey',
  # use 'BugsnagAPIKey' as a fallback if it exists (<v6.x.x)
  if api_key.nil?
    api_key = plist_getter.run(path: file_path, key: "BugsnagAPIKey")
  end
  {
    apiKey: api_key,
    config_file: file_path,
  }
end
parse_dsym_paths(dsym_path) click to toggle source
# File lib/fastlane/plugin/bugsnag/actions/upload_symbols_to_bugsnag.rb, line 170
def self.parse_dsym_paths dsym_path
  dsym_paths = dsym_path.is_a?(Array) ? dsym_path : [dsym_path]
  dsym_paths.compact.map do |path|
    path.end_with?(".dSYM") ? File.dirname(path) : path
  end.uniq
end
upload_args(dir, symbol_maps_dir, upload_url, project_root, api_key, verbose, ignore_missing_dwarf, ignore_empty_dsym) click to toggle source
# File lib/fastlane/plugin/bugsnag/actions/upload_symbols_to_bugsnag.rb, line 158
def self.upload_args dir, symbol_maps_dir, upload_url, project_root, api_key, verbose, ignore_missing_dwarf, ignore_empty_dsym
  args = [verbose ? "--verbose" : "--silent"]
  args += ["--ignore-missing-dwarf"] if ignore_missing_dwarf
  args += ["--ignore-empty-dsym"] if ignore_empty_dsym
  args += ["--api-key", api_key] unless api_key.nil?
  args += ["--upload-server", upload_url] unless upload_url.nil?
  args += ["--symbol-maps", symbol_maps_dir] unless symbol_maps_dir.nil?
  args += ["--project-root", project_root] unless project_root.nil?
  args << dir
  args
end