Skip to content

Commit 0c5a63f

Browse files
authored
feat: Add Swift Package Registry tools and config (#1597)
1 parent 8651f9b commit 0c5a63f

File tree

197 files changed

+1409
-180
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

197 files changed

+1409
-180
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,7 @@ codegen/protocol-test-codegen/smithy-build.json
3535

3636
# VS Code config files
3737
.vscode/
38+
39+
# Allow the AWSSDKSwiftCLI Package.resolved
40+
# while excluding all other Package.resolved files
41+
!/AWSSDKSwiftCLI/Package.resolved

.swiftlint.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
included:
2-
- Sources/Core
2+
- Sources/Core/AWSClientRuntime/Sources
3+
- Sources/Core/AWSSDKChecksums/Sources
4+
- Sources/Core/AWSSDKCommon/Sources
5+
- Sources/Core/AWSSDKEventStreamsAuth/Sources
6+
- Sources/Core/AWSSDKHTTPAuth/Sources
7+
- Sources/Core/AWSSDKIdentity/Sources
38

49
analyzer_rules:
510
- unused_import

AWSSDKSwiftCLI/Package.resolved

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
{
2+
"pins" : [
3+
{
4+
"identity" : "aws-crt-swift",
5+
"kind" : "remoteSourceControl",
6+
"location" : "https://github.com/awslabs/aws-crt-swift",
7+
"state" : {
8+
"revision" : "b6380f683b31072d77b601c88674461c11bcad5a",
9+
"version" : "0.30.0"
10+
}
11+
},
12+
{
13+
"identity" : "aws-sdk-swift",
14+
"kind" : "remoteSourceControl",
15+
"location" : "https://github.com/awslabs/aws-sdk-swift",
16+
"state" : {
17+
"revision" : "3c20e0be8c8246de8b8e04372404ef1f90be71b6",
18+
"version" : "0.46.0"
19+
}
20+
},
21+
{
22+
"identity" : "smithy-swift",
23+
"kind" : "remoteSourceControl",
24+
"location" : "https://github.com/smithy-lang/smithy-swift",
25+
"state" : {
26+
"revision" : "b2322a067f85c230f17c80be8a67dd543454b081",
27+
"version" : "0.51.0"
28+
}
29+
},
30+
{
31+
"identity" : "swift-algorithms",
32+
"kind" : "remoteSourceControl",
33+
"location" : "https://github.com/apple/swift-algorithms",
34+
"state" : {
35+
"revision" : "f6919dfc309e7f1b56224378b11e28bab5bccc42",
36+
"version" : "1.2.0"
37+
}
38+
},
39+
{
40+
"identity" : "swift-argument-parser",
41+
"kind" : "remoteSourceControl",
42+
"location" : "https://github.com/apple/swift-argument-parser",
43+
"state" : {
44+
"revision" : "46989693916f56d1186bd59ac15124caef896560",
45+
"version" : "1.3.1"
46+
}
47+
},
48+
{
49+
"identity" : "swift-llbuild",
50+
"kind" : "remoteSourceControl",
51+
"location" : "https://github.com/apple/swift-llbuild.git",
52+
"state" : {
53+
"revision" : "fb7ebf0b06c0d7c45ca8e18b3371424503a38b5c",
54+
"version" : "0.3.0"
55+
}
56+
},
57+
{
58+
"identity" : "swift-log",
59+
"kind" : "remoteSourceControl",
60+
"location" : "https://github.com/apple/swift-log.git",
61+
"state" : {
62+
"revision" : "e97a6fcb1ab07462881ac165fdbb37f067e205d5",
63+
"version" : "1.5.4"
64+
}
65+
},
66+
{
67+
"identity" : "swift-numerics",
68+
"kind" : "remoteSourceControl",
69+
"location" : "https://github.com/apple/swift-numerics.git",
70+
"state" : {
71+
"revision" : "0a5bc04095a675662cf24757cc0640aa2204253b",
72+
"version" : "1.0.2"
73+
}
74+
},
75+
{
76+
"identity" : "swift-package-manager",
77+
"kind" : "remoteSourceControl",
78+
"location" : "https://github.com/apple/swift-package-manager",
79+
"state" : {
80+
"revision" : "f5ea3972d7d6c574e8bb16a19b2a7bca98ea131b",
81+
"version" : "0.6.0"
82+
}
83+
},
84+
{
85+
"identity" : "swift-tools-support-core",
86+
"kind" : "remoteSourceControl",
87+
"location" : "https://github.com/apple/swift-tools-support-core.git",
88+
"state" : {
89+
"revision" : "98a5916a811fcaaed770f1ed812e9405be762945",
90+
"version" : "0.1.0"
91+
}
92+
}
93+
],
94+
"version" : 2
95+
}

AWSSDKSwiftCLI/Package.swift

+36-3
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,61 @@ import PackageDescription
55
let package = Package(
66
name: "AWSSDKSwiftCLI",
77
platforms: [
8-
.macOS(.v10_15)
8+
.macOS(.v13)
99
],
1010
dependencies: [
1111
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.2.0"),
1212
.package(url: "https://github.com/apple/swift-package-manager", from: "0.6.0"),
1313
.package(url: "https://github.com/apple/swift-algorithms", from: "1.0.0"),
1414
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
15+
.package(url: "https://github.com/awslabs/aws-sdk-swift", from: "0.46.0"),
1516
],
1617
targets: [
1718
.executableTarget(
1819
name: "AWSSDKSwiftCLI",
1920
dependencies: [
21+
"AWSCLIUtils",
2022
.product(name: "ArgumentParser", package: "swift-argument-parser"),
21-
.product(name: "PackageDescription", package: "swift-package-manager"),
2223
.product(name: "Algorithms", package: "swift-algorithms"),
23-
.product(name: "Logging", package: "swift-log"),
2424
],
2525
resources: [
2626
.process("Resources/Package.Base.swift"),
2727
.process("Resources/DocIndex.Base.md")
2828
]
2929
),
30+
.executableTarget(
31+
name: "spr-publish",
32+
dependencies: [
33+
"SPR",
34+
"AWSCLIUtils",
35+
.product(name: "ArgumentParser", package: "swift-argument-parser"),
36+
]
37+
),
38+
.executableTarget(
39+
name: "spr-multi-publish",
40+
dependencies: [
41+
"SPR",
42+
"AWSCLIUtils",
43+
"spr-publish",
44+
]
45+
),
46+
.target(
47+
name: "SPR",
48+
dependencies: [
49+
"AWSCLIUtils",
50+
.product(name: "ArgumentParser", package: "swift-argument-parser"),
51+
.product(name: "AWSS3", package: "aws-sdk-swift"),
52+
.product(name: "AWSCloudFront", package: "aws-sdk-swift"),
53+
]
54+
),
55+
.target(
56+
name: "AWSCLIUtils",
57+
dependencies: [
58+
.product(name: "ArgumentParser", package: "swift-argument-parser"),
59+
.product(name: "Logging", package: "swift-log"),
60+
.product(name: "PackageDescription", package: "swift-package-manager"),
61+
]
62+
),
3063
.testTarget(
3164
name: "AWSSDKSwiftCLITests",
3265
dependencies: ["AWSSDKSwiftCLI"]

AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Models/Error.swift AWSSDKSwiftCLI/Sources/AWSCLIUtils/Error.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
import Foundation
99

10-
struct Error: LocalizedError {
11-
var message: String
12-
var errorDescription: String? { message }
13-
14-
init(_ message: String) {
10+
public struct Error: LocalizedError {
11+
public var message: String
12+
public var errorDescription: String? { message }
13+
14+
public init(_ message: String) {
1515
self.message = message
1616
}
1717
}

AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Utils/FileManager+Utils.swift AWSSDKSwiftCLI/Sources/AWSCLIUtils/FileManager+Utils.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import Foundation
99

10-
extension FileManager {
10+
public extension FileManager {
1111
/// Changes the working directory to the provided path
1212
func changeWorkingDirectory(_ path: String) throws {
1313
log("Changing working directory to: \(path)")

AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Models/Logger.swift AWSSDKSwiftCLI/Sources/AWSCLIUtils/Logger.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import Logging
1010
struct Logger {
1111
static let standard = Logging.Logger(
1212
label: "com.aws.sdk.swift.cli",
13-
factory: { StreamLogHandler.standardOutput(label: $0) }
13+
factory: {
14+
var logger = StreamLogHandler.standardOutput(label: $0)
15+
logger.logLevel = .info
16+
return logger
17+
}
1418
)
1519
}
1620

AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Utils/Process+Git.swift AWSSDKSwiftCLI/Sources/AWSCLIUtils/Process+Git.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Foundation
99
import PackageDescription
1010
import struct ArgumentParser.ExitCode
1111

12-
extension Process {
12+
public extension Process {
1313
/// A struct to create processes for executing git commands.
1414
struct Git {
1515
/// Returns a process for executing git commands.
@@ -18,31 +18,31 @@ extension Process {
1818
}
1919

2020
/// Returns a process for executing `git status`
21-
func status() -> Process {
21+
public func status() -> Process {
2222
gitProcess(["status"])
2323
}
2424

2525
/// Returns a process for executing `git diff <a>..<b> --quiet`
2626
/// This is used for determining if `<a>` is different from `<b>` and therefore
27-
func diff(_ a: String, _ b: String) -> Process {
27+
public func diff(_ a: String, _ b: String) -> Process {
2828
gitProcess(["diff", "\(a)..\(b)", "--quiet"])
2929
}
3030

3131
/// Returns a process for executing `git add <args>`
3232
/// This is used for staging specific files.
33-
func add(_ files: [String]) -> Process {
33+
public func add(_ files: [String]) -> Process {
3434
gitProcess(["add"] + files)
3535
}
3636

3737
/// Returns a process for executing `git commit -m <message>`
3838
/// This is used for committing changes with the provided message
39-
func commit(_ message: String) -> Process {
39+
public func commit(_ message: String) -> Process {
4040
gitProcess(["commit", "-m", message])
4141
}
4242

4343
/// Returns a process for executing `git tag -a <version> -m <message>`
4444
/// This is used for creating a tag with the provided version and message.
45-
func tag(_ version: Version, _ message: String) -> Process {
45+
public func tag(_ version: Version, _ message: String) -> Process {
4646
gitProcess(["tag", "-a", "\(version)", "-m", message])
4747
}
4848

@@ -69,7 +69,7 @@ extension Process {
6969
static var git: Git { Git() }
7070
}
7171

72-
extension Process.Git {
72+
public extension Process.Git {
7373
/// Returns true if the provided commits/branches/trees are different, otherwise returns false
7474
func diffHasChanges(_ a: String, _ b: String) throws -> Bool {
7575
let task = diff(a, b)

AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Utils/Process+Swift.swift AWSSDKSwiftCLI/Sources/AWSCLIUtils/Process+Swift.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
import Foundation
99
import PackageDescription
1010

11-
extension Process {
11+
public extension Process {
1212
struct Swift {
1313
/// Returns a process for executing swift commands.
1414
private func swiftProcess(_ args: [String]) -> Process {
1515
Process(["swift"] + args)
1616
}
1717

1818
/// Returns a process for executing `swift test`
19-
func test() -> Process {
19+
public func test() -> Process {
2020
swiftProcess(["test"])
2121
}
2222
}

AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Utils/Process+Utils.swift AWSSDKSwiftCLI/Sources/AWSCLIUtils/Process+Utils.swift

+15-14
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import Foundation
99
import ArgumentParser
1010

11-
extension Process {
11+
public extension Process {
1212
/// Creates a process using `/usr/bin/env` as the executable
1313
/// This makes it easy to create a process for any command, as long as the corresponding executable exists in the PATH.
1414
///
@@ -29,14 +29,14 @@ extension Process {
2929

3030
/// Returns the executable and arguments combined as a string
3131
var commandString: String {
32-
let items = [executableURL?.path] + (arguments ?? [])
32+
let items = [urlPath(executableURL)] + (arguments ?? [])
3333
return items
3434
.compactMap { $0 }
3535
.joined(separator: " ")
3636
}
3737
}
3838

39-
func _run(_ process: Process) throws {
39+
public func _run(_ process: Process) throws {
4040
// If debug and we have a non-nil test runner, then use that
4141
// This allows developers to intercept processes when they run to assert that it is the expected process
4242
#if DEBUG
@@ -48,30 +48,31 @@ func _run(_ process: Process) throws {
4848
try ProcessRunner.standard.run(process)
4949
}
5050

51-
func _runReturningStdOut(_ process: Process) throws -> String? {
51+
public func _runReturningStdOut(_ process: Process) throws -> String? {
5252
let stdOut = Pipe()
5353
process.standardOutput = stdOut
5454

55-
var data = Data()
56-
stdOut.fileHandleForReading.readabilityHandler = { handle in
57-
data += handle.availableData
58-
}
59-
6055
try _run(process)
6156
process.waitUntilExit()
6257

58+
let data = try stdOut.fileHandleForReading.readToEnd() ?? Data()
6359
return String(data: data, encoding: .utf8)
6460
}
6561

6662
/// A simple struct that runs a process
67-
struct ProcessRunner {
68-
let run: (Process) throws -> Void
63+
public struct ProcessRunner {
64+
65+
public init(_ run: @escaping (Process) throws -> Void) {
66+
self.run = run
67+
}
68+
69+
public let run: (Process) throws -> Void
6970

7071
/// Creates the standard runner to be used by the release version of this CLI
7172
///
7273
/// Runs the process and prints out the process's full command.
73-
static let standard = ProcessRunner { process in
74-
log("Running process: \(process.commandString)")
74+
public static let standard = ProcessRunner { process in
75+
log(level: .debug, "Running process: \(process.commandString)")
7576
try process.run()
7677
process.waitUntilExit()
7778
let exitCode = ExitCode(process.terminationStatus)
@@ -82,6 +83,6 @@ struct ProcessRunner {
8283

8384
#if DEBUG
8485
// Set this to a non-nil value in tests to intercept when a process is run
85-
static var testRunner: ProcessRunner? = nil
86+
public static var testRunner: ProcessRunner? = nil
8687
#endif
8788
}

AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Utils/String+Utils.swift AWSSDKSwiftCLI/Sources/AWSCLIUtils/String+Utils.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import Foundation
99

10-
extension String {
10+
public extension String {
1111
/// Returns the receiver wrapped in the provided string
1212
///
1313
/// ```swift
@@ -37,3 +37,9 @@ extension String {
3737
/// Returns the string that represents a newline
3838
static var newline: Self { "\n" }
3939
}
40+
41+
public func printError(_ items: Any..., separator: String = " ", terminator: String = "\n") throws {
42+
var s = ""
43+
print(items, separator: separator, terminator: terminator, to: &s)
44+
try FileHandle.standardError.write(contentsOf: Data(s.utf8))
45+
}

0 commit comments

Comments
 (0)