import Foundation import ArgumentParser import XKit import XCLIUtils /// `xtool dist` — App Store Connect distribution (upload + submit). /// /// Output lines `BUILD_ID:` / `BUILD_STATE:` (upload) and `SUBMISSION_ID:` / /// `SUBMISSION_STATE:` (submit) are a stable machine-readable contract; the /// Modern-Apps release pipeline parses them. struct DistCommand: AsyncParsableCommand { static let configuration = CommandConfiguration( commandName: "dist", abstract: "Upload builds to App Store Connect and submit them for review", subcommands: [ DistUploadCommand.self, DistSubmitCommand.self, ] ) } struct DistUploadCommand: AsyncParsableCommand { static let configuration = CommandConfiguration( commandName: "upload", abstract: "Upload an .ipa to App Store Connect" ) @Argument(help: "Path to the .ipa to upload") var ipaPath: String func run() async throws { let client = AppStoreConnectClient(key: try resolveASCKey()) let result = try await client.uploadIPA(at: URL(fileURLWithPath: ipaPath)) print("BUILD_ID:\(result.buildID)") print("BUILD_STATE:\(result.state)") } } struct DistSubmitCommand: AsyncParsableCommand { static let configuration = CommandConfiguration( commandName: "submit", abstract: "Create/attach the App Store version for a build and submit it for review" ) @Option(help: "Bundle id of the app, e.g. cc.findfamily.app.1") var bundleID: String @Option(name: .customLong("version"), help: "App Store version string, e.g. 2.6.11") var versionString: String @Option(help: "Build number (CFBundleVersion) already uploaded and processed") var buildNumber: String @Option(help: "Path to a plain-text whatsNew file (max 4000 characters)") var whatsNew: String @Option(help: "Localization locale for whatsNew") var locale: String = "en-US" func run() async throws { let notes = try String(contentsOfFile: whatsNew, encoding: .utf8) .trimmingCharacters(in: .whitespacesAndNewlines) guard !notes.isEmpty, notes.count <= 4000 else { throw Console.Error("whatsNew must be 1...4000 characters (got \(notes.count))") } let client = AppStoreConnectClient(key: try resolveASCKey()) let result = try await client.submitForReview( bundleID: bundleID, version: versionString, buildNumber: buildNumber, whatsNew: notes, locale: locale ) print("SUBMISSION_ID:\(result.submissionID)") print("SUBMISSION_STATE:\(result.state)") } }