Skip to content

Commit e45efb8

Browse files
authored
chore: Run CLI unit tests in CI (#1799)
1 parent 4c65c09 commit e45efb8

File tree

14 files changed

+61
-43
lines changed

14 files changed

+61
-43
lines changed

.github/workflows/continuous-integration.yml

+17-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
matrix:
1616
# This matrix runs tests on iOS sim & Mac, on oldest & newest supported Xcodes
1717
runner:
18-
- macos-13
18+
- macos-14
1919
- macos-15
2020
xcode:
2121
- Xcode_15.2
@@ -30,7 +30,7 @@ jobs:
3030
- 'platform=macOS'
3131
exclude:
3232
# Don't run old macOS with new Xcode
33-
- runner: macos-13
33+
- runner: macos-14
3434
xcode: Xcode_16
3535
# Don't run new macOS with old Xcode
3636
- runner: macos-15
@@ -101,6 +101,14 @@ jobs:
101101
java-version: 17
102102
- name: Tools Versions
103103
run: ./scripts/ci_steps/log_tool_versions.sh
104+
- name: Run CLI Unit Tests
105+
if: ${{ matrix.destination == 'platform=macOS' }}
106+
run: |
107+
cd AWSSDKSwiftCLI
108+
swift test
109+
cd ../SPRCLI
110+
unset AWS_SWIFT_SDK_USE_LOCAL_DEPS
111+
swift build
104112
- name: Prepare Protocol & Unit Tests
105113
run: |
106114
./scripts/ci_steps/prepare_protocol_and_unit_tests.sh
@@ -182,6 +190,13 @@ jobs:
182190
run: ./scripts/ci_steps/install_native_linux_dependencies.sh
183191
- name: Tools Versions
184192
run: ./scripts/ci_steps/log_tool_versions.sh
193+
- name: Run CLI Unit Tests
194+
run: |
195+
cd AWSSDKSwiftCLI
196+
swift test
197+
cd ../SPRCLI
198+
unset AWS_SWIFT_SDK_USE_LOCAL_DEPS
199+
swift build
185200
- name: Prepare Protocol & Unit Tests
186201
run: |
187202
./scripts/ci_steps/prepare_protocol_and_unit_tests.sh

AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Commands/AWSSDKSwiftCLI/Subcommands/PrepareRelease.swift

+6-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct PrepareRelease {
7676
let diffChecker: DiffChecker
7777

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

@@ -235,13 +235,16 @@ struct PrepareRelease {
235235
previousVersion: Version
236236
) throws {
237237
let commits = try Process.git.listOfCommitsBetween("HEAD", "\(previousVersion)")
238-
238+
let featuresReader = FeaturesReader()
239+
239240
let releaseNotes = try ReleaseNotesBuilder(
240241
previousVersion: previousVersion,
241242
newVersion: newVersion,
242243
repoOrg: repoOrg,
243244
repoType: repoType,
244-
commits: commits
245+
commits: commits,
246+
features: featuresReader.getFeaturesFromFile(),
247+
featuresIDToServiceName: featuresReader.getFeaturesIDToServiceNameDictFromFile()
245248
).build()
246249

247250
let manifest = ReleaseManifest(

AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Models/Features.swift

+6-13
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,18 @@
88
import Foundation
99
import AWSCLIUtils
1010

11-
struct FeaturesReader: Decodable {
12-
private let requestFilePath: String
13-
private let mappingFilePath: String
14-
15-
public init(
16-
requestFilePath: String = "../build-request.json",
17-
mappingFilePath: String = "../feature-service-id.json"
18-
) {
19-
self.requestFilePath = requestFilePath
20-
self.mappingFilePath = mappingFilePath
21-
}
11+
/// Reads the Trebuchet request & service mapping files from the parent of the current working directory.
12+
struct FeaturesReader {
13+
private let requestFile = "../build-request.json"
14+
private let mappingFile = "../feature-service-id.json"
2215

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

2821
public func getFeaturesIDToServiceNameDictFromFile() throws -> [String: String] {
29-
let fileContents = try FileManager.default.loadContents(atPath: mappingFilePath)
22+
let fileContents = try FileManager.default.loadContents(atPath: mappingFile)
3023
return try JSONDecoder().decode([String: String].self, from: fileContents)
3124
}
3225
}

AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Models/ReleaseNotesBuilder.swift

+3-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ struct ReleaseNotesBuilder {
1515
let repoOrg: PrepareRelease.Org
1616
let repoType: PrepareRelease.Repo
1717
let commits: [String]
18-
var featuresReader: FeaturesReader = FeaturesReader()
18+
let features: Features
19+
let featuresIDToServiceName: [String: String]
1920

2021
// MARK: - Build
2122

@@ -41,9 +42,7 @@ struct ReleaseNotesBuilder {
4142
}
4243

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

4948
private func buildServiceFeatureSection(

AWSSDKSwiftCLI/Tests/AWSSDKSwiftCLITests/CLITestCase.swift

+11
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@ import AWSCLIUtils
1111

1212
class CLITestCase: XCTestCase {
1313
let tmpPath = "tmp"
14+
let projectPath = "aws-sdk-swift-or-smithy-swift"
1415
private var originalWorkingDirectory: String!
1516

17+
/// Creates a temp directory that contains a project dir.
18+
///
19+
/// The project dir is set as CWD when setup is complete.
20+
/// This folder structure permits Trebuchet artifacts to be written in the parent of the project directory.
21+
/// At the conclusion of the test, the tear-down method deletes the entire temp directory.
1622
override func setUp() {
1723
super.setUp()
1824
try? FileManager.default.removeItem(atPath: tmpPath)
@@ -23,6 +29,11 @@ class CLITestCase: XCTestCase {
2329
)
2430
originalWorkingDirectory = FileManager.default.currentDirectoryPath
2531
try! FileManager.default.changeWorkingDirectory(tmpPath)
32+
try! FileManager.default.createDirectory(
33+
atPath: projectPath,
34+
withIntermediateDirectories: false
35+
)
36+
try! FileManager.default.changeWorkingDirectory(projectPath)
2637
}
2738

2839
override func tearDown() {

AWSSDKSwiftCLI/Tests/AWSSDKSwiftCLITests/Commands/PrepareReleaseTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ class PrepareReleaseTests: CLITestCase {
5050
"features": []
5151
}
5252
"""
53-
FileManager.default.createFile(atPath: "build-request.json", contents: Data(buildRequest.utf8))
53+
FileManager.default.createFile(atPath: "../build-request.json", contents: Data(buildRequest.utf8))
5454

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

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

AWSSDKSwiftCLI/Tests/AWSSDKSwiftCLITests/Models/ReleaseNotesBuilderTests.swift

+7-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import XCTest
1212
/*
1313
* Regression tests for protection against change in generated release notes markdown content.
1414
*/
15-
class ReleaseNotesBuilderTests: XCTestCase {
15+
class ReleaseNotesBuilderTests: CLITestCase {
1616
/* Reusable feature strings */
1717

1818
// New feature 1
@@ -195,10 +195,9 @@ class ReleaseNotesBuilderTests: XCTestCase {
195195

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

204203
private func setUpBuilder(testCommits: [String] = []) throws -> ReleaseNotesBuilder {
@@ -208,11 +207,9 @@ class ReleaseNotesBuilderTests: XCTestCase {
208207
repoOrg: .awslabs,
209208
repoType: .awsSdkSwift,
210209
commits: testCommits,
211-
// Parametrize behavior of FeaturesReader with paths used to create JSON test files
212-
featuresReader: FeaturesReader(
213-
requestFilePath: "build-request.json",
214-
mappingFilePath: "feature-service-id.json"
215-
)
210+
// Parameterize behavior of FeaturesReader with paths used to create JSON test files
211+
features: FeaturesReader().getFeaturesFromFile(),
212+
featuresIDToServiceName: FeaturesReader().getFeaturesIDToServiceNameDictFromFile()
216213
)
217214
}
218215
}

SPRCLI/Package.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ let package = Package(
99
],
1010
dependencies: [
1111
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.2.0"),
12-
.package(url: "https://github.com/awslabs/aws-sdk-swift", from: "0.46.0"),
12+
.package(url: "https://github.com/awslabs/aws-sdk-swift", from: "1.0.0"),
1313
.package(path: "../AWSSDKSwiftCLI"),
1414
],
1515
targets: [

SPRCLI/Sources/SPR/Process+SPR.swift

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//
77

88
import Foundation
9-
import PackageDescription
109
import AWSCLIUtils
1110

1211
extension Process {

SPRCLI/Sources/SPR/SPRPublisher.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public struct SPRPublisher {
6565
}
6666

6767
private mutating func setOptions() async {
68-
await SDKLoggingSystem.initialize(logLevel: .error)
68+
await SDKLoggingSystem().initialize(logLevel: .error)
6969
let env = ProcessInfo.processInfo.environment
7070
bucket = bucket ?? env["AWS_SDK_SPR_BUCKET"]
7171
if region.isEmpty {

SPRCLI/Sources/SPR/UpdateList.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ extension SPRPublisher {
6363
throw Error("URL is invalid")
6464
}
6565
return baseURL
66-
.appending(component: scope)
67-
.appending(component: name)
68-
.appending(component: version)
66+
.appendingPathComponent(scope)
67+
.appendingPathComponent(name)
68+
.appendingPathComponent(version)
6969
}
7070
}
7171
}

SPRCLI/Sources/SPR/UploadArchive.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extension SPRPublisher {
1515

1616
mutating func uploadArchive() async throws {
1717
let tmpDirFileURL = FileManager.default.temporaryDirectory
18-
let archiveFileURL = tmpDirFileURL.appending(component: "\(UUID().uuidString).zip")
18+
let archiveFileURL = tmpDirFileURL.appendingPathComponent("\(UUID().uuidString).zip")
1919
let archiveProcess = Process.SPR.archive(name: name, packagePath: path, archiveFileURL: archiveFileURL)
2020
_ = try _runReturningStdOut(archiveProcess)
2121
guard FileManager.default.fileExists(atPath: urlPath(archiveFileURL)) else {

SPRCLI/Sources/SPR/UploadManifest.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extension SPRPublisher {
1515

1616
func uploadManifest() async throws {
1717
let packageFileURL = URL(fileURLWithPath: path).standardizedFileURL
18-
let manifestFileURL = packageFileURL.appending(component: "Package.swift")
18+
let manifestFileURL = packageFileURL.appendingPathComponent("Package.swift")
1919
let s3Client = try S3Client(region: region)
2020
try await verify(s3Client: s3Client)
2121
try await upload(s3Client: s3Client, manifestFileURL: manifestFileURL)

SPRCLI/Sources/SPR/UploadMetadata.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ extension SPRPublisher {
4747
}
4848

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

0 commit comments

Comments
 (0)