Skip to content
This repository was archived by the owner on Jan 29, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ Call `amazon_app_submission` in your Fastfile.
upload_apk: true,
changelogs_path: "<CHANGELOG_PATH>",
upload_changelogs: false,
submit_for_review: false
submit_for_review: false,
read_timeout: 1000,
write_timeout: 1000,
)
```

Expand All @@ -47,6 +49,8 @@ upload_apk | true | true | set this to false to not upload an apk. can be use
changelogs_path | "" | true | setting the folder path where you have the change logs with different file for each language, if language file not found it will use default.txt
upload_changelogs | false | true | updating the change logs for the upcoming version
submit_for_review | false | true | submit the uploaded APK to the store
read_timeout | 1000 | true | read timeout in seconds for the apk upload process
submit_for_review | 1000 | true | write timeout in seconds for the apk upload process

* changelogs folder files name should be:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def self.run(params)
token = Helper::AmazonAppSubmissionHelper.get_token(params[:client_id], params[:client_secret])

if token.nil?
UI.message("Cannot retrieve token, please check your client ID and client secret")
UI.user_error!("Cannot retrieve token, please check your client ID and client secret", show_github_issues: false)
end

UI.message("Getting current edit")
Expand All @@ -23,38 +23,37 @@ def self.run(params)
end

if current_edit_id.nil?
UI.error("Creating new edit failed!")
UI.crash!("Creating new edit failed!")
return
end

if params[:upload_apk]
UI.message("Get current apk id")
current_apk_id = Helper::AmazonAppSubmissionHelper.get_current_apk_id(token, params[:app_id], current_edit_id)

UI.message("Get current apk ETag")
current_apk_eTag = Helper::AmazonAppSubmissionHelper.get_current_apk_etag(token, params[:app_id], current_edit_id, current_apk_id)
if current_apk_id.nil?
UI.message("No apk found. Uploading new apk.")
Helper::AmazonAppSubmissionHelper.uploadNewApk(token, params[:app_id], current_edit_id, params[:apk_path], params[:read_timeout], params[:write_timeout])
else
UI.message("Get current apk ETag")
current_apk_eTag = Helper::AmazonAppSubmissionHelper.get_current_apk_etag(token, params[:app_id], current_edit_id, current_apk_id)

UI.message("Replacing the apk with apk from #{params[:apk_path]}")
replace_apk_response_code, replace_apk_response = Helper::AmazonAppSubmissionHelper.replaceExistingApk(token, params[:app_id], current_edit_id, current_apk_id, current_apk_eTag, params[:apk_path])
UI.message("Replacing the apk with apk from #{params[:apk_path]}")
Helper::AmazonAppSubmissionHelper.replaceExistingApk(token, params[:app_id], current_edit_id, current_apk_id, current_apk_eTag, params[:apk_path], params[:read_timeout], params[:write_timeout])
end
end

if params[:upload_changelogs]
UI.message("Updating the changelogs")
Helper::AmazonAppSubmissionHelper.update_listings( token, params[:app_id],current_edit_id, params[:changelogs_path], params[:changelogs_path])
end

if params[:upload_apk]
if replace_apk_response_code == '200'
if params[:submit_for_review]
UI.message("Submitting to Amazon app store")
Helper::AmazonAppSubmissionHelper.commit_edit(token, params[:app_id], current_edit_id, edit_eTag)
end
else
UI.message("Amazon app submission failed at replacing the apk error code #{replace_apk_response_code} and error respones #{replace_apk_response}")
return
end
if params[:upload_apk] && params[:submit_for_review]
UI.message("Submitting to Amazon app store")
Helper::AmazonAppSubmissionHelper.commit_edit(token, params[:app_id], current_edit_id, edit_eTag)
end
UI.message("Amazon app submission finished successfully!")

UI.success("Amazon app submission finished successfully!")
end

def self.description
Expand All @@ -71,7 +70,7 @@ def self.return_value

def self.details
# Optional:
"Fastlane plugin for Amazon App Submissions"
"Creates an Upcoming Version for an Amazon Appstore app, uploads the data, then and submits the new Version for review"
end

def self.available_options
Expand Down Expand Up @@ -127,7 +126,21 @@ def self.available_options
description: "Amazon App Submission submit for review",
default_value: false,
optional: true,
type: Boolean)
type: Boolean),

FastlaneCore::ConfigItem.new(key: :read_timeout,
env_name: "AMAZON_APP_SUBMISSION_READ_TIMEOUT",
description: "Read timeout in seconds for the apk upload process",
default_value: 1000,
optional: true,
type: Fixnum),

FastlaneCore::ConfigItem.new(key: :write_timeout,
env_name: "AMAZON_APP_SUBMISSION_WRITE_TIMEOUT",
description: "Write timeout in seconds for the apk upload process",
default_value: 1000,
optional: true,
type: Fixnum)

# FastlaneCore::ConfigItem.new(key: :your_option,
# env_name: "AMAZON_APP_SUBMISSION_YOUR_OPTION",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ def self.get_token(client_id, client_secret)
auth_token = "Bearer #{result_json['access_token']}"

if result_json['error'] == 'invalid_scope'
UI.message("It seems that the provided security profile is not attached to the App Submission API")
UI.crash!("It seems that the provided security profile is not attached to the App Submission API")
end
UI.crash!(res.body) unless res.code == '200'

return auth_token
end
Expand All @@ -46,8 +47,9 @@ def self.create_new_edit(token, app_id)
)

res = http.request(req)
UI.crash!(res.body) unless res.code == '200'
current_edit = JSON.parse(res.body)

return current_edit['id']
end

Expand Down Expand Up @@ -86,6 +88,7 @@ def self.get_current_apk_id(token, app_id, edit_id)
)

res = http.request(req)

if !res.body.nil?
apks = JSON.parse(res.body)
firstAPK = apks.kind_of?(Array) ? apks[0] : apks
Expand All @@ -109,10 +112,11 @@ def self.get_current_apk_etag(token, app_id, edit_id, apk_id)
)

res = http.request(req)
UI.crash!(res.body) unless res.code == '200'
return res.header['ETag']
end

def self.replaceExistingApk(token, app_id, edit_id, apk_id, eTag, apk_path, should_retry = true)
def self.replaceExistingApk(token, app_id, edit_id, apk_id, eTag, apk_path, read_timeout, write_timeout, should_retry = true)

replace_apk_path = "/v1/applications/#{app_id}/edits/#{edit_id}/apks/#{apk_id}/replace"
local_apk = File.open(apk_path, "r").read
Expand All @@ -124,7 +128,8 @@ def self.replaceExistingApk(token, app_id, edit_id, apk_id, eTag, apk_path, shou
uri = URI(replace_apk_url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.write_timeout = 1000
http.write_timeout = write_timeout
http.read_timeout = read_timeout
req = Net::HTTP::Put.new(
uri.path,
'Authorization' => token,
Expand All @@ -135,12 +140,13 @@ def self.replaceExistingApk(token, app_id, edit_id, apk_id, eTag, apk_path, shou

req.body = local_apk
res = http.request(req)

replace_apk_response = JSON.parse(res.body)
# Retry again if replace failed
if res.code == '412' && should_retry
UI.message("replacing the apk failed, retrying uploading it again...")
replaceExistingApk(token, app_id, edit_id, apk_id, eTag, apk_path, false)
return
UI.important("replacing the apk failed, retrying uploading it again...")
retry_code, retry_res = replaceExistingApk(token, app_id, edit_id, apk_id, eTag, apk_path, read_timeout, write_timeout, false)
UI.crash!(retry_res) unless retry_code == '200'
end
return res.code, replace_apk_response
end
Expand All @@ -161,10 +167,11 @@ def self.delete_apk(token, app_id, edit_id, apk_id, eTag)
)

res = http.request(req)
UI.crash!(res.body) unless res.code == '200'
result_json = JSON.parse(res.body)
end

def self.uploadNewApk(token, app_id, edit_id, apk_path)
def self.uploadNewApk(token, app_id, edit_id, apk_path, read_timeout, write_timeout)

add_apk_path = "/v1/applications/#{app_id}/edits/#{edit_id}/apks/upload"
add_apk_url = BASE_URL + add_apk_path
Expand All @@ -173,8 +180,8 @@ def self.uploadNewApk(token, app_id, edit_id, apk_path)
uri = URI(add_apk_url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.write_timeout = 1000
http.read_timeout = 1000
http.write_timeout = write_timeout
http.read_timeout = read_timeout
req = Net::HTTP::Post.new(
uri.path,
'Authorization' => token,
Expand All @@ -183,6 +190,7 @@ def self.uploadNewApk(token, app_id, edit_id, apk_path)

req.body = local_apk
res = http.request(req)
UI.crash!(res.body) unless res.code == '200'
result_json = JSON.parse(res.body)
end

Expand All @@ -201,6 +209,7 @@ def self.update_listings(token, app_id, edit_id, changelogs_path, upload_changel
)

res = http.request(req)
UI.crash!(res.body) unless res.code == '200'
listings_response = JSON.parse(res.body)

# Iterating over the languages for getting the ETag.
Expand All @@ -217,6 +226,7 @@ def self.update_listings(token, app_id, edit_id, changelogs_path, upload_changel
'Content-Type' => 'application/json'
)
etag_response = http.request(req)
UI.crash!(etag_response) unless etag_response.code == '200'
etag = etag_response.header['Etag']

recent_changes = find_changelog(
Expand All @@ -242,6 +252,7 @@ def self.update_listings(token, app_id, edit_id, changelogs_path, upload_changel

req.body = listing.to_json
res = http.request(req)
UI.crash!(res.body) unless res.code == '200'
listings_response = JSON.parse(res.body)
end
end
Expand Down Expand Up @@ -281,6 +292,7 @@ def self.commit_edit(token, app_id, edit_id, eTag)
)

res = http.request(req)
UI.crash!(res.body) unless res.code == '200'
result_json = JSON.parse(res.body)
end
end
Expand Down