xtool.git
Publicgit clone https://git.maproj.org/xtool.gitxtool.git / Sources / XToolSupport / DistCommand.swift
DistCommand.swift76 lines · 2.6 KiBRaw
| 1 | import Foundation |
| 2 | import ArgumentParser |
| 3 | import XKit |
| 4 | |
| 5 | /// `xtool dist` — App Store Connect distribution (upload + submit). |
| 6 | /// |
| 7 | /// Output lines `BUILD_ID:` / `BUILD_STATE:` (upload) and `SUBMISSION_ID:` / |
| 8 | /// `SUBMISSION_STATE:` (submit) are a stable machine-readable contract; the |
| 9 | /// Modern-Apps release pipeline parses them. |
| 10 | struct DistCommand: AsyncParsableCommand { |
| 11 | static let configuration = CommandConfiguration( |
| 12 | commandName: "dist", |
| 13 | abstract: "Upload builds to App Store Connect and submit them for review", |
| 14 | subcommands: [ |
| 15 | DistUploadCommand.self, |
| 16 | DistSubmitCommand.self, |
| 17 | ] |
| 18 | ) |
| 19 | } |
| 20 | |
| 21 | struct DistUploadCommand: AsyncParsableCommand { |
| 22 | static let configuration = CommandConfiguration( |
| 23 | commandName: "upload", |
| 24 | abstract: "Upload an .ipa to App Store Connect" |
| 25 | ) |
| 26 | |
| 27 | @Argument(help: "Path to the .ipa to upload") |
| 28 | var ipaPath: String |
| 29 | |
| 30 | func run() async throws { |
| 31 | let client = AppStoreConnectClient(key: try resolveASCKey()) |
| 32 | let result = try await client.uploadIPA(at: URL(fileURLWithPath: ipaPath)) |
| 33 | print("BUILD_ID:\(result.buildID)") |
| 34 | print("BUILD_STATE:\(result.state)") |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | struct DistSubmitCommand: AsyncParsableCommand { |
| 39 | static let configuration = CommandConfiguration( |
| 40 | commandName: "submit", |
| 41 | abstract: "Create/attach the App Store version for a build and submit it for review" |
| 42 | ) |
| 43 | |
| 44 | @Option(help: "Bundle id of the app, e.g. cc.findfamily.app.1") |
| 45 | var bundleID: String |
| 46 | |
| 47 | @Option(name: .customLong("version"), help: "App Store version string, e.g. 2.6.11") |
| 48 | var versionString: String |
| 49 | |
| 50 | @Option(help: "Build number (CFBundleVersion) already uploaded and processed") |
| 51 | var buildNumber: String |
| 52 | |
| 53 | @Option(help: "Path to a plain-text whatsNew file (max 4000 characters)") |
| 54 | var whatsNew: String |
| 55 | |
| 56 | @Option(help: "Localization locale for whatsNew") |
| 57 | var locale: String = "en-US" |
| 58 | |
| 59 | func run() async throws { |
| 60 | let notes = try String(contentsOfFile: whatsNew, encoding: .utf8) |
| 61 | .trimmingCharacters(in: .whitespacesAndNewlines) |
| 62 | guard !notes.isEmpty, notes.count <= 4000 else { |
| 63 | throw Console.Error("whatsNew must be 1...4000 characters (got \(notes.count))") |
| 64 | } |
| 65 | let client = AppStoreConnectClient(key: try resolveASCKey()) |
| 66 | let result = try await client.submitForReview( |
| 67 | bundleID: bundleID, |
| 68 | version: versionString, |
| 69 | buildNumber: buildNumber, |
| 70 | whatsNew: notes, |
| 71 | locale: locale |
| 72 | ) |
| 73 | print("SUBMISSION_ID:\(result.submissionID)") |
| 74 | print("SUBMISSION_STATE:\(result.state)") |
| 75 | } |
| 76 | } |