Class: Fastlane::Actions::DeploygateAction

Inherits:
Fastlane::Action show all
Defined in:
fastlane/lib/fastlane/actions/deploygate.rb

Constant Summary collapse

DEPLOYGATE_URL_BASE =
'https://deploygate.com'

Constants inherited from Fastlane::Action

Fastlane::Action::AVAILABLE_CATEGORIES, Fastlane::Action::RETURN_TYPES

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, author, deprecated_notes, lane_context, method_missing, other_action, return_type, return_value, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorsObject



205
206
207
# File 'fastlane/lib/fastlane/actions/deploygate.rb', line 205

def self.authors
  ["tnj", "tomorrowkey"]
end

.available_optionsObject



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

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :api_token,
                                 env_name: "DEPLOYGATE_API_TOKEN",
                                 description: "Deploygate API Token",
                                 sensitive: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("No API Token for DeployGate given, pass using `api_token: 'token'`") unless value.to_s.length > 0
                                 end),
    FastlaneCore::ConfigItem.new(key: :user,
                                 env_name: "DEPLOYGATE_USER",
                                 description: "Target username or organization name",
                                 verify_block: proc do |value|
                                   UI.user_error!("No User for DeployGate given, pass using `user: 'user'`") unless value.to_s.length > 0
                                 end),
    FastlaneCore::ConfigItem.new(key: :ipa,
                                 env_name: "DEPLOYGATE_IPA_PATH",
                                 description: "Path to your IPA file. Optional if you use the _gym_ or _xcodebuild_ action",
                                 default_value: Actions.lane_context[SharedValues::IPA_OUTPUT_PATH],
                                 default_value_dynamic: true,
                                 optional: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("Couldn't find ipa file at path '#{value}'") unless File.exist?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :apk,
                                 env_name: "DEPLOYGATE_APK_PATH",
                                 description: "Path to your APK file",
                                 default_value: Actions.lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH],
                                 default_value_dynamic: true,
                                 optional: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("Couldn't find apk file at path '#{value}'") unless File.exist?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :message,
                                 env_name: "DEPLOYGATE_MESSAGE",
                                 description: "Release Notes",
                                 default_value: "No changelog provided"),
    FastlaneCore::ConfigItem.new(key: :distribution_key,
                                 optional: true,
                                 env_name: "DEPLOYGATE_DISTRIBUTION_KEY",
                                 sensitive: true,
                                 description: "Target Distribution Key"),
    FastlaneCore::ConfigItem.new(key: :release_note,
                                 optional: true,
                                 env_name: "DEPLOYGATE_RELEASE_NOTE",
                                 description: "Release note for distribution page"),
    FastlaneCore::ConfigItem.new(key: :disable_notify,
                                 optional: true,
                                 is_string: false,
                                 default_value: false,
                                 env_name: "DEPLOYGATE_DISABLE_NOTIFY",
                                 description: "Disables Push notification emails"),
    FastlaneCore::ConfigItem.new(key: :distribution_name,
                                 optional: true,
                                 is_string: true,
                                 env_name: "DEPLOYGATE_DISTRIBUTION_NAME",
                                 description: "Target Distribution Name")
  ]
end

.categoryObject



201
202
203
# File 'fastlane/lib/fastlane/actions/deploygate.rb', line 201

def self.category
  :beta
end

.descriptionObject



101
102
103
# File 'fastlane/lib/fastlane/actions/deploygate.rb', line 101

def self.description
  "Upload a new build to [DeployGate](https://deploygate.com/)"
end

.detailsObject



105
106
107
108
109
110
# File 'fastlane/lib/fastlane/actions/deploygate.rb', line 105

def self.details
  [
    "You can retrieve your username and API token on [your settings page](https://deploygate.com/settings).",
    "More information about the available options can be found in the [DeployGate Push API document](https://deploygate.com/docs/api)."
  ].join("\n")
end

.example_codeObject



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'fastlane/lib/fastlane/actions/deploygate.rb', line 180

def self.example_code
  [
    'deploygate(
      api_token: "...",
      user: "target username or organization name",
      ipa: "./ipa_file.ipa",
      message: "Build #{lane_context[SharedValues::BUILD_NUMBER]}",
      distribution_key: "(Optional) Target Distribution Key",
      distribution_name: "(Optional) Target Distribution Name"
    )',
    'deploygate(
      api_token: "...",
      user: "target username or organization name",
      apk: "./apk_file.apk",
      message: "Build #{lane_context[SharedValues::BUILD_NUMBER]}",
      distribution_key: "(Optional) Target Distribution Key",
      distribution_name: "(Optional) Target Distribution Name"
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



12
13
14
# File 'fastlane/lib/fastlane/actions/deploygate.rb', line 12

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

.outputObject



172
173
174
175
176
177
178
# File 'fastlane/lib/fastlane/actions/deploygate.rb', line 172

def self.output
  [
    ['DEPLOYGATE_URL', 'URL of the newly uploaded build'],
    ['DEPLOYGATE_REVISION', 'auto incremented revision number'],
    ['DEPLOYGATE_APP_INFO', 'Contains app revision, bundle identifier, etc.']
  ]
end

.run(options) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'fastlane/lib/fastlane/actions/deploygate.rb', line 40

def self.run(options)
  # Available options: https://deploygate.com/docs/api
  UI.success('Starting with app upload to DeployGate... this could take some time ⏳')

  api_token = options[:api_token]
  user_name = options[:user]
  binary = options[:ipa] || options[:apk]
  upload_options = options.values.select do |key, _|
    [:message, :distribution_key, :release_note, :disable_notify, :distribution_name].include?(key)
  end

  UI.user_error!('missing `ipa` and `apk`. deploygate action needs least one.') unless binary

  return binary if Helper.test?

  response = self.upload_build(api_token, user_name, binary, upload_options)
  if parse_response(response)
    UI.message("DeployGate URL: #{Actions.lane_context[SharedValues::DEPLOYGATE_URL]}")
    UI.success("Build successfully uploaded to DeployGate as revision \##{Actions.lane_context[SharedValues::DEPLOYGATE_REVISION]}!")
  else
    UI.user_error!("Error when trying to upload app to DeployGate")
  end
end

.upload_build(api_token, user_name, binary, options) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'fastlane/lib/fastlane/actions/deploygate.rb', line 16

def self.upload_build(api_token, user_name, binary, options)
  require 'faraday'
  require 'faraday_middleware'

  connection = Faraday.new(url: DEPLOYGATE_URL_BASE, request: { timeout: 120 }) do |builder|
    builder.request(:multipart)
    builder.request(:json)
    builder.response(:json, content_type: /\bjson$/)
    builder.use(FaradayMiddleware::FollowRedirects)
    builder.adapter(:net_http)
  end

  options.update({
    token: api_token,
    file: Faraday::UploadIO.new(binary, 'application/octet-stream'),
    message: options[:message] || ''
  })
  options[:disable_notify] = 'yes' if options[:disable_notify]

  connection.post("/api/users/#{user_name}/apps", options)
rescue Faraday::Error::TimeoutError
  UI.crash!("Timed out while uploading build. Check https://deploygate.com/ to see if the upload was completed.")
end