Skip to content

Commit

Permalink
Merge branch 'main' into jbe/spr2
Browse files Browse the repository at this point in the history
  • Loading branch information
jbelkins committed Oct 24, 2024
2 parents 4ed4e5e + e45efb8 commit 7a1554e
Show file tree
Hide file tree
Showing 57 changed files with 3,856 additions and 365 deletions.
19 changes: 17 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
matrix:
# This matrix runs tests on iOS sim & Mac, on oldest & newest supported Xcodes
runner:
- macos-13
- macos-14
- macos-15
xcode:
- Xcode_15.2
Expand All @@ -30,7 +30,7 @@ jobs:
- 'platform=macOS'
exclude:
# Don't run old macOS with new Xcode
- runner: macos-13
- runner: macos-14
xcode: Xcode_16
# Don't run new macOS with old Xcode
- runner: macos-15
Expand Down Expand Up @@ -101,6 +101,14 @@ jobs:
java-version: 17
- name: Tools Versions
run: ./scripts/ci_steps/log_tool_versions.sh
- name: Run CLI Unit Tests
if: ${{ matrix.destination == 'platform=macOS' }}
run: |
cd AWSSDKSwiftCLI
swift test
cd ../SPRCLI
unset AWS_SWIFT_SDK_USE_LOCAL_DEPS
swift build
- name: Prepare Protocol & Unit Tests
run: |
./scripts/ci_steps/prepare_protocol_and_unit_tests.sh
Expand Down Expand Up @@ -182,6 +190,13 @@ jobs:
run: ./scripts/ci_steps/install_native_linux_dependencies.sh
- name: Tools Versions
run: ./scripts/ci_steps/log_tool_versions.sh
- name: Run CLI Unit Tests
run: |
cd AWSSDKSwiftCLI
swift test
cd ../SPRCLI
unset AWS_SWIFT_SDK_USE_LOCAL_DEPS
swift build
- name: Prepare Protocol & Unit Tests
run: |
./scripts/ci_steps/prepare_protocol_and_unit_tests.sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct PrepareRelease {
let diffChecker: DiffChecker

/// Prepares a release for the specified repository.
/// If the respository doesn't have any changes, then this does nothing.
/// If the repository doesn't have any changes, then this does nothing.
func run() throws {
try FileManager.default.changeWorkingDirectory(repoPath)

Expand Down Expand Up @@ -235,13 +235,16 @@ struct PrepareRelease {
previousVersion: Version
) throws {
let commits = try Process.git.listOfCommitsBetween("HEAD", "\(previousVersion)")

let featuresReader = FeaturesReader()

let releaseNotes = try ReleaseNotesBuilder(
previousVersion: previousVersion,
newVersion: newVersion,
repoOrg: repoOrg,
repoType: repoType,
commits: commits
commits: commits,
features: featuresReader.getFeaturesFromFile(),
featuresIDToServiceName: featuresReader.getFeaturesIDToServiceNameDictFromFile()
).build()

let manifest = ReleaseManifest(
Expand Down
19 changes: 6 additions & 13 deletions AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Models/Features.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,18 @@
import Foundation
import AWSCLIUtils

struct FeaturesReader: Decodable {
private let requestFilePath: String
private let mappingFilePath: String

public init(
requestFilePath: String = "../build-request.json",
mappingFilePath: String = "../feature-service-id.json"
) {
self.requestFilePath = requestFilePath
self.mappingFilePath = mappingFilePath
}
/// 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"

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

public func getFeaturesIDToServiceNameDictFromFile() throws -> [String: String] {
let fileContents = try FileManager.default.loadContents(atPath: mappingFilePath)
let fileContents = try FileManager.default.loadContents(atPath: mappingFile)
return try JSONDecoder().decode([String: String].self, from: fileContents)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ struct ReleaseNotesBuilder {
let repoOrg: PrepareRelease.Org
let repoType: PrepareRelease.Repo
let commits: [String]
var featuresReader: FeaturesReader = FeaturesReader()
let features: Features
let featuresIDToServiceName: [String: String]

// MARK: - Build

Expand All @@ -41,9 +42,7 @@ struct ReleaseNotesBuilder {
}

func buildServiceChangeSection() throws -> [String] {
let features = try featuresReader.getFeaturesFromFile()
let mapping = try featuresReader.getFeaturesIDToServiceNameDictFromFile()
return buildServiceFeatureSection(features, mapping) + buildServiceDocSection(features, mapping)
return buildServiceFeatureSection(features, featuresIDToServiceName) + buildServiceDocSection(features, featuresIDToServiceName)
}

private func buildServiceFeatureSection(
Expand Down
11 changes: 11 additions & 0 deletions AWSSDKSwiftCLI/Tests/AWSSDKSwiftCLITests/CLITestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ import AWSCLIUtils

class CLITestCase: XCTestCase {
let tmpPath = "tmp"
let projectPath = "aws-sdk-swift-or-smithy-swift"
private var originalWorkingDirectory: String!

/// Creates a temp directory that contains a project dir.
///
/// The project dir is set as CWD when setup is complete.
/// This folder structure permits Trebuchet artifacts to be written in the parent of the project directory.
/// At the conclusion of the test, the tear-down method deletes the entire temp directory.
override func setUp() {
super.setUp()
try? FileManager.default.removeItem(atPath: tmpPath)
Expand All @@ -23,6 +29,11 @@ class CLITestCase: XCTestCase {
)
originalWorkingDirectory = FileManager.default.currentDirectoryPath
try! FileManager.default.changeWorkingDirectory(tmpPath)
try! FileManager.default.createDirectory(
atPath: projectPath,
withIntermediateDirectories: false
)
try! FileManager.default.changeWorkingDirectory(projectPath)
}

override func tearDown() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ class PrepareReleaseTests: CLITestCase {
"features": []
}
"""
FileManager.default.createFile(atPath: "build-request.json", contents: Data(buildRequest.utf8))
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))
FileManager.default.createFile(atPath: "../feature-service-id.json", contents: Data(mapping.utf8))

let subject = PrepareRelease.mock(repoType: .awsSdkSwift, diffChecker: { _,_ in true })
try! subject.run()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import XCTest
/*
* Regression tests for protection against change in generated release notes markdown content.
*/
class ReleaseNotesBuilderTests: XCTestCase {
class ReleaseNotesBuilderTests: CLITestCase {
/* Reusable feature strings */

// New feature 1
Expand Down Expand Up @@ -195,10 +195,9 @@ class ReleaseNotesBuilderTests: XCTestCase {

private func setUpBuildRequestAndMappingJSONs(_ buildRequest: String, _ mapping: String) {
// In real scenario, the JSON files we need are located one level above, in the workspace directory.
// For tests, due to sandboxing, the dummy files are created in current directory instead of
// in parent directory.
FileManager.default.createFile(atPath: "build-request.json", contents: Data(buildRequest.utf8))
FileManager.default.createFile(atPath: "feature-service-id.json", contents: Data(mapping.utf8))
// So, the dummy files are created in the parent of the current directory to match a real build.
FileManager.default.createFile(atPath: "../build-request.json", contents: Data(buildRequest.utf8))
FileManager.default.createFile(atPath: "../feature-service-id.json", contents: Data(mapping.utf8))
}

private func setUpBuilder(testCommits: [String] = []) throws -> ReleaseNotesBuilder {
Expand All @@ -208,11 +207,9 @@ class ReleaseNotesBuilderTests: XCTestCase {
repoOrg: .awslabs,
repoType: .awsSdkSwift,
commits: testCommits,
// Parametrize behavior of FeaturesReader with paths used to create JSON test files
featuresReader: FeaturesReader(
requestFilePath: "build-request.json",
mappingFilePath: "feature-service-id.json"
)
// Parameterize behavior of FeaturesReader with paths used to create JSON test files
features: FeaturesReader().getFeaturesFromFile(),
featuresIDToServiceName: FeaturesReader().getFeaturesIDToServiceNameDictFromFile()
)
}
}
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import PackageDescription

// MARK: - Dynamic Content

let clientRuntimeVersion: Version = "0.82.0"
let crtVersion: Version = "0.36.0"
let clientRuntimeVersion: Version = "0.83.0"
let crtVersion: Version = "0.37.0"

let packageScope = "aws-sdk-swift"

Expand Down
2 changes: 1 addition & 1 deletion Package.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.24
1.0.26
2 changes: 1 addition & 1 deletion Package.version.next
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.25
1.0.27
2 changes: 1 addition & 1 deletion SPRCLI/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.2.0"),
.package(url: "https://github.com/awslabs/aws-sdk-swift", from: "0.46.0"),
.package(url: "https://github.com/awslabs/aws-sdk-swift", from: "1.0.0"),
.package(path: "../AWSSDKSwiftCLI"),
],
targets: [
Expand Down
1 change: 0 additions & 1 deletion SPRCLI/Sources/SPR/Process+SPR.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import Foundation
import PackageDescription
import AWSCLIUtils

extension Process {
Expand Down
15 changes: 15 additions & 0 deletions SPRCLI/Sources/SPR/SPRPublisher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,19 @@ public struct SPRPublisher {
var keyPrefix: [String] {
url.pathComponents.filter { $0 != "/" }
}

private mutating func setOptions() async {
await SDKLoggingSystem().initialize(logLevel: .error)
let env = ProcessInfo.processInfo.environment
bucket = bucket ?? env["AWS_SDK_SPR_BUCKET"]
if region.isEmpty {
region = env["AWS_SDK_SPR_REGION"] ?? "us-east-1"
}
distributionID = Self.resolvedDistributionID(from: distributionID)
}

static func resolvedDistributionID(from distributionID: String?) -> String? {
let env = ProcessInfo.processInfo.environment
return distributionID ?? env["AWS_SDK_SPR_DISTRIBUTION_ID"]
}
}
11 changes: 7 additions & 4 deletions SPRCLI/Sources/SPR/UpdateList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ extension SPRPublisher {

private var releaseURL: URL {
get throws {
return url
.appending(component: scope)
.appending(component: name)
.appending(component: version)
guard let baseURL = URL(string: url) else {
throw Error("URL is invalid")
}
return baseURL
.appendingPathComponent(scope)
.appendingPathComponent(name)
.appendingPathComponent(version)
}
}
}
2 changes: 1 addition & 1 deletion SPRCLI/Sources/SPR/UploadArchive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension SPRPublisher {

mutating func uploadArchive() async throws {
let tmpDirFileURL = FileManager.default.temporaryDirectory
let archiveFileURL = tmpDirFileURL.appending(component: "\(UUID().uuidString).zip")
let archiveFileURL = tmpDirFileURL.appendingPathComponent("\(UUID().uuidString).zip")
let archiveProcess = Process.SPR.archive(name: name, packagePath: path, archiveFileURL: archiveFileURL)
_ = try _runReturningStdOut(archiveProcess)
guard FileManager.default.fileExists(atPath: urlPath(archiveFileURL)) else {
Expand Down
2 changes: 1 addition & 1 deletion SPRCLI/Sources/SPR/UploadManifest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension SPRPublisher {

func uploadManifest() async throws {
let packageFileURL = URL(fileURLWithPath: path).standardizedFileURL
let manifestFileURL = packageFileURL.appending(component: "Package.swift")
let manifestFileURL = packageFileURL.appendingPathComponent("Package.swift")
let s3Client = try S3Client(region: region)
try await verify(s3Client: s3Client)
try await upload(s3Client: s3Client, manifestFileURL: manifestFileURL)
Expand Down
3 changes: 2 additions & 1 deletion SPRCLI/Sources/SPR/UploadMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ extension SPRPublisher {
}

private func createMetadata() -> PackageInfo {
let now = Date().ISO8601Format()
let formatter = ISO8601DateFormatter()
let now = formatter.string(from: Date())
let organization = PackageInfo.Metadata.Author.Organization(name: "Amazon Web Services", email: nil, description: nil, url: URL(string: "https://aws.amazon.com/")!)
let author = PackageInfo.Metadata.Author(name: "AWS SDK for Swift Team", email: nil, description: nil, organization: organization, url: nil)
let resource = Resource(name: "source-archive", type: "application/zip", checksum: checksum, signing: nil)
Expand Down
Loading

0 comments on commit 7a1554e

Please sign in to comment.