-
Notifications
You must be signed in to change notification settings - Fork 81
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
fix: Replace SwiftPM dependency with local Version type #1684
Changes from all commits
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 |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
// | ||
|
||
import Foundation | ||
import PackageDescription | ||
|
||
public extension Process { | ||
struct Swift { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,14 @@ public func _run(_ process: Process) throws { | |
} | ||
|
||
public func _runReturningStdOut(_ process: Process) throws -> String? { | ||
// 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 | ||
if let testRunner = ProcessRunner.testRunner { | ||
try testRunner.run(process) | ||
return nil | ||
} | ||
#endif | ||
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. Adding this code fixes this process runner so that it can be mocked with a test runner. Note that when the behavior is mocked, the returned output is |
||
let stdOut = Pipe() | ||
process.standardOutput = stdOut | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,15 +7,46 @@ | |
|
||
import Foundation | ||
import ArgumentParser | ||
import PackageDescription | ||
|
||
// MARK: - Decodable | ||
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 struct below replaces the one that was previously imported from the |
||
public struct Version: Equatable { | ||
public let major: Int | ||
public let minor: Int | ||
public let patch: Int | ||
|
||
private var versionString: String { "\(major).\(minor).\(patch)" } | ||
|
||
init(_ major: Int, _ minor: Int, _ patch: Int) { | ||
self.major = major | ||
self.minor = minor | ||
self.patch = patch | ||
} | ||
|
||
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. Note that creating a |
||
public init(_ value: String) throws { | ||
let components = value.split(separator: ".") | ||
guard components.count == 3 else { | ||
throw Error("Version does not have three components") | ||
} | ||
guard let major = Int(components[0]), let minor = Int(components[1]), let patch = Int(components[2]) else { | ||
throw Error("Version components are not all Int") | ||
} | ||
self.init(major, minor, patch) | ||
} | ||
} | ||
|
||
extension Version: CustomStringConvertible { | ||
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. Like the previous |
||
public var description: String { versionString } | ||
} | ||
|
||
// MARK: - Codable | ||
|
||
extension Version: Codable { | ||
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.
|
||
|
||
extension Version: Decodable { | ||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.singleValueContainer() | ||
let value = try container.decode(String.self) | ||
self.init(stringLiteral: value) | ||
try self.init(try String(from: decoder)) | ||
} | ||
|
||
public func encode(to encoder: any Encoder) throws { | ||
try versionString.encode(to: encoder) | ||
} | ||
} | ||
|
||
|
@@ -37,11 +68,7 @@ public extension Version { | |
|
||
let normalizedVersionString = versionString.trimmingCharacters(in: .whitespacesAndNewlines) | ||
|
||
guard let version = Version.init(normalizedVersionString) else { | ||
throw Error("Failed to parse version from string \(normalizedVersionString)") | ||
} | ||
|
||
return version | ||
return try Version(normalizedVersionString) | ||
} | ||
} | ||
|
||
|
@@ -55,9 +82,7 @@ public extension Version { | |
Version( | ||
self.major + 1, | ||
0, | ||
0, | ||
prereleaseIdentifiers: prereleaseIdentifiers, | ||
buildMetadataIdentifiers: buildMetadataIdentifiers | ||
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. Prerelease & build metadata identifiers are removed, since our project does not use them. |
||
) | ||
} | ||
|
||
|
@@ -68,9 +93,7 @@ public extension Version { | |
Version( | ||
self.major, | ||
self.minor + 1, | ||
0, | ||
prereleaseIdentifiers: prereleaseIdentifiers, | ||
buildMetadataIdentifiers: buildMetadataIdentifiers | ||
0 | ||
) | ||
} | ||
|
||
|
@@ -81,17 +104,16 @@ public extension Version { | |
Version( | ||
self.major, | ||
self.minor, | ||
self.patch + 1, | ||
prereleaseIdentifiers: prereleaseIdentifiers, | ||
buildMetadataIdentifiers: buildMetadataIdentifiers | ||
self.patch + 1 | ||
) | ||
} | ||
} | ||
|
||
// MARK: - ExpressibleByArgument | ||
|
||
extension Version: ExpressibleByArgument { | ||
|
||
public init?(argument: String) { | ||
self.init(argument) | ||
try? self.init(argument) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
// | ||
|
||
import Foundation | ||
import PackageDescription | ||
|
||
struct ReleaseManifest: Codable { | ||
let name: String | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
// | ||
|
||
import Foundation | ||
import PackageDescription | ||
import AWSCLIUtils | ||
|
||
// Builds the release notes | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
// | ||
|
||
@testable import AWSSDKSwiftCLI | ||
import PackageDescription | ||
import AWSCLIUtils | ||
import XCTest | ||
|
||
class GeneratePackageManifestTests: CLITestCase { | ||
|
@@ -16,10 +16,10 @@ class GeneratePackageManifestTests: CLITestCase { | |
func createPackageDependencies( | ||
crtVersion: String, | ||
clientRuntimeVersion: String | ||
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. Below, many tests have been marked with |
||
) { | ||
let packageDependencies = PackageDependencies( | ||
awsCRTSwiftVersion: .init(crtVersion)!, | ||
clientRuntimeVersion: .init(clientRuntimeVersion)! | ||
) throws { | ||
let packageDependencies = try PackageDependencies( | ||
awsCRTSwiftVersion: .init(crtVersion), | ||
clientRuntimeVersion: .init(clientRuntimeVersion) | ||
) | ||
try! packageDependencies.save() | ||
} | ||
|
@@ -41,11 +41,11 @@ class GeneratePackageManifestTests: CLITestCase { | |
|
||
// MARK: Golden Path | ||
|
||
func testGoldenPath() { | ||
func testGoldenPath() throws { | ||
let clientRuntimeVersion = "1.2.3" | ||
let crtVersion = "3.2.1" | ||
let services = ["EC2", "S3"] | ||
createPackageDependencies( | ||
try createPackageDependencies( | ||
crtVersion: crtVersion, | ||
clientRuntimeVersion: clientRuntimeVersion | ||
) | ||
|
@@ -61,10 +61,10 @@ class GeneratePackageManifestTests: CLITestCase { | |
|
||
// MARK: resolveVersions() | ||
|
||
func testResolveVersionsRetrievesVersionsFromPackageDependencies() { | ||
func testResolveVersionsRetrievesVersionsFromPackageDependencies() throws { | ||
let clientRuntimeVersion = "1.2.3" | ||
let crtVersion = "3.2.1" | ||
createPackageDependencies( | ||
try createPackageDependencies( | ||
crtVersion: crtVersion, | ||
clientRuntimeVersion: clientRuntimeVersion | ||
) | ||
|
@@ -74,10 +74,10 @@ class GeneratePackageManifestTests: CLITestCase { | |
XCTAssertEqual(versions.crt.description, crtVersion) | ||
} | ||
|
||
func testResolveVersionsWithExplicitVersions() { | ||
func testResolveVersionsWithExplicitVersions() throws { | ||
let clientRuntimeVersion = "1.2.3" | ||
let crtVersion = "3.2.1" | ||
let subject = GeneratePackageManifest.mock( | ||
let subject = try GeneratePackageManifest.mock( | ||
clientRuntimeVersion: .init(clientRuntimeVersion), | ||
crtVersion: .init(crtVersion) | ||
) | ||
|
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.
Bye bye, useless dependencies