Modern Apps git

xtool.git

Public
git clone https://git.maproj.org/xtool.git
main ▾

xtool.git / Sources / XToolSupport / DistCommand.swift

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