Skip to content

Commit 4dc1234

Browse files
authored
feat: Generate package manifest for preview builds (#1863)
1 parent 9a590d6 commit 4dc1234

File tree

9 files changed

+110
-28
lines changed

9 files changed

+110
-28
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ codegen/protocol-test-codegen-local/smithy-build.json
3131
codegen/protocol-test-codegen/smithy-build.json
3232
SmokeTests/
3333

34+
# Preview embedded dependencies
35+
/smithy-swift/
36+
3437
# vim temporary files
3538
*.swp
3639

AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Commands/AWSSDKSwiftCLI/Subcommands/GeneratePackageManifest.swift

+13-4
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,18 @@ struct GeneratePackageManifestCommand: ParsableCommand {
3535
@Flag(help: "If the package manifest should exclude runtime tests.")
3636
var excludeRuntimeTests = false
3737

38+
@Flag(help: "If the package manifest should be configured for a preview build.")
39+
var previewBuild = false
40+
3841
func run() throws {
3942
let generatePackageManifest = GeneratePackageManifest.standard(
4043
repoPath: repoPath,
4144
packageFileName: packageFileName,
4245
clientRuntimeVersion: clientRuntimeVersion,
4346
crtVersion: crtVersion,
4447
services: services.isEmpty ? nil : services,
45-
excludeRuntimeTests: excludeRuntimeTests
48+
excludeRuntimeTests: excludeRuntimeTests,
49+
previewBuild: previewBuild
4650
)
4751
try generatePackageManifest.run()
4852
}
@@ -67,6 +71,8 @@ struct GeneratePackageManifest {
6771
let services: [String]?
6872
/// If the package manifest should exclude runtime unit tests.
6973
let excludeRuntimeTests: Bool
74+
/// If the package manifest should be configured for a preview build.
75+
let previewBuild: Bool
7076

7177
typealias BuildPackageManifest = (
7278
_ clientRuntimeVersion: Version,
@@ -199,21 +205,24 @@ extension GeneratePackageManifest {
199205
crtVersion: Version? = nil,
200206
services: [String]? = nil,
201207
excludeAWSServices: Bool = false,
202-
excludeRuntimeTests: Bool = false
208+
excludeRuntimeTests: Bool = false,
209+
previewBuild: Bool = false
203210
) -> Self {
204211
GeneratePackageManifest(
205212
repoPath: repoPath,
206213
packageFileName: packageFileName,
207214
clientRuntimeVersion: clientRuntimeVersion,
208215
crtVersion: crtVersion,
209216
services: services,
210-
excludeRuntimeTests: excludeRuntimeTests
217+
excludeRuntimeTests: excludeRuntimeTests,
218+
previewBuild: previewBuild
211219
) { _clientRuntimeVersion, _crtVersion, _services in
212220
let builder = PackageManifestBuilder(
213221
clientRuntimeVersion: _clientRuntimeVersion,
214222
crtVersion: _crtVersion,
215223
services: _services,
216-
excludeRuntimeTests: excludeRuntimeTests
224+
excludeRuntimeTests: excludeRuntimeTests,
225+
previewBuild: previewBuild
217226
)
218227
return try builder.build()
219228
}

AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Models/Features.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct FeaturesReader {
2525
}
2626

2727
struct Features: Decodable {
28-
let features: [Feature]
28+
let features: [Feature]?
2929
}
3030

3131
struct Feature: Decodable {

AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Models/PackageManifestBuilder.swift

+13-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ struct PackageManifestBuilder {
1818
let crtVersion: Version
1919
let services: [Service]
2020
let excludeRuntimeTests: Bool
21+
let previewBuild: Bool
2122
let prefixContents: () throws -> String
2223
let basePackageContents: () throws -> String
2324

@@ -26,13 +27,15 @@ struct PackageManifestBuilder {
2627
crtVersion: Version,
2728
services: [Service],
2829
excludeRuntimeTests: Bool,
30+
previewBuild: Bool,
2931
prefixContents: @escaping () throws -> String,
3032
basePackageContents: @escaping () throws -> String
3133
) {
3234
self.clientRuntimeVersion = clientRuntimeVersion
3335
self.crtVersion = crtVersion
3436
self.services = services
3537
self.excludeRuntimeTests = excludeRuntimeTests
38+
self.previewBuild = previewBuild
3639
self.prefixContents = prefixContents
3740
self.basePackageContents = basePackageContents
3841
}
@@ -41,13 +44,15 @@ struct PackageManifestBuilder {
4144
clientRuntimeVersion: Version,
4245
crtVersion: Version,
4346
services: [Service],
44-
excludeRuntimeTests: Bool
47+
excludeRuntimeTests: Bool,
48+
previewBuild: Bool
4549
) {
4650
self.init(
4751
clientRuntimeVersion: clientRuntimeVersion,
4852
crtVersion: crtVersion,
4953
services: services,
5054
excludeRuntimeTests: excludeRuntimeTests,
55+
previewBuild: previewBuild,
5156
prefixContents: Self.contentReader(filename: "Package.Prefix"),
5257
basePackageContents: Self.contentReader(filename: "Package.Base")
5358
)
@@ -96,6 +101,9 @@ struct PackageManifestBuilder {
96101
// Remove the runtime tests if needed
97102
buildRuntimeTests(),
98103
"",
104+
// Configure for preview or regular build
105+
buildPreviewFlag(),
106+
"",
99107
// Add the generated content that defines the list of services to include
100108
buildServiceTargets(),
101109
"",
@@ -123,6 +131,10 @@ struct PackageManifestBuilder {
123131
"let excludeRuntimeUnitTests = \(excludeRuntimeTests)"
124132
}
125133

134+
private func buildPreviewFlag() -> String {
135+
"let isPreviewBuild = \(previewBuild)"
136+
}
137+
126138
/// Builds the list of services to include.
127139
/// This generates an array of strings, where the each item is a name of a service
128140
/// and calls the `addServiceTarget` for each item.

AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Models/ReleaseNotesBuilder.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct ReleaseNotesBuilder {
4949
_ features: Features,
5050
_ mapping: [String: String]
5151
) -> [String] {
52-
let formattedFeatures = features.features
52+
let formattedFeatures = (features.features ?? [])
5353
.filter { $0.featureMetadata.trebuchet.featureType == "NEW_FEATURE" }
5454
.map { "* **AWS \(mapping[$0.featureMetadata.trebuchet.featureId]!)**: \($0.releaseNotes ?? "No description provided.")" }
5555
.joined(separator: .newline)
@@ -63,7 +63,7 @@ struct ReleaseNotesBuilder {
6363
_ features: Features,
6464
_ mapping: [String: String]
6565
) -> [String] {
66-
let formattedDocUpdates = features.features
66+
let formattedDocUpdates = (features.features ?? [])
6767
.filter { $0.featureMetadata.trebuchet.featureType == "DOC_UPDATE" }
6868
.map { "* **AWS \(mapping[$0.featureMetadata.trebuchet.featureId]!)**: \($0.releaseNotes ?? "No description provided.")" }
6969
.joined(separator: .newline)

AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Resources/Package.Base.txt

+9-2
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,17 @@ private func productForService(_ service: String) -> Product {
6969
// MARK: Dependencies
7070

7171
private var clientRuntimeDependency: Package.Dependency {
72-
let path = "../smithy-swift"
72+
let previewPath = "./smithy-swift"
73+
let developmentPath = "../smithy-swift"
7374
let gitURL = "https://github.com/smithy-lang/smithy-swift"
7475
let useLocalDeps = ProcessInfo.processInfo.environment["AWS_SWIFT_SDK_USE_LOCAL_DEPS"] != nil
75-
return useLocalDeps ? .package(path: path) : .package(url: gitURL, exact: clientRuntimeVersion)
76+
if isPreviewBuild {
77+
return .package(path: previewPath)
78+
} else if useLocalDeps {
79+
return .package(path: developmentPath)
80+
} else {
81+
return .package(url: gitURL, exact: clientRuntimeVersion)
82+
}
7683
}
7784

7885
private var crtDependency: Package.Dependency {

AWSSDKSwiftCLI/Tests/AWSSDKSwiftCLITests/Commands/GeneratePackageManifestTests.swift

+2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ extension GeneratePackageManifest {
115115
crtVersion: Version? = nil,
116116
services: [String]? = nil,
117117
excludeRuntimeTests: Bool = false,
118+
previewBuild: Bool = false,
118119
buildPackageManifest: @escaping BuildPackageManifest = { (_,_,_) throws -> String in "" }
119120
) -> GeneratePackageManifest {
120121
GeneratePackageManifest(
@@ -124,6 +125,7 @@ extension GeneratePackageManifest {
124125
crtVersion: crtVersion,
125126
services: services,
126127
excludeRuntimeTests: excludeRuntimeTests,
128+
previewBuild: previewBuild,
127129
buildPackageManifest: buildPackageManifest
128130
)
129131
}

AWSSDKSwiftCLI/Tests/AWSSDKSwiftCLITests/Models/PackageManifestBuilderTests.swift

+56-16
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,72 @@ import XCTest
1010

1111
class PackageManifestBuilderTests: XCTestCase {
1212

13-
let expected = """
14-
<contents of prefix>
15-
// MARK: - Dynamic Content
13+
func testBuildWithDefaults() throws {
14+
let expected = """
15+
<contents of prefix>
16+
// MARK: - Dynamic Content
1617
17-
let clientRuntimeVersion: Version = "1.2.3"
18-
let crtVersion: Version = "4.5.6"
18+
let clientRuntimeVersion: Version = "1.2.3"
19+
let crtVersion: Version = "4.5.6"
1920
20-
let excludeRuntimeUnitTests = false
21+
let excludeRuntimeUnitTests = false
2122
22-
let serviceTargets: [String] = [
23-
"A",
24-
"B",
25-
"C",
26-
"D",
27-
"E",
28-
]
23+
let isPreviewBuild = false
2924
30-
<contents of base package>
31-
"""
25+
let serviceTargets: [String] = [
26+
"A",
27+
"B",
28+
"C",
29+
"D",
30+
"E",
31+
]
3232
33-
func testBuild() throws {
33+
<contents of base package>
34+
"""
3435
let subject = try PackageManifestBuilder(
3536
clientRuntimeVersion: .init("1.2.3"),
3637
crtVersion: .init("4.5.6"),
3738
services: ["A","B","C","D","E"].map { PackageManifestBuilder.Service(name: $0) },
3839
excludeRuntimeTests: false,
40+
previewBuild: false,
41+
prefixContents: { "<contents of prefix>" },
42+
basePackageContents: { "<contents of base package>" }
43+
)
44+
let result = try! subject.build()
45+
print("")
46+
print(result)
47+
print("")
48+
XCTAssertEqual(result, expected)
49+
}
50+
51+
func testBuildWithPreviewBuildAndExcludedTests() throws {
52+
let expected = """
53+
<contents of prefix>
54+
// MARK: - Dynamic Content
55+
56+
let clientRuntimeVersion: Version = "1.2.3"
57+
let crtVersion: Version = "4.5.6"
58+
59+
let excludeRuntimeUnitTests = true
60+
61+
let isPreviewBuild = true
62+
63+
let serviceTargets: [String] = [
64+
"A",
65+
"B",
66+
"C",
67+
"D",
68+
"E",
69+
]
70+
71+
<contents of base package>
72+
"""
73+
let subject = try PackageManifestBuilder(
74+
clientRuntimeVersion: .init("1.2.3"),
75+
crtVersion: .init("4.5.6"),
76+
services: ["A","B","C","D","E"].map { PackageManifestBuilder.Service(name: $0) },
77+
excludeRuntimeTests: true,
78+
previewBuild: true,
3979
prefixContents: { "<contents of prefix>" },
4080
basePackageContents: { "<contents of base package>" }
4181
)

Package.swift

+11-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ let crtVersion: Version = "0.43.0"
2020

2121
let excludeRuntimeUnitTests = false
2222

23+
let isPreviewBuild = false
24+
2325
let serviceTargets: [String] = [
2426
"AWSACM",
2527
"AWSACMPCA",
@@ -496,10 +498,17 @@ private func productForService(_ service: String) -> Product {
496498
// MARK: Dependencies
497499

498500
private var clientRuntimeDependency: Package.Dependency {
499-
let path = "../smithy-swift"
501+
let previewPath = "./smithy-swift"
502+
let developmentPath = "../smithy-swift"
500503
let gitURL = "https://github.com/smithy-lang/smithy-swift"
501504
let useLocalDeps = ProcessInfo.processInfo.environment["AWS_SWIFT_SDK_USE_LOCAL_DEPS"] != nil
502-
return useLocalDeps ? .package(path: path) : .package(url: gitURL, exact: clientRuntimeVersion)
505+
if isPreviewBuild {
506+
return .package(path: previewPath)
507+
} else if useLocalDeps {
508+
return .package(path: developmentPath)
509+
} else {
510+
return .package(url: gitURL, exact: clientRuntimeVersion)
511+
}
503512
}
504513

505514
private var crtDependency: Package.Dependency {

0 commit comments

Comments
 (0)