-
Notifications
You must be signed in to change notification settings - Fork 80
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: Run CLI unit tests in CI #1799
Changes from all commits
231adf4
f18b7e8
dd803d8
e26ee0d
5c17a4d
e6aa350
45a3bbf
1288bf2
c5bffb5
17f8c72
84d9220
4bac8e3
cdd65ac
9782279
3bba2eb
d3cdd34
465ee53
5604554
835f097
3ed9e1d
cc376b2
df03510
681870b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Macs test & build CLI tools only directly on the Mac, not on simulators. |
||
- name: Prepare Protocol & Unit Tests | ||
run: | | ||
./scripts/ci_steps/prepare_protocol_and_unit_tests.sh | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All Linux jobs build & test the CLI tools. |
||
- name: Prepare Protocol & Unit Tests | ||
run: | | ||
./scripts/ci_steps/prepare_protocol_and_unit_tests.sh | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
||
|
@@ -235,13 +235,16 @@ struct PrepareRelease { | |
previousVersion: Version | ||
) throws { | ||
let commits = try Process.git.listOfCommitsBetween("HEAD", "\(previousVersion)") | ||
|
||
let featuresReader = FeaturesReader() | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Features reader is used to read the build message & mapping, then the read data is passed into the release notes builder. |
||
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( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,25 +8,18 @@ | |
import Foundation | ||
import AWSCLIUtils | ||
|
||
struct FeaturesReader: Decodable { | ||
private let requestFilePath: String | ||
private let mappingFilePath: String | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of taking individual paths to files, this type assumes the individual files are in the parent of the current working directory (which will be the repo's root). |
||
|
||
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) | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ReleaseNotesBuilders takes the feature list & mapping as inputs rather than reading them itself. |
||
|
||
// MARK: - Build | ||
|
||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, the injected features & mapping are used directly to generate the release notes content. |
||
} | ||
|
||
private func buildServiceFeatureSection( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,14 @@ import AWSCLIUtils | |
|
||
class CLITestCase: XCTestCase { | ||
let tmpPath = "tmp" | ||
let projectPath = "aws-sdk-swift-or-smithy-swift" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The directory at This structure allows Trebuchet build files to be written to the same relative location in tests as in actual use. |
||
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) | ||
|
@@ -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() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ import XCTest | |
/* | ||
* Regression tests for protection against change in generated release notes markdown content. | ||
*/ | ||
class ReleaseNotesBuilderTests: XCTestCase { | ||
class ReleaseNotesBuilderTests: CLITestCase { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test now inherits from CLITestCase, which sets up a temporary directory structure that allows the Trebuchet files to be written to the workspace directory. |
||
/* Reusable feature strings */ | ||
|
||
// New feature 1 | ||
|
@@ -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 { | ||
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. During tests, the FeaturesReader just reads the feature & map files out of the temp project root created for testing. |
||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GA AWS SDK now used by the SPRCLI tools. |
||
.package(path: "../AWSSDKSwiftCLI"), | ||
], | ||
targets: [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
// | ||
|
||
import Foundation | ||
import PackageDescription | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an old remnant of the AWSSDKSwiftCLI dependency on the |
||
import AWSCLIUtils | ||
|
||
extension Process { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,7 +65,7 @@ public struct SPRPublisher { | |
} | ||
|
||
private mutating func setOptions() async { | ||
await SDKLoggingSystem.initialize(logLevel: .error) | ||
await SDKLoggingSystem().initialize(logLevel: .error) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We changed this interface before GA. |
||
let env = ProcessInfo.processInfo.environment | ||
bucket = bucket ?? env["AWS_SDK_SPR_BUCKET"] | ||
if region.isEmpty { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,9 +63,9 @@ extension SPRPublisher { | |
throw Error("URL is invalid") | ||
} | ||
return baseURL | ||
.appending(component: scope) | ||
.appending(component: name) | ||
.appending(component: version) | ||
.appendingPathComponent(scope) | ||
.appendingPathComponent(name) | ||
.appendingPathComponent(version) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You will see several places where the method |
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,8 @@ extension SPRPublisher { | |
} | ||
|
||
private func createMetadata() -> PackageInfo { | ||
let now = Date().ISO8601Format() | ||
let formatter = ISO8601DateFormatter() | ||
let now = formatter.string(from: Date()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another new method replaced by an older one for compatibility with older Swift. |
||
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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
macos-14 is used for running min Xcode instead of macos-13. This matches the macOS used in Catapult.