Skip to content

Commit

Permalink
Merge branch 'main' into jbe/sbs
Browse files Browse the repository at this point in the history
  • Loading branch information
jbelkins committed Jan 14, 2025
2 parents 731b4d9 + f0074fd commit d2f6529
Show file tree
Hide file tree
Showing 490 changed files with 58,138 additions and 34,343 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 @@ -86,6 +86,18 @@ struct PrepareRelease {
/// Empty manifest file makes GitHubReleasePublisher be no-op.
/// The manifest file is required regardless of whether there should
/// be a release or not.
log("Repo has no changes to publish.")
log("Writing empty manifest and exiting.")
try createEmptyReleaseManifest()
/// Return without creating new commit or tag in local repos.
/// This makes GitPublisher be no-op.
return
}
guard FeaturesReader.buildRequestAndMappingExist() else {
/// If the build request or mapping input files
/// don't exist, create an empty release-manifest.json file.
log("build-request.json and/or feature-service-id.json don't exist.")
log("Writing empty manifest and exiting.")
try createEmptyReleaseManifest()
/// Return without creating new commit or tag in local repos.
/// This makes GitPublisher be no-op.
Expand Down
15 changes: 10 additions & 5 deletions AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Models/Features.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,27 @@ import AWSCLIUtils

/// Reads the Trebuchet request & service mapping files from the parent of the current working directory.
struct FeaturesReader {
private let requestFile = "../build-request.json"
private let mappingFile = "../feature-service-id.json"
private static let requestFile = "../build-request.json"
private static let mappingFile = "../feature-service-id.json"

public static func buildRequestAndMappingExist() -> Bool {
return FileManager.default.fileExists(atPath: requestFile) &&
FileManager.default.fileExists(atPath: mappingFile)
}

public func getFeaturesFromFile() throws -> Features {
let fileContents = try FileManager.default.loadContents(atPath: requestFile)
let fileContents = try FileManager.default.loadContents(atPath: Self.requestFile)
return try JSONDecoder().decode(Features.self, from: fileContents)
}

public func getFeaturesIDToServiceNameDictFromFile() throws -> [String: String] {
let fileContents = try FileManager.default.loadContents(atPath: mappingFile)
let fileContents = try FileManager.default.loadContents(atPath: Self.mappingFile)
return try JSONDecoder().decode([String: String].self, from: fileContents)
}
}

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
14 changes: 11 additions & 3 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 Expand Up @@ -103,7 +110,8 @@ private var runtimeTargets: [Target] {
.smithyEventStreamsAuthAPI,
.awsSDKCommon,
.awsSDKHTTPAuth,
.awsSDKIdentity
.awsSDKIdentity,
.awsSDKChecksums,
],
path: "Sources/Core/AWSClientRuntime/Sources/AWSClientRuntime",
resources: [
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 @@ -45,15 +45,7 @@ class PrepareReleaseTests: CLITestCase {
createPackageVersion(previousVersion)
createNextPackageVersion(newVersion)

let buildRequest = """
{
"features": []
}
"""
FileManager.default.createFile(atPath: "../build-request.json", contents: Data(buildRequest.utf8))

let mapping = "{}"
FileManager.default.createFile(atPath: "../feature-service-id.json", contents: Data(mapping.utf8))
createBuildRequestAndMapping()

let subject = PrepareRelease.mock(repoType: .awsSdkSwift, diffChecker: { _,_ in true })
try! subject.run()
Expand Down Expand Up @@ -87,15 +79,45 @@ class PrepareReleaseTests: CLITestCase {
createPackageVersion(previousVersion)
createNextPackageVersion(newVersion)

createBuildRequestAndMapping()

let subject = PrepareRelease.mock(diffChecker: { _,_ in false })
try! subject.run()

let versionFromFile = try! Version.fromFile("Package.version")
XCTAssertEqual(versionFromFile, previousVersion)

XCTAssertTrue(commands.isEmpty)

// Verify that an empty release manifest was written
let data = try FileManager.default.loadContents(atPath: "release-manifest.json")
XCTAssertTrue(data.isEmpty)
}


func testRunBailsEarlyIfThereAreNoBuildRequestAndMapping() throws {
var commands: [String] = []
let runner = ProcessRunner {
commands.append($0.commandString)
}
ProcessRunner.testRunner = runner
let previousVersion = try Version("1.2.3")
let newVersion = try Version("1.2.4")
createPackageVersion(previousVersion)
createNextPackageVersion(newVersion)

let subject = PrepareRelease.mock(diffChecker: { _,_ in true })
try! subject.run()

let versionFromFile = try! Version.fromFile("Package.version")
XCTAssertEqual(versionFromFile, previousVersion)

XCTAssertTrue(commands.isEmpty)

// Verify that an empty release manifest was written
let data = try FileManager.default.loadContents(atPath: "release-manifest.json")
XCTAssertTrue(data.isEmpty)
}

// MARK: createNewVersion()

func testCreateNewSDKVersion() async throws {
Expand Down Expand Up @@ -175,6 +197,16 @@ class PrepareReleaseTests: CLITestCase {
try! subject.stageFiles()
XCTAssertTrue(command.hasSuffix("git add Package.version Package.version.next"))
}

// MARK: - Private methods

private func createBuildRequestAndMapping() {
let buildRequest = "{\"features\":[]}"
FileManager.default.createFile(atPath: "../build-request.json", contents: Data(buildRequest.utf8))

let mapping = "{}"
FileManager.default.createFile(atPath: "../feature-service-id.json", contents: Data(mapping.utf8))
}
}

// MARK: - Mocks
Expand Down
Loading

0 comments on commit d2f6529

Please sign in to comment.