-
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
feat: Generate package manifest for preview builds #1863
Changes from 3 commits
0697fdb
7f0c4a8
cb79921
e35434d
fbf0dea
a1e6657
c12cc49
f154b7a
fc726b0
ba17ef1
ca6ce6a
e780066
6ee263a
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 |
---|---|---|
|
@@ -35,14 +35,18 @@ struct GeneratePackageManifestCommand: ParsableCommand { | |
@Flag(help: "If the package manifest should exclude runtime tests.") | ||
var excludeRuntimeTests = false | ||
|
||
@Flag(help: "If the package manifest should be configured for a preview build.") | ||
var previewBuild = false | ||
|
||
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 CLI flag that is being added. Note it defaults to false, which renders a manifest with current behavior. |
||
func run() throws { | ||
let generatePackageManifest = GeneratePackageManifest.standard( | ||
repoPath: repoPath, | ||
packageFileName: packageFileName, | ||
clientRuntimeVersion: clientRuntimeVersion, | ||
crtVersion: crtVersion, | ||
services: services.isEmpty ? nil : services, | ||
excludeRuntimeTests: excludeRuntimeTests | ||
excludeRuntimeTests: excludeRuntimeTests, | ||
previewBuild: previewBuild | ||
) | ||
try generatePackageManifest.run() | ||
} | ||
|
@@ -67,6 +71,8 @@ struct GeneratePackageManifest { | |
let services: [String]? | ||
/// If the package manifest should exclude runtime unit tests. | ||
let excludeRuntimeTests: Bool | ||
/// If the package manifest should be configured for a preview build. | ||
let previewBuild: Bool | ||
|
||
typealias BuildPackageManifest = ( | ||
_ clientRuntimeVersion: Version, | ||
|
@@ -199,21 +205,24 @@ extension GeneratePackageManifest { | |
crtVersion: Version? = nil, | ||
services: [String]? = nil, | ||
excludeAWSServices: Bool = false, | ||
excludeRuntimeTests: Bool = false | ||
excludeRuntimeTests: Bool = false, | ||
previewBuild: Bool = false | ||
) -> Self { | ||
GeneratePackageManifest( | ||
repoPath: repoPath, | ||
packageFileName: packageFileName, | ||
clientRuntimeVersion: clientRuntimeVersion, | ||
crtVersion: crtVersion, | ||
services: services, | ||
excludeRuntimeTests: excludeRuntimeTests | ||
excludeRuntimeTests: excludeRuntimeTests, | ||
previewBuild: previewBuild | ||
) { _clientRuntimeVersion, _crtVersion, _services in | ||
let builder = PackageManifestBuilder( | ||
clientRuntimeVersion: _clientRuntimeVersion, | ||
crtVersion: _crtVersion, | ||
services: _services, | ||
excludeRuntimeTests: excludeRuntimeTests | ||
excludeRuntimeTests: excludeRuntimeTests, | ||
previewBuild: previewBuild | ||
) | ||
return try builder.build() | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ struct PackageManifestBuilder { | |
let crtVersion: Version | ||
let services: [Service] | ||
let excludeRuntimeTests: Bool | ||
let previewBuild: Bool | ||
let prefixContents: () throws -> String | ||
let basePackageContents: () throws -> String | ||
|
||
|
@@ -26,13 +27,15 @@ struct PackageManifestBuilder { | |
crtVersion: Version, | ||
services: [Service], | ||
excludeRuntimeTests: Bool, | ||
previewBuild: Bool, | ||
prefixContents: @escaping () throws -> String, | ||
basePackageContents: @escaping () throws -> String | ||
) { | ||
self.clientRuntimeVersion = clientRuntimeVersion | ||
self.crtVersion = crtVersion | ||
self.services = services | ||
self.excludeRuntimeTests = excludeRuntimeTests | ||
self.previewBuild = previewBuild | ||
self.prefixContents = prefixContents | ||
self.basePackageContents = basePackageContents | ||
} | ||
|
@@ -41,13 +44,15 @@ struct PackageManifestBuilder { | |
clientRuntimeVersion: Version, | ||
crtVersion: Version, | ||
services: [Service], | ||
excludeRuntimeTests: Bool | ||
excludeRuntimeTests: Bool, | ||
previewBuild: Bool | ||
) { | ||
self.init( | ||
clientRuntimeVersion: clientRuntimeVersion, | ||
crtVersion: crtVersion, | ||
services: services, | ||
excludeRuntimeTests: excludeRuntimeTests, | ||
previewBuild: previewBuild, | ||
prefixContents: Self.contentReader(filename: "Package.Prefix"), | ||
basePackageContents: Self.contentReader(filename: "Package.Base") | ||
) | ||
|
@@ -96,6 +101,9 @@ struct PackageManifestBuilder { | |
// Remove the runtime tests if needed | ||
buildRuntimeTests(), | ||
"", | ||
// Configure for preview or regular build | ||
buildPreviewFlag(), | ||
"", | ||
// Add the generated content that defines the list of services to include | ||
buildServiceTargets(), | ||
"", | ||
|
@@ -123,6 +131,10 @@ struct PackageManifestBuilder { | |
"let excludeRuntimeUnitTests = \(excludeRuntimeTests)" | ||
} | ||
|
||
private func buildPreviewFlag() -> String { | ||
"let isPreviewBuild = \(previewBuild)" | ||
} | ||
|
||
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 boolean variable is rendered into the |
||
/// Builds the list of services to include. | ||
/// This generates an array of strings, where the each item is a name of a service | ||
/// and calls the `addServiceTarget` for each item. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,10 +69,17 @@ private func productForService(_ service: String) -> Product { | |
// MARK: Dependencies | ||
|
||
private var clientRuntimeDependency: Package.Dependency { | ||
let path = "../smithy-swift" | ||
let previewPath = "./smithy-swift" | ||
let developmentPath = "../smithy-swift" | ||
let gitURL = "https://github.com/smithy-lang/smithy-swift" | ||
let useLocalDeps = ProcessInfo.processInfo.environment["AWS_SWIFT_SDK_USE_LOCAL_DEPS"] != nil | ||
return useLocalDeps ? .package(path: path) : .package(url: gitURL, exact: clientRuntimeVersion) | ||
if isPreviewBuild { | ||
return .package(path: previewPath) | ||
} else if useLocalDeps { | ||
return .package(path: developmentPath) | ||
} else { | ||
return .package(url: gitURL, exact: clientRuntimeVersion) | ||
} | ||
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. If Otherwise, the |
||
} | ||
|
||
private var crtDependency: Package.Dependency { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,32 +10,72 @@ import XCTest | |
|
||
class PackageManifestBuilderTests: XCTestCase { | ||
|
||
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, manifest generator tests are added/modified for the new flag. |
||
let expected = """ | ||
<contents of prefix> | ||
// MARK: - Dynamic Content | ||
func testBuildWithDefaults() throws { | ||
let expected = """ | ||
<contents of prefix> | ||
// MARK: - Dynamic Content | ||
|
||
let clientRuntimeVersion: Version = "1.2.3" | ||
let crtVersion: Version = "4.5.6" | ||
let clientRuntimeVersion: Version = "1.2.3" | ||
let crtVersion: Version = "4.5.6" | ||
|
||
let excludeRuntimeUnitTests = false | ||
let excludeRuntimeUnitTests = false | ||
|
||
let serviceTargets: [String] = [ | ||
"A", | ||
"B", | ||
"C", | ||
"D", | ||
"E", | ||
] | ||
let isPreviewBuild = false | ||
|
||
<contents of base package> | ||
""" | ||
let serviceTargets: [String] = [ | ||
"A", | ||
"B", | ||
"C", | ||
"D", | ||
"E", | ||
] | ||
|
||
func testBuild() throws { | ||
<contents of base package> | ||
""" | ||
let subject = try PackageManifestBuilder( | ||
clientRuntimeVersion: .init("1.2.3"), | ||
crtVersion: .init("4.5.6"), | ||
services: ["A","B","C","D","E"].map { PackageManifestBuilder.Service(name: $0) }, | ||
excludeRuntimeTests: false, | ||
previewBuild: false, | ||
prefixContents: { "<contents of prefix>" }, | ||
basePackageContents: { "<contents of base package>" } | ||
) | ||
let result = try! subject.build() | ||
print("") | ||
print(result) | ||
print("") | ||
XCTAssertEqual(result, expected) | ||
} | ||
|
||
func testBuildWithPreviewBuildAndExcludedTests() throws { | ||
let expected = """ | ||
<contents of prefix> | ||
// MARK: - Dynamic Content | ||
|
||
let clientRuntimeVersion: Version = "1.2.3" | ||
let crtVersion: Version = "4.5.6" | ||
|
||
let excludeRuntimeUnitTests = true | ||
|
||
let isPreviewBuild = true | ||
|
||
let serviceTargets: [String] = [ | ||
"A", | ||
"B", | ||
"C", | ||
"D", | ||
"E", | ||
] | ||
|
||
<contents of base package> | ||
""" | ||
let subject = try PackageManifestBuilder( | ||
clientRuntimeVersion: .init("1.2.3"), | ||
crtVersion: .init("4.5.6"), | ||
services: ["A","B","C","D","E"].map { PackageManifestBuilder.Service(name: $0) }, | ||
excludeRuntimeTests: true, | ||
previewBuild: true, | ||
prefixContents: { "<contents of prefix>" }, | ||
basePackageContents: { "<contents of base package>" } | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ let crtVersion: Version = "0.43.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. Regenerated manifest with changes is below. |
||
let excludeRuntimeUnitTests = false | ||
|
||
let isPreviewBuild = false | ||
|
||
let serviceTargets: [String] = [ | ||
"AWSACM", | ||
"AWSACMPCA", | ||
|
@@ -496,10 +498,17 @@ private func productForService(_ service: String) -> Product { | |
// MARK: Dependencies | ||
|
||
private var clientRuntimeDependency: Package.Dependency { | ||
let path = "../smithy-swift" | ||
let previewPath = "./smithy-swift" | ||
let developmentPath = "../smithy-swift" | ||
let gitURL = "https://github.com/smithy-lang/smithy-swift" | ||
let useLocalDeps = ProcessInfo.processInfo.environment["AWS_SWIFT_SDK_USE_LOCAL_DEPS"] != nil | ||
return useLocalDeps ? .package(path: path) : .package(url: gitURL, exact: clientRuntimeVersion) | ||
if isPreviewBuild { | ||
return .package(path: previewPath) | ||
} else if useLocalDeps { | ||
return .package(path: developmentPath) | ||
} else { | ||
return .package(url: gitURL, exact: clientRuntimeVersion) | ||
} | ||
} | ||
|
||
private var crtDependency: Package.Dependency { | ||
|
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.
We'll be embedding
smithy-swift
in the SDK repo in preview build artifacts. This.gitignore
will make it so that if a preview customer wants to push their SDK up to Git,smithy-swift
won't get pushed with it.