Class: Fastlane::Actions::UploadToAmazonAppstoreAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



220
221
222
# File 'lib/fastlane/plugin/amazon_appstore/actions/upload_to_amazon_appstore_action.rb', line 220

def self.authors
  ["ntsk"]
end

.available_languages(metadata_path) ⇒ Object



209
210
211
212
213
214
# File 'lib/fastlane/plugin/amazon_appstore/actions/upload_to_amazon_appstore_action.rb', line 209

def self.available_languages()
  return [] unless File.directory?()

  Dir.entries()
     .select { |entry| File.directory?(File.join(, entry)) && !entry.start_with?('.') }
end

.available_optionsObject



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# File 'lib/fastlane/plugin/amazon_appstore/actions/upload_to_amazon_appstore_action.rb', line 232

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :client_id,
                                 env_name: "AMAZON_APPSTORE_CLIENT_ID",
                                 description: "Your client id",
                                 optional: false,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :client_secret,
                                 env_name: "AMAZON_APPSTORE_CLIENT_SECRET",
                                 description: "Your client secret",
                                 optional: false,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :package_name,
                                 env_name: "AMAZON_APPSTORE_PACKAGE_NAME",
                                 description: "The package name of the application to use",
                                 default_value: CredentialsManager::AppfileConfig.try_fetch_value(:package_name),
                                 default_value_dynamic: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :apk,
                                 env_name: "AMAZON_APPSTORE_APK",
                                 description: "The path of the apk file",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :apk_paths,
                                 env_name: "AMAZON_APPSTORE_APK_PATHS",
                                 description: "An array of paths to APK files to upload",
                                 optional: true,
                                 type: Array),
    FastlaneCore::ConfigItem.new(key: :skip_upload_apk,
                                 env_name: "AMAZON_APPSTORE_SKIP_UPLOAD_APK",
                                 description: "Whether to skip uploading APK",
                                 default_value: false,
                                 optional: true,
                                 type: Boolean),
    FastlaneCore::ConfigItem.new(key: :skip_upload_metadata,
                                 env_name: "AMAZON_APPSTORE_SKIP_UPLOAD_METADATA",
                                 description: "Whether to skip uploading metadata (title, descriptions)",
                                 default_value: false,
                                 optional: true,
                                 type: Boolean),
    FastlaneCore::ConfigItem.new(key: :skip_upload_changelogs,
                                 env_name: "AMAZON_APPSTORE_SKIP_UPLOAD_CHANGELOGS",
                                 description: "Whether to skip uploading changelogs",
                                 default_value: false,
                                 optional: true,
                                 type: Boolean),
    FastlaneCore::ConfigItem.new(key: :skip_upload_images,
                                 env_name: "AMAZON_APPSTORE_SKIP_UPLOAD_IMAGES",
                                 description: "Whether to skip uploading images (icons, promo images)",
                                 default_value: true,
                                 optional: true,
                                 type: Boolean),
    FastlaneCore::ConfigItem.new(key: :skip_upload_screenshots,
                                 env_name: "AMAZON_APPSTORE_SKIP_UPLOAD_SCREENSHOTS",
                                 description: "Whether to skip uploading screenshots",
                                 default_value: true,
                                 optional: true,
                                 type: Boolean),
    FastlaneCore::ConfigItem.new(key: :metadata_path,
                                 env_name: "AMAZON_APPSTORE_METADATA_PATH",
                                 description: "Path to the directory containing the metadata files",
                                 default_value: "./fastlane/metadata/android",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :changes_not_sent_for_review,
                                 env_name: "AMAZON_APPSTORE_CHANGES_NOT_SENT_FOR_REVIEW",
                                 description: "Indicates that the changes in this edit will not be reviewed until they are explicitly sent for review from the Amazon Appstore Console UI",
                                 default_value: false,
                                 optional: true,
                                 type: Boolean),
    FastlaneCore::ConfigItem.new(key: :overwrite_upload,
                                 env_name: "AMAZON_APPSTORE_OVERWRITE_UPLOAD",
                                 description: "Whether to allow overwriting an existing upload",
                                 default_value: false,
                                 optional: true,
                                 type: Boolean),
    FastlaneCore::ConfigItem.new(key: :overwrite_upload_mode,
                                 env_name: "AMAZON_APPSTORE_OVERWRITE_UPLOAD_MODE",
                                 description: "Upload strategy. Can be 'new' or 'reuse'",
                                 default_value: 'new',
                                 verify_block: proc do |value|
                                   UI.user_error!("overwrite_upload can only be 'new' or 'reuse'") unless %w(new reuse).include?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :timeout,
                                 env_name: "AMAZON_APPSTORE_TIMEOUT",
                                 description: "Timeout for read, open (in seconds)",
                                 default_value: 300,
                                 optional: true,
                                 type: Integer)
  ]
end

.descriptionObject



216
217
218
# File 'lib/fastlane/plugin/amazon_appstore/actions/upload_to_amazon_appstore_action.rb', line 216

def self.description
  "Upload apps to Amazon Appstore"
end

.detailsObject



228
229
230
# File 'lib/fastlane/plugin/amazon_appstore/actions/upload_to_amazon_appstore_action.rb', line 228

def self.details
  "Upload apps to Amazon Appstore"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


324
325
326
# File 'lib/fastlane/plugin/amazon_appstore/actions/upload_to_amazon_appstore_action.rb', line 324

def self.is_supported?(platform)
  platform.equal?(:android)
end

.return_valueObject



224
225
226
# File 'lib/fastlane/plugin/amazon_appstore/actions/upload_to_amazon_appstore_action.rb', line 224

def self.return_value
  # nothing
end

.run(params) ⇒ Object

rubocop:disable Metrics/PerceivedComplexity



7
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
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
125
126
127
128
129
130
131
# File 'lib/fastlane/plugin/amazon_appstore/actions/upload_to_amazon_appstore_action.rb', line 7

def self.run(params) # rubocop:disable Metrics/PerceivedComplexity
  Helper::AmazonAppstoreHelper.setup(
    timeout: params[:timeout]
  )

  UI.message("Fetching access token...")
  begin
    token = Helper::AmazonAppstoreHelper.token(
      client_id: params[:client_id],
      client_secret: params[:client_secret]
    )
  rescue StandardError => e
    UI.error(e.message)
    UI.abort_with_message!("Failed to get token")
  end
  UI.abort_with_message!("Failed to get token") if token.nil?

  if params[:overwrite_upload]
    if params[:overwrite_upload_mode] == "new"
      UI.message("Deleting existing edits if needed (overwrite_upload: true, overwrite_upload_mode: new)...")
      begin
        Helper::AmazonAppstoreHelper.delete_edits_if_exists(
          app_id: params[:package_name],
          token: token
        )
      rescue StandardError => e
        UI.error(e.message)
        UI.abort_with_message!("Failed to delete edits (overwrite_upload: true, overwrite_upload_mode: new)")
      end
    elsif params[:overwrite_upload_mode] == "reuse"
      UI.message("Retrieving active edit (overwrite_upload: true, overwrite_upload_mode: reuse)...")
      begin
        edit_id, = Helper::AmazonAppstoreHelper.get_edits(
          app_id: params[:package_name],
          token: token
        )
      rescue StandardError => e
        UI.error(e.message)
        UI.abort_with_message!("Failed to get edit_id (overwrite_upload: true, overwrite_upload_mode: reuse)")
      end
      UI.message("No active edit") if edit_id.nil?
    end
  end

  if edit_id.nil?
    UI.message("Creating new edits...")
    begin
      edit_id = Helper::AmazonAppstoreHelper.create_edits(
        app_id: params[:package_name],
        token: token
      )
    rescue StandardError => e
      UI.error(e.message)
      UI.abort_with_message!("Failed to create edits")
    end
    UI.abort_with_message!("Failed to get edit_id") if edit_id.nil?
  end

  version_codes = []

  unless params[:skip_upload_apk]
    apks = []
    apks << params[:apk] if params[:apk]
    apks += params[:apk_paths] if params[:apk_paths]

    if apks.empty?
      UI.abort_with_message!("No APK files provided. Please provide either 'apk' or 'apk_paths' parameter")
    end

    UI.message("Replacing APKs with #{apks.length} file(s)...")
    begin
      apk_results = Helper::AmazonAppstoreHelper.replace_apks(
        apk_paths: apks,
        app_id: params[:package_name],
        edit_id: edit_id,
        token: token
      )
    rescue StandardError => e
      UI.error(e.message)
      UI.abort_with_message!("Failed to replace APKs")
    end
    version_codes = apk_results.map { |result| result[:version_code] }
    apk_results.each_with_index do |result, index|
      UI.message("Successfully processed APK #{index + 1} with version code: #{result[:version_code]}")
    end
  end

  UI.message("Updating release notes...")
  begin
    Helper::AmazonAppstoreHelper.update_changelogs(
      app_id: params[:package_name],
      edit_id: edit_id,
      token: token,
      version_codes: version_codes,
      skip_upload_changelogs: params[:skip_upload_changelogs],
      metadata_path: params[:metadata_path]
    )
  rescue StandardError => e
    UI.error(e.message)
    UI.abort_with_message!("Failed to update changelogs")
  end

  (params, edit_id, token) unless params[:skip_upload_metadata]
  upload_images(params, edit_id, token) unless params[:skip_upload_images]
  upload_screenshots(params, edit_id, token) unless params[:skip_upload_screenshots]

  if params[:changes_not_sent_for_review]
    UI.success('Successfully finished the upload to Amazon Appstore')
    return
  end

  UI.message("Committing edits...")
  begin
    Helper::AmazonAppstoreHelper.commit_edits(
      app_id: params[:package_name],
      edit_id: edit_id,
      token: token
    )
  rescue StandardError => e
    UI.error(e.message)
    UI.abort_with_message!("Failed to commit edits")
  end

  UI.success('Successfully finished the upload to Amazon Appstore')
end

.upload_image_assets(params, edit_id, token, image_types) ⇒ Object



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
# File 'lib/fastlane/plugin/amazon_appstore/actions/upload_to_amazon_appstore_action.rb', line 168

def self.upload_image_assets(params, edit_id, token, image_types)
  languages = available_languages(params[:metadata_path])

  languages.each do |language|
    image_types.each do |image_type|
      images = Helper::AmazonAppstoreHelper.find_images_for_type(
        metadata_path: params[:metadata_path],
        language: language,
        image_type: image_type
      )
      next if images.empty?

      begin
        Helper::AmazonAppstoreHelper.delete_all_images(
          app_id: params[:package_name],
          edit_id: edit_id,
          language: language,
          image_type: image_type,
          token: token
        )
      rescue StandardError => e
        UI.message("Failed to delete existing #{image_type} for #{language}: #{e.message}")
      end

      images.each do |image_path|
        Helper::AmazonAppstoreHelper.upload_image(
          app_id: params[:package_name],
          edit_id: edit_id,
          language: language,
          image_type: image_type,
          image_path: image_path,
          token: token
        )
        UI.message("Uploaded #{image_type} for #{language}: #{File.basename(image_path)}")
      rescue StandardError => e
        UI.error("Failed to upload #{image_type} for #{language}: #{e.message}")
      end
    end
  end
end

.upload_images(params, edit_id, token) ⇒ Object



158
159
160
161
# File 'lib/fastlane/plugin/amazon_appstore/actions/upload_to_amazon_appstore_action.rb', line 158

def self.upload_images(params, edit_id, token)
  UI.message("Uploading images...")
  upload_image_assets(params, edit_id, token, %w[small-icons large-icons promo-images firetv-icons firetv-backgrounds])
end

.upload_metadata(params, edit_id, token) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/fastlane/plugin/amazon_appstore/actions/upload_to_amazon_appstore_action.rb', line 133

def self.(params, edit_id, token)
  UI.message("Uploading metadata...")
  languages = available_languages(params[:metadata_path])
  languages.each do |language|
     = Helper::AmazonAppstoreHelper.(
      metadata_path: params[:metadata_path],
      language: language
    )
    next if .values.all?(&:nil?)

    begin
      Helper::AmazonAppstoreHelper.(
        app_id: params[:package_name],
        edit_id: edit_id,
        language: language,
        listing_data: ,
        token: token
      )
      UI.message("Updated metadata for #{language}")
    rescue StandardError => e
      UI.error("Failed to update metadata for #{language}: #{e.message}")
    end
  end
end

.upload_screenshots(params, edit_id, token) ⇒ Object



163
164
165
166
# File 'lib/fastlane/plugin/amazon_appstore/actions/upload_to_amazon_appstore_action.rb', line 163

def self.upload_screenshots(params, edit_id, token)
  UI.message("Uploading screenshots...")
  upload_image_assets(params, edit_id, token, %w[screenshots firetv-screenshots])
end