spaceship/lib/spaceship/connect_api/models/app_screenshot.rb in fastlane-2.152.0 vs spaceship/lib/spaceship/connect_api/models/app_screenshot.rb in fastlane-2.153.0
- old
+ new
@@ -1,26 +1,29 @@
require_relative '../model'
require_relative '../file_uploader'
+require_relative './app_screenshot_set'
require 'spaceship/globals'
require 'digest/md5'
module Spaceship
class ConnectAPI
class AppScreenshot
include Spaceship::ConnectAPI::Model
+ attr_accessor :file_size
attr_accessor :file_name
attr_accessor :source_file_checksum
attr_accessor :image_asset
attr_accessor :asset_token
attr_accessor :asset_type
attr_accessor :upload_operations
attr_accessor :asset_delivery_state
attr_accessor :uploaded
attr_mapping({
+ "fileSize" => "file_size",
"fileName" => "file_name",
"sourceFileChecksum" => "source_file_checksum",
"imageAsset" => "image_asset",
"assetToken" => "asset_token",
"assetType" => "asset_type",
@@ -31,10 +34,14 @@
def self.type
return "appScreenshots"
end
+ def awaiting_upload?
+ (asset_delivery_state || {})["state"] == "AWAITING_UPLOAD"
+ end
+
def complete?
(asset_delivery_state || {})["state"] == "COMPLETE"
end
def error?
@@ -82,14 +89,46 @@
post_attributes = {
fileSize: filesize,
fileName: filename
}
- # Create placeholder
- screenshot = Spaceship::ConnectAPI.post_app_screenshot(
- app_screenshot_set_id: app_screenshot_set_id,
- attributes: post_attributes
- ).first
+ # Create placeholder to upload screenshot
+ begin
+ screenshot = Spaceship::ConnectAPI.post_app_screenshot(
+ app_screenshot_set_id: app_screenshot_set_id,
+ attributes: post_attributes
+ ).first
+ rescue => error
+ # Sometimes creating a screenshot with the web session App Store Connect API
+ # will result in a false failure. The response will return a 503 but the database
+ # insert will eventually go through.
+ #
+ # When this is observed, we will poll until we find the matchin screenshot that
+ # is awaiting for upload and file size
+ #
+ # https://github.com/fastlane/fastlane/pull/16842
+ time = Time.now.to_i
+
+ timeout_minutes = (ENV["SPACESHIP_SCREENSHOT_UPLOAD_TIMEOUT"] || 20).to_i
+
+ loop do
+ puts("Waiting for screenshot to appear before uploading...")
+ sleep(30)
+
+ screenshots = Spaceship::ConnectAPI::AppScreenshotSet
+ .get(app_screenshot_set_id: app_screenshot_set_id)
+ .app_screenshots
+
+ screenshot = screenshots.find do |s|
+ s.awaiting_upload? && s.file_size == filesize
+ end
+
+ break if screenshot
+
+ time_diff = Time.now.to_i - time
+ raise error if time_diff >= (60 * timeout_minutes)
+ end
+ end
# Upload the file
upload_operations = screenshot.upload_operations
Spaceship::ConnectAPI::FileUploader.upload(upload_operations, bytes)