From 4dc1234b3fcc851cc23c833c09d3e8c12f61a1f4 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Tue, 14 Jan 2025 11:42:41 -0600 Subject: [PATCH] feat: Generate package manifest for preview builds (#1863) --- .gitignore | 3 + .../Subcommands/GeneratePackageManifest.swift | 17 +++-- .../AWSSDKSwiftCLI/Models/Features.swift | 2 +- .../Models/PackageManifestBuilder.swift | 14 +++- .../Models/ReleaseNotesBuilder.swift | 4 +- .../AWSSDKSwiftCLI/Resources/Package.Base.txt | 11 ++- .../GeneratePackageManifestTests.swift | 2 + .../Models/PackageManifestBuilderTests.swift | 72 ++++++++++++++----- Package.swift | 13 +++- 9 files changed, 110 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index d8974287bdd..f6bb478cbe1 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,9 @@ codegen/protocol-test-codegen-local/smithy-build.json codegen/protocol-test-codegen/smithy-build.json SmokeTests/ +# Preview embedded dependencies +/smithy-swift/ + # vim temporary files *.swp diff --git a/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Commands/AWSSDKSwiftCLI/Subcommands/GeneratePackageManifest.swift b/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Commands/AWSSDKSwiftCLI/Subcommands/GeneratePackageManifest.swift index 376b0cf8c36..6e566becf5c 100644 --- a/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Commands/AWSSDKSwiftCLI/Subcommands/GeneratePackageManifest.swift +++ b/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Commands/AWSSDKSwiftCLI/Subcommands/GeneratePackageManifest.swift @@ -35,6 +35,9 @@ 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 + func run() throws { let generatePackageManifest = GeneratePackageManifest.standard( repoPath: repoPath, @@ -42,7 +45,8 @@ struct GeneratePackageManifestCommand: ParsableCommand { 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,7 +205,8 @@ extension GeneratePackageManifest { crtVersion: Version? = nil, services: [String]? = nil, excludeAWSServices: Bool = false, - excludeRuntimeTests: Bool = false + excludeRuntimeTests: Bool = false, + previewBuild: Bool = false ) -> Self { GeneratePackageManifest( repoPath: repoPath, @@ -207,13 +214,15 @@ extension GeneratePackageManifest { 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() } diff --git a/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Models/Features.swift b/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Models/Features.swift index 4040a9816a5..275708ba0bc 100644 --- a/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Models/Features.swift +++ b/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Models/Features.swift @@ -25,7 +25,7 @@ struct FeaturesReader { } struct Features: Decodable { - let features: [Feature] + let features: [Feature]? } struct Feature: Decodable { diff --git a/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Models/PackageManifestBuilder.swift b/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Models/PackageManifestBuilder.swift index a8a8ba68936..409305d0537 100644 --- a/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Models/PackageManifestBuilder.swift +++ b/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Models/PackageManifestBuilder.swift @@ -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,6 +27,7 @@ struct PackageManifestBuilder { crtVersion: Version, services: [Service], excludeRuntimeTests: Bool, + previewBuild: Bool, prefixContents: @escaping () throws -> String, basePackageContents: @escaping () throws -> String ) { @@ -33,6 +35,7 @@ struct PackageManifestBuilder { 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)" + } + /// 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. diff --git a/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Models/ReleaseNotesBuilder.swift b/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Models/ReleaseNotesBuilder.swift index b2a6f9a32b6..36afb12bfdd 100644 --- a/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Models/ReleaseNotesBuilder.swift +++ b/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Models/ReleaseNotesBuilder.swift @@ -49,7 +49,7 @@ struct ReleaseNotesBuilder { _ features: Features, _ mapping: [String: String] ) -> [String] { - let formattedFeatures = features.features + let formattedFeatures = (features.features ?? []) .filter { $0.featureMetadata.trebuchet.featureType == "NEW_FEATURE" } .map { "* **AWS \(mapping[$0.featureMetadata.trebuchet.featureId]!)**: \($0.releaseNotes ?? "No description provided.")" } .joined(separator: .newline) @@ -63,7 +63,7 @@ struct ReleaseNotesBuilder { _ features: Features, _ mapping: [String: String] ) -> [String] { - let formattedDocUpdates = features.features + let formattedDocUpdates = (features.features ?? []) .filter { $0.featureMetadata.trebuchet.featureType == "DOC_UPDATE" } .map { "* **AWS \(mapping[$0.featureMetadata.trebuchet.featureId]!)**: \($0.releaseNotes ?? "No description provided.")" } .joined(separator: .newline) diff --git a/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Resources/Package.Base.txt b/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Resources/Package.Base.txt index 56028fa8da4..d28889b57d3 100644 --- a/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Resources/Package.Base.txt +++ b/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Resources/Package.Base.txt @@ -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) + } } private var crtDependency: Package.Dependency { diff --git a/AWSSDKSwiftCLI/Tests/AWSSDKSwiftCLITests/Commands/GeneratePackageManifestTests.swift b/AWSSDKSwiftCLI/Tests/AWSSDKSwiftCLITests/Commands/GeneratePackageManifestTests.swift index a0bc5b4cb02..9cc3de861c0 100644 --- a/AWSSDKSwiftCLI/Tests/AWSSDKSwiftCLITests/Commands/GeneratePackageManifestTests.swift +++ b/AWSSDKSwiftCLI/Tests/AWSSDKSwiftCLITests/Commands/GeneratePackageManifestTests.swift @@ -115,6 +115,7 @@ extension GeneratePackageManifest { crtVersion: Version? = nil, services: [String]? = nil, excludeRuntimeTests: Bool = false, + previewBuild: Bool = false, buildPackageManifest: @escaping BuildPackageManifest = { (_,_,_) throws -> String in "" } ) -> GeneratePackageManifest { GeneratePackageManifest( @@ -124,6 +125,7 @@ extension GeneratePackageManifest { crtVersion: crtVersion, services: services, excludeRuntimeTests: excludeRuntimeTests, + previewBuild: previewBuild, buildPackageManifest: buildPackageManifest ) } diff --git a/AWSSDKSwiftCLI/Tests/AWSSDKSwiftCLITests/Models/PackageManifestBuilderTests.swift b/AWSSDKSwiftCLI/Tests/AWSSDKSwiftCLITests/Models/PackageManifestBuilderTests.swift index ecb12da89a5..69f7727e8eb 100644 --- a/AWSSDKSwiftCLI/Tests/AWSSDKSwiftCLITests/Models/PackageManifestBuilderTests.swift +++ b/AWSSDKSwiftCLI/Tests/AWSSDKSwiftCLITests/Models/PackageManifestBuilderTests.swift @@ -10,32 +10,72 @@ import XCTest class PackageManifestBuilderTests: XCTestCase { - let expected = """ - -// MARK: - Dynamic Content + func testBuildWithDefaults() throws { + let expected = """ + + // 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 - -""" + let serviceTargets: [String] = [ + "A", + "B", + "C", + "D", + "E", + ] - func testBuild() throws { + + """ 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: { "" }, + basePackageContents: { "" } + ) + let result = try! subject.build() + print("") + print(result) + print("") + XCTAssertEqual(result, expected) + } + + func testBuildWithPreviewBuildAndExcludedTests() throws { + let expected = """ + + // 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", + ] + + + """ + 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: { "" }, basePackageContents: { "" } ) diff --git a/Package.swift b/Package.swift index 52cd245e948..a910d6fa8c7 100644 --- a/Package.swift +++ b/Package.swift @@ -20,6 +20,8 @@ let crtVersion: Version = "0.43.0" 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 {