Skip to content
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

chore: Don't fail prepare-release when build request is missing #1865

Merged
merged 4 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 9 additions & 4 deletions AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Models/Features.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ 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)
}
}
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()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creation of JSON files extracted to a reusable helper below, so it can be used in the "no code changes" test case below


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