Class: Fastlane::Actions::SendBuildToBugsnagAction

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

Constant Summary collapse

BUILD_TOOL =
"bugsnag-fastlane-plugin"

Class Method Summary collapse

Class Method Details

.authorsObject


99
100
101
# File 'lib/fastlane/plugin/bugsnag/actions/send_build_to_bugsnag.rb', line 99

def self.authors
  ["cawllec"]
end

.available_optionsObject


123
124
125
126
127
128
129
130
131
132
133
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
# File 'lib/fastlane/plugin/bugsnag/actions/send_build_to_bugsnag.rb', line 123

def self.available_options
  git_options = load_git_remote_options
  [
    FastlaneCore::ConfigItem.new(key: :config_file,
                                 description: "AndroidManifest.xml/Info.plist location",
                                 optional: true,
                                 default_value: default_config_file_path),
    FastlaneCore::ConfigItem.new(key: :api_key,
                                 description: "Bugsnag API Key",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :app_version,
                                 description: "App version being built",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :android_version_code,
                                 description: "Android app version code",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :ios_bundle_version,
                                 description: "iOS/macOS/tvOS bundle version",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :release_stage,
                                 description: "Release stage being built, i.e. staging, production",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :builder,
                                 description: "The name of the entity triggering the build",
                                 optional: true,
                                 default_value: `whoami`.chomp),
    FastlaneCore::ConfigItem.new(key: :repository,
                                 description: "The source control repository URL for this application",
                                 optional: true,
                                 default_value: git_options[:repository]),
    FastlaneCore::ConfigItem.new(key: :revision,
                                 description: "The source control revision id",
                                 optional: true,
                                 default_value: git_options[:revision]),
    FastlaneCore::ConfigItem.new(key: :provider,
                                 description: "The source control provider, one of 'github-enterprise', 'gitlab-onpremise', or 'bitbucket-server', if any",
                                 optional: true,
                                 default_value: nil,
                                 verify_block: proc do |value|
                                   valid = ['github', 'github-enterprise', 'gitlab', 'gitlab-onpremise', 'bitbucket', 'bitbucket-server'].include? value
                                   unless valid
                                     UI.user_error!("Provider must be one of 'github', 'github-enterprise', 'gitlab', 'gitlab-onpremise', 'bitbucket', 'bitbucket-server', or unspecified")
                                   end
                                 end),
    FastlaneCore::ConfigItem.new(key: :endpoint,
                                 description: "Bugsnag deployment endpoint",
                                 optional: true,
                                 default_value: "https://build.bugsnag.com")
  ]
end

.categoryObject


107
108
109
# File 'lib/fastlane/plugin/bugsnag/actions/send_build_to_bugsnag.rb', line 107

def self.category
  :building
end

.descriptionObject


95
96
97
# File 'lib/fastlane/plugin/bugsnag/actions/send_build_to_bugsnag.rb', line 95

def self.description
  "Notifies Bugsnag of a build"
end

.detailsObject


115
116
117
# File 'lib/fastlane/plugin/bugsnag/actions/send_build_to_bugsnag.rb', line 115

def self.details
  "Notifies Bugsnag of a new build being released including app version and source control details"
end

.example_codeObject


103
104
105
# File 'lib/fastlane/plugin/bugsnag/actions/send_build_to_bugsnag.rb', line 103

def self.example_code
  ['send_build_to_bugsnag']
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)

119
120
121
# File 'lib/fastlane/plugin/bugsnag/actions/send_build_to_bugsnag.rb', line 119

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

.missing_api_key_message(params) ⇒ Object


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/fastlane/plugin/bugsnag/actions/send_build_to_bugsnag.rb', line 59

def self.missing_api_key_message(params)
  message = "A Bugsnag API key is required to release a build. "
  if lane_context[:PLATFORM_NAME] == :android
    if params[:config_file]
      message << "Set com.bugsnag.android.API_KEY in your AndroidManifest.xml to detect API key automatically."
    else
      message << "Set the config_file option with the path to your AndroidManifest.xml and set com.bugsnag.android.API_KEY in it to detect API key automatically."
    end
  else
    if params[:config_file]
      message << "Set bugsnag.apiKey in your Info.plist file to detect API key automatically."
    else
      message << "Set the config_file option with the path to your Info.plist and set bugsnag.apiKey in it to detect API key automatically."
    end
  end
  message
end

.missing_app_version_message(params) ⇒ Object


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/fastlane/plugin/bugsnag/actions/send_build_to_bugsnag.rb', line 77

def self.missing_app_version_message(params)
  message = "An app version must be specified release a build. "
  if lane_context[:PLATFORM_NAME] == :android
    if params[:config_file]
      message << "Set com.bugsnag.android.APP_VERSION in your AndroidManifest.xml to detect this value automatically."
    else
      message << "Set the config_file option with the path to your AndroidManifest.xml and set com.bugsnag.android.APP_VERSION in it to detect this value automatically."
    end
  else
    if params[:config_file]
      message << "Set the app_version option with your app version or set config_file to update the path to your Info.plist"
    else
      message << "Set the config_file option with the path to your Info.plist"
    end
  end
  message
end

.return_valueObject


111
112
113
# File 'lib/fastlane/plugin/bugsnag/actions/send_build_to_bugsnag.rb', line 111

def self.return_value
  nil
end

.run(params) ⇒ Object


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

def self.run(params)
  payload = {buildTool: BUILD_TOOL, sourceControl: {}}

  # If a configuration file was found or was specified, load in the options:
  if params[:config_file]
    UI.message("Loading build information from #{params[:config_file]}")
    config_options = load_config_file_options(params[:config_file])

    # for each of the config options, if it's not been overriden by any
    # input to the lane, write it to the payload:
    payload[:apiKey] = params[:api_key] || config_options[:apiKey]
    payload[:appVersion] = params[:app_version] || config_options[:appVersion]
    payload[:appVersionCode] = params[:android_version_code] || config_options[:appVersionCode]
    payload[:appBundleVersion] = params[:ios_bundle_version] || config_options[:appBundleVersion]
    payload[:releaseStage] = params[:release_stage] || config_options[:releaseStage] || "production"
  else
    # No configuration file was found or specified, use the input parameters:
    payload[:apiKey] = params[:api_key]
    payload[:appVersion] = params[:app_version]
    payload[:appVersionCode] = params[:android_version_code]
    payload[:appBundleVersion] = params[:ios_bundle_version]
    payload[:releaseStage] = params[:release_stage] || "production"
  end

  # If builder, or source control information has been provided into
  # Fastlane, apply it to the payload here.
  payload[:builderName] = params[:builder] if params[:builder]
  payload[:sourceControl][:revision] = params[:revision] if params[:revision]
  payload[:sourceControl][:repository] = params[:repository] if params[:repository]
  payload[:sourceControl][:provider] = params[:provider] if params[:provider]

  payload.reject! {|k,v| v == nil || (v.is_a?(Hash) && v.empty?)}

  if payload[:apiKey].nil? || !payload[:apiKey].is_a?(String)
    UI.user_error! missing_api_key_message(params)
  end
  if payload[:appVersion].nil?
    UI.user_error! missing_app_version_message(params)
  end

  # If verbose flag is enabled (`--verbose`), display the payload debug info
  UI.verbose("Sending build to Bugsnag with payload:")
  payload.each do |param|
    UI.verbose("  #{param[0].to_s.rjust(18)}: #{param[1]}")
  end

  send_notification(params[:endpoint], ::JSON.dump(payload))
end