Skip to content

Commit

Permalink
feat: Generate package manifest for preview builds (#1863)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbelkins authored Jan 14, 2025
1 parent 9a590d6 commit 4dc1234
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 28 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

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()
}
Expand All @@ -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,
Expand Down Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct FeaturesReader {
}

struct Features: Decodable {
let features: [Feature]
let features: [Feature]?
}

struct Feature: Decodable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
}
Expand All @@ -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")
)
Expand Down Expand Up @@ -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(),
"",
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Resources/Package.Base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -124,6 +125,7 @@ extension GeneratePackageManifest {
crtVersion: crtVersion,
services: services,
excludeRuntimeTests: excludeRuntimeTests,
previewBuild: previewBuild,
buildPackageManifest: buildPackageManifest
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,72 @@ import XCTest

class PackageManifestBuilderTests: XCTestCase {

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>" }
)
Expand Down
13 changes: 11 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ let crtVersion: Version = "0.43.0"

let excludeRuntimeUnitTests = false

let isPreviewBuild = false

let serviceTargets: [String] = [
"AWSACM",
"AWSACMPCA",
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 4dc1234

Please sign in to comment.