Files
swiftcontrol/ios/fastlane/Fastfile
Jonas Bark 1f378f7cd2 Upload App Store screenshots via the API, not deliver
deliver's screenshot upload races App Store Connect's async processing:
it duplicates locales ("too many screenshots", 05/06 dropped) and, even
when the count is right, orders them wrong (virtualshifting-settings
landed first on every locale). fastlane 2.236.1 is the latest, so this
is an inherent deliver limitation, not a version bug.

Replace the deliver screenshot path with a deterministic direct
Spaceship::ConnectAPI sync: clear each set (confirming the delete
actually committed, since ASC reports it optimistically), upload each
shot serialized with wait_for_processing and an explicit position, then
reorder by filename. deliver now only handles the localized texts
(skip_screenshots). Applies to both the iOS and macOS lanes.

Verified against the live 6.1 listing: all iOS locales (iPhone+iPad) and
all macOS locales now show 6 screenshots each in device → trainer →
virtualshifting → virtualshifting-settings → customization → companion
order, no duplicates.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-18 20:22:09 +02:00

194 lines
7.5 KiB
Ruby

# Fastlane configuration for the Apple App Store listing (iOS + macOS).
#
# Manages the localized store metadata (name, subtitle, description, keywords,
# ...) and the screenshots. The listing text lives in the private `prop`
# submodule under prop/store_metadata/ios/<locale>/ so it is not exposed in the
# public repo. Authentication uses an App Store Connect API key.
#
# Screenshots are uploaded directly through the App Store Connect API rather
# than via deliver: deliver's screenshot handling races App Store Connect's
# asynchronous processing, which leaves duplicates ("too many screenshots"),
# drops images and — even when the count is right — orders them wrong. The
# direct path below clears each set, uploads serialized (wait_for_processing)
# and sets an explicit position, then reorders, so the result is deterministic.
default_platform(:ios)
# fastlane chdir's into the fastlane/ folder before running a lane, so relative
# paths resolve against ios/fastlane/. Anchor everything at the repo root
# instead (GITHUB_WORKSPACE in CI; two levels up from this file locally).
ROOT = ENV["GITHUB_WORKSPACE"] || File.expand_path("../..", __dir__)
APP_IDENTIFIER = "de.jonasbark.swiftcontrol.darwin"
METADATA = File.join(ROOT, "prop/store_metadata/ios") # private submodule
SCREENSHOTS = File.join(ROOT, "ios/fastlane/screenshots")
# macOS shares the App Store record (same bundle id) and reuses the iOS listing
# texts; only the screenshots differ (desktop renders, prepared into this dir).
SCREENSHOTS_MACOS = File.join(ROOT, "ios/fastlane/screenshots_macos")
API_KEY_JSON = File.join(ROOT, "ios/fastlane/asc_api_key.json")
# Store locales (the per-locale screenshot folder names).
STORE_LOCALES = ["en-US", "de-DE", "fr-FR", "es-ES", "it", "pl"]
def asc_api_key
app_store_connect_api_key(
key_id: ENV["APPSTORE_API_KEY"], # the AuthKey id, e.g. "ABCD1234XY"
issuer_id: ENV["APPSTORE_API_ISSUER_ID"],
key_filepath: ENV["APPSTORE_API_KEY_PATH"] ||
File.join(ROOT, "private_keys/AuthKey_#{ENV['APPSTORE_API_KEY']}.p8"),
in_house: false,
)
end
# Authorize Spaceship::ConnectAPI for the direct screenshot calls below.
def authorize_spaceship
app_store_connect_api_key(
key_id: ENV["APPSTORE_API_KEY"],
issuer_id: ENV["APPSTORE_API_ISSUER_ID"],
key_filepath: ENV["APPSTORE_API_KEY_PATH"] ||
File.join(ROOT, "private_keys/AuthKey_#{ENV['APPSTORE_API_KEY']}.p8"),
in_house: false,
set_spaceship_token: true,
)
end
# Map a prepared screenshot filename to its App Store Connect display type.
def screenshot_display_type(filename)
return "APP_IPHONE_65" if filename.include?("iphone65")
return "APP_IPAD_PRO_3GEN_129" if filename.include?("ipad129")
return "APP_DESKTOP" if filename.include?("desktop")
nil
end
def version_localization(version, locale)
version.get_app_store_version_localizations.find { |l| l.locale == locale }
end
# Delete every screenshot for one locale. App Store Connect reports deletions
# optimistically (a freshly-deleted set reads as empty before the delete has
# committed), so once we've deleted anything we require two consecutive empty
# reads before trusting it. A set that is already empty returns immediately.
def clear_locale_screenshots(version, locale)
empties = 0
deleted = false
20.times do
shots = version_localization(version, locale)
.get_app_screenshot_sets.flat_map { |s| s.app_screenshots || [] }
if shots.empty?
return unless deleted
empties += 1
return if empties >= 2
else
deleted = true
empties = 0
shots.each do |s|
begin
s.delete!
rescue => e
UI.error("#{locale}: failed to delete a screenshot: #{e.message}")
end
end
end
sleep(12)
end
UI.important("#{locale}: screenshots not confirmed empty after retries; continuing")
end
# Upload NN_*.png in filename order, serialized and with an explicit position,
# then reorder by filename so the final display order is deterministic.
def upload_locale_screenshots(version, locale, dir)
loc = version_localization(version, locale)
Dir.glob(File.join(dir, "*.png")).sort
.group_by { |f| screenshot_display_type(File.basename(f)) }
.each do |display_type, files|
next if display_type.nil?
set = loc.get_app_screenshot_sets.find { |s| s.screenshot_display_type == display_type }
set ||= loc.create_app_screenshot_set(attributes: { screenshotDisplayType: display_type })
files.sort.each_with_index do |file, i|
UI.message("#{locale} #{display_type}: #{File.basename(file)} (pos #{i})")
set.upload_screenshot(path: file, wait_for_processing: true, position: i)
end
end
version_localization(version, locale).get_app_screenshot_sets.each do |set|
shots = set.app_screenshots || []
next if shots.empty?
ordered = shots.sort_by { |s| s.file_name.to_s }
set.reorder_screenshots(app_screenshot_ids: ordered.map(&:id))
end
end
# Replace the whole screenshot set for the editable version of `platform`
# ("IOS" / "MAC_OS") from the prepared per-locale folders under `root`.
def sync_screenshots(platform, root)
authorize_spaceship
app = Spaceship::ConnectAPI::App.find(APP_IDENTIFIER)
UI.user_error!("App #{APP_IDENTIFIER} not found on App Store Connect") if app.nil?
version = app.get_edit_app_store_version(platform: platform)
if version.nil?
UI.important("#{platform}: no editable version — skipping screenshot sync")
return
end
STORE_LOCALES.each do |locale|
dir = File.join(root, locale)
next unless File.directory?(dir)
UI.message("Syncing #{platform} screenshots for #{locale}")
clear_locale_screenshots(version, locale)
upload_locale_screenshots(version, locale, dir)
end
UI.success("#{platform}: screenshots synced")
end
platform :ios do
desc "Upload the localized App Store listing texts & screenshots (no binary)"
lane :upload_metadata do
# deliver handles the localized texts only; screenshots go through the
# deterministic direct-API path (deliver's own upload misorders/duplicates).
deliver(
api_key: asc_api_key,
app_identifier: APP_IDENTIFIER,
metadata_path: METADATA,
skip_binary_upload: true,
skip_screenshots: true,
skip_app_version_update: true,
submit_for_review: false,
run_precheck_before_submit: false,
force: true,
)
sync_screenshots("IOS", SCREENSHOTS)
end
desc "Upload the Mac App Store listing — mirrors the iOS texts (same metadata "\
"path), with the desktop screenshots"
lane :upload_metadata_macos do
deliver(
api_key: asc_api_key,
app_identifier: APP_IDENTIFIER,
platform: "osx",
metadata_path: METADATA, # mirror the iOS listing texts
skip_binary_upload: true,
skip_screenshots: true,
skip_app_version_update: true,
submit_for_review: false,
run_precheck_before_submit: false,
force: true,
)
sync_screenshots("MAC_OS", SCREENSHOTS_MACOS)
end
desc "Download the current App Store listing into prop/store_metadata/ios"
lane :download_metadata do
require "json"
key = asc_api_key
File.write(API_KEY_JSON, JSON.pretty_generate(key))
begin
sh(
"bundle", "exec", "fastlane", "deliver", "download_metadata",
"--api_key_path", API_KEY_JSON,
"--app_identifier", APP_IDENTIFIER,
"--metadata_path", METADATA,
"--force", "true",
)
ensure
File.delete(API_KEY_JSON) if File.exist?(API_KEY_JSON)
end
end
end