-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add Swift Package Registry tools and config #1597
Changes from all commits
18c72f9
a5bf6fb
ab35029
ff8ec99
f301c24
6e1197c
abc6e16
71f8a11
071e733
7333369
70d5f30
91220cb
ddc9cc4
eb409a0
5266077
4db4cef
29a476d
9bd23a9
a559104
6eedca9
d0f7420
3aad806
8c825cc
8ab7558
1367871
63eb711
1bd0c35
7fc9342
7a873a3
9a6903b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
{ | ||
"pins" : [ | ||
{ | ||
"identity" : "aws-crt-swift", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/awslabs/aws-crt-swift", | ||
"state" : { | ||
"revision" : "b6380f683b31072d77b601c88674461c11bcad5a", | ||
"version" : "0.30.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "aws-sdk-swift", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/awslabs/aws-sdk-swift", | ||
"state" : { | ||
"revision" : "3c20e0be8c8246de8b8e04372404ef1f90be71b6", | ||
"version" : "0.46.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "smithy-swift", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/smithy-lang/smithy-swift", | ||
"state" : { | ||
"revision" : "b2322a067f85c230f17c80be8a67dd543454b081", | ||
"version" : "0.51.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-algorithms", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-algorithms", | ||
"state" : { | ||
"revision" : "f6919dfc309e7f1b56224378b11e28bab5bccc42", | ||
"version" : "1.2.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-argument-parser", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-argument-parser", | ||
"state" : { | ||
"revision" : "46989693916f56d1186bd59ac15124caef896560", | ||
"version" : "1.3.1" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-llbuild", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-llbuild.git", | ||
"state" : { | ||
"revision" : "fb7ebf0b06c0d7c45ca8e18b3371424503a38b5c", | ||
"version" : "0.3.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-log", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-log.git", | ||
"state" : { | ||
"revision" : "e97a6fcb1ab07462881ac165fdbb37f067e205d5", | ||
"version" : "1.5.4" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-numerics", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-numerics.git", | ||
"state" : { | ||
"revision" : "0a5bc04095a675662cf24757cc0640aa2204253b", | ||
"version" : "1.0.2" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-package-manager", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-package-manager", | ||
"state" : { | ||
"revision" : "f5ea3972d7d6c574e8bb16a19b2a7bca98ea131b", | ||
"version" : "0.6.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-tools-support-core", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-tools-support-core.git", | ||
"state" : { | ||
"revision" : "98a5916a811fcaaed770f1ed812e9405be762945", | ||
"version" : "0.1.0" | ||
} | ||
} | ||
], | ||
"version" : 2 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,28 +5,61 @@ import PackageDescription | |
let package = Package( | ||
name: "AWSSDKSwiftCLI", | ||
platforms: [ | ||
.macOS(.v10_15) | ||
.macOS(.v13) | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.2.0"), | ||
.package(url: "https://github.com/apple/swift-package-manager", from: "0.6.0"), | ||
.package(url: "https://github.com/apple/swift-algorithms", from: "1.0.0"), | ||
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"), | ||
.package(url: "https://github.com/awslabs/aws-sdk-swift", from: "0.46.0"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our own AWS SDK for Swift is added as a dependency so that it can be used to perform the S3 & Cloudfront operations needed for publishing to the Registry. |
||
], | ||
targets: [ | ||
.executableTarget( | ||
name: "AWSSDKSwiftCLI", | ||
dependencies: [ | ||
"AWSCLIUtils", | ||
.product(name: "ArgumentParser", package: "swift-argument-parser"), | ||
.product(name: "PackageDescription", package: "swift-package-manager"), | ||
.product(name: "Algorithms", package: "swift-algorithms"), | ||
.product(name: "Logging", package: "swift-log"), | ||
], | ||
resources: [ | ||
.process("Resources/Package.Base.swift"), | ||
.process("Resources/DocIndex.Base.md") | ||
] | ||
), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two new CLI commands are created, |
||
.executableTarget( | ||
name: "spr-publish", | ||
dependencies: [ | ||
"SPR", | ||
"AWSCLIUtils", | ||
.product(name: "ArgumentParser", package: "swift-argument-parser"), | ||
] | ||
), | ||
.executableTarget( | ||
name: "spr-multi-publish", | ||
dependencies: [ | ||
"SPR", | ||
"AWSCLIUtils", | ||
"spr-publish", | ||
] | ||
), | ||
.target( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
name: "SPR", | ||
dependencies: [ | ||
"AWSCLIUtils", | ||
.product(name: "ArgumentParser", package: "swift-argument-parser"), | ||
.product(name: "AWSS3", package: "aws-sdk-swift"), | ||
.product(name: "AWSCloudFront", package: "aws-sdk-swift"), | ||
] | ||
), | ||
.target( | ||
name: "AWSCLIUtils", | ||
dependencies: [ | ||
.product(name: "ArgumentParser", package: "swift-argument-parser"), | ||
.product(name: "Logging", package: "swift-log"), | ||
.product(name: "PackageDescription", package: "swift-package-manager"), | ||
] | ||
), | ||
.testTarget( | ||
name: "AWSSDKSwiftCLITests", | ||
dependencies: ["AWSSDKSwiftCLI"] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,11 @@ | |
|
||
import Foundation | ||
|
||
struct Error: LocalizedError { | ||
var message: String | ||
var errorDescription: String? { message } | ||
init(_ message: String) { | ||
public struct Error: LocalizedError { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As you will see below, many types like this one have been moved into AWSCLIUtils and been marked public, so that they can be shared between CLI utilities. |
||
public var message: String | ||
public var errorDescription: String? { message } | ||
|
||
public init(_ message: String) { | ||
self.message = message | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
import Foundation | ||
import ArgumentParser | ||
|
||
extension Process { | ||
public extension Process { | ||
/// Creates a process using `/usr/bin/env` as the executable | ||
/// This makes it easy to create a process for any command, as long as the corresponding executable exists in the PATH. | ||
/// | ||
|
@@ -29,14 +29,14 @@ extension Process { | |
|
||
/// Returns the executable and arguments combined as a string | ||
var commandString: String { | ||
let items = [executableURL?.path] + (arguments ?? []) | ||
let items = [urlPath(executableURL)] + (arguments ?? []) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As you will see below, Foundation |
||
return items | ||
.compactMap { $0 } | ||
.joined(separator: " ") | ||
} | ||
} | ||
|
||
func _run(_ process: Process) throws { | ||
public func _run(_ process: Process) throws { | ||
// If debug and we have a non-nil test runner, then use that | ||
// This allows developers to intercept processes when they run to assert that it is the expected process | ||
#if DEBUG | ||
|
@@ -48,30 +48,31 @@ func _run(_ process: Process) throws { | |
try ProcessRunner.standard.run(process) | ||
} | ||
|
||
func _runReturningStdOut(_ process: Process) throws -> String? { | ||
public func _runReturningStdOut(_ process: Process) throws -> String? { | ||
let stdOut = Pipe() | ||
process.standardOutput = stdOut | ||
|
||
var data = Data() | ||
stdOut.fileHandleForReading.readabilityHandler = { handle in | ||
data += handle.availableData | ||
} | ||
|
||
try _run(process) | ||
process.waitUntilExit() | ||
|
||
let data = try stdOut.fileHandleForReading.readToEnd() ?? Data() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
return String(data: data, encoding: .utf8) | ||
} | ||
|
||
/// A simple struct that runs a process | ||
struct ProcessRunner { | ||
let run: (Process) throws -> Void | ||
public struct ProcessRunner { | ||
|
||
public init(_ run: @escaping (Process) throws -> Void) { | ||
self.run = run | ||
} | ||
|
||
public let run: (Process) throws -> Void | ||
|
||
/// Creates the standard runner to be used by the release version of this CLI | ||
/// | ||
/// Runs the process and prints out the process's full command. | ||
static let standard = ProcessRunner { process in | ||
log("Running process: \(process.commandString)") | ||
public static let standard = ProcessRunner { process in | ||
log(level: .debug, "Running process: \(process.commandString)") | ||
try process.run() | ||
process.waitUntilExit() | ||
let exitCode = ExitCode(process.terminationStatus) | ||
|
@@ -82,6 +83,6 @@ struct ProcessRunner { | |
|
||
#if DEBUG | ||
// Set this to a non-nil value in tests to intercept when a process is run | ||
static var testRunner: ProcessRunner? = nil | ||
public static var testRunner: ProcessRunner? = nil | ||
#endif | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
|
||
import Foundation | ||
|
||
extension String { | ||
public extension String { | ||
/// Returns the receiver wrapped in the provided string | ||
/// | ||
/// ```swift | ||
|
@@ -37,3 +37,9 @@ extension String { | |
/// Returns the string that represents a newline | ||
static var newline: Self { "\n" } | ||
} | ||
|
||
public func printError(_ items: Any..., separator: String = " ", terminator: String = "\n") throws { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A simple free function that acts like a |
||
var s = "" | ||
print(items, separator: separator, terminator: terminator, to: &s) | ||
try FileHandle.standardError.write(contentsOf: Data(s.utf8)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is committed so that when we run the command line tools, we all get the same versions of dependencies until we choose to update them.