Skip to content

Commit e8196d3

Browse files
committed
fixup
1 parent dff8d36 commit e8196d3

File tree

3 files changed

+151
-69
lines changed

3 files changed

+151
-69
lines changed

Sources/PackageRegistry/RegistryClient.swift

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -952,37 +952,12 @@ extension RegistryClient {
952952
}
953953
}
954954

955-
extension RegistryClient {
956-
public enum SignatureFormat {
957-
case CMS_1_0_0
958-
}
959-
}
960-
961-
extension RegistryClient {
962-
public struct PublishConfiguration {
963-
public let signing: Signing
964-
965-
public init(signing: Signing) {
966-
self.signing = signing
967-
}
968-
969-
public struct Signing {
970-
public let required: Bool
971-
public let acceptedSignatureFormats: [SignatureFormat]
972-
public let trustedRootCertificates: [String]
973-
974-
public init(
975-
required: Bool,
976-
acceptedSignatureFormats: [SignatureFormat],
977-
trustedRootCertificates: [String]
978-
) {
979-
self.required = required
980-
self.acceptedSignatureFormats = acceptedSignatureFormats
981-
self.trustedRootCertificates = trustedRootCertificates
982-
}
983-
}
984-
}
985-
}
955+
/*
956+
extension RegistryClient {
957+
public enum SignatureFormat {
958+
case CMS_1_0_0
959+
}
960+
}*/
986961

987962
extension RegistryClient {
988963
public enum PublishResult: Equatable {

Sources/PackageRegistryTool/PackageRegistryTool+Publish.swift

Lines changed: 74 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extension SwiftPackageRegistryTool {
3333
@OptionGroup(visibility: .hidden)
3434
var globalOptions: GlobalOptions
3535

36-
@Option(name: [.customLong("id"), .customLong("package-id")] , help: "The package identity")
36+
@Option(name: [.customLong("id"), .customLong("package-id")], help: "The package identity")
3737
var packageIdentity: PackageIdentity
3838

3939
@Option(name: [.customLong("version"), .customLong("package-version")], help: "The package version")
@@ -68,6 +68,9 @@ extension SwiftPackageRegistryTool {
6868
)
6969
var certificateChainPaths: [AbsolutePath] = []
7070

71+
@Option(help: "Dry run only, prepare the archive and sign it but do not publish to the registry")
72+
var dryRun: Bool = false
73+
7174
func run(_ swiftTool: SwiftTool) throws {
7275
let configuration = try getRegistriesConfig(swiftTool).configuration
7376

@@ -131,23 +134,40 @@ extension SwiftPackageRegistryTool {
131134
)
132135

133136
// step 1: publishing configuration
134-
let metadataPath = self.customMetadataPath ?? packageDirectory.appending(component: Self.metadataFilename)
135-
guard localFileSystem.exists(metadataPath) else {
136-
throw StringError(
137-
"Publishing to '\(registryURL)' requires metadata file but none was found at '\(metadataPath)'."
138-
)
139-
}
140-
141-
let publishConfiguration = RegistryClient.PublishConfiguration(
137+
let publishConfiguration = PublishConfiguration(
138+
metadataLocation: self.customMetadataPath
139+
.flatMap { .external($0) } ??
140+
.sourceTree(packageDirectory.appending(component: Self.metadataFilename)),
142141
signing: .init(
143142
required: self.signingIdentity != nil || self.privateKeyPath != nil,
144-
acceptedSignatureFormats: [.CMS_1_0_0],
145-
trustedRootCertificates: []
143+
format: self.signatureFormat,
144+
signingIdentity: self.signingIdentity,
145+
privateKeyPath: self.privateKeyPath,
146+
certificateChainPaths: self.certificateChainPaths
146147
)
147148
)
148149

149-
// step 2: generate source archive for the package release
150+
guard localFileSystem.exists(publishConfiguration.metadataLocation.path) else {
151+
throw StringError(
152+
"Publishing to '\(registryURL)' requires metadata file but none was found at '\(publishConfiguration.metadataLocation)'."
153+
)
154+
}
155+
156+
if publishConfiguration.signing.privateKeyPath == nil {
157+
guard !publishConfiguration.signing.certificateChainPaths.isEmpty else {
158+
throw StringError(
159+
"Both 'privateKeyPath' and 'certificateChainPaths' are required when one of them is set."
160+
)
161+
}
162+
} else {
163+
guard publishConfiguration.signing.certificateChainPaths.isEmpty else {
164+
throw StringError(
165+
"Both 'privateKeyPath' and 'certificateChainPaths' are required when one of them is set."
166+
)
167+
}
168+
}
150169

170+
// step 2: generate source archive for the package release
151171
swiftTool.observabilityScope.emit(info: "archiving the source at '\(packageDirectory)'")
152172
let archivePath = try self.archiveSource(
153173
packageIdentity: self.packageIdentity,
@@ -164,14 +184,19 @@ extension SwiftPackageRegistryTool {
164184
swiftTool.observabilityScope.emit(info: "signing the archive at '\(archivePath)'")
165185
signature = try self.sign(
166186
archivePath: archivePath,
167-
signatureFormat: self.signatureFormat,
168-
signingIdentity: self.signingIdentity,
169-
privateKeyPath: self.privateKeyPath,
187+
configuration: publishConfiguration.signing,
170188
observabilityScope: swiftTool.observabilityScope
171189
)
172190
}
173191

174192
// step 4: publish the package
193+
guard !self.dryRun else {
194+
print(
195+
"\(packageIdentity)@\(packageVersion) was successfully prepared for publishing but was not published due to dry run flag. artifacts available at '\(workingDirectory)'."
196+
)
197+
return
198+
}
199+
175200
swiftTool.observabilityScope
176201
.emit(info: "publishing '\(self.packageIdentity)' archive at '\(archivePath)' to '\(registryURL)'")
177202
// TODO: handle signature
@@ -194,9 +219,13 @@ extension SwiftPackageRegistryTool {
194219
case .published(.none):
195220
print("\(packageIdentity)@\(packageVersion) was successfully published to \(registryURL)")
196221
case .published(.some(let location)):
197-
print("\(packageIdentity)@\(packageVersion) was successfully published to \(registryURL) and is available at \(location)")
222+
print(
223+
"\(packageIdentity)@\(packageVersion) was successfully published to \(registryURL) and is available at \(location)"
224+
)
198225
case .processing(let statusURL, _):
199-
print("\(packageIdentity)@\(packageVersion) was successfully submitted to \(registryURL) and is being processed. Publishing status is available at \(statusURL)")
226+
print(
227+
"\(packageIdentity)@\(packageVersion) was successfully submitted to \(registryURL) and is being processed. Publishing status is available at \(statusURL)"
228+
)
200229
}
201230
}
202231

@@ -236,16 +265,41 @@ extension SwiftPackageRegistryTool {
236265

237266
func sign(
238267
archivePath: AbsolutePath,
239-
signatureFormat: SignatureFormat,
240-
signingIdentity: String?,
241-
privateKeyPath: AbsolutePath?,
268+
configuration: PublishConfiguration.Signing,
242269
observabilityScope: ObservabilityScope
243270
) throws -> Data {
244271
fatalError("not implemented")
245272
}
246273
}
247274
}
248275

276+
struct PublishConfiguration {
277+
let metadataLocation: MetadataLocation
278+
let signing: Signing
279+
280+
enum MetadataLocation {
281+
case sourceTree(AbsolutePath)
282+
case external(AbsolutePath)
283+
284+
var path: AbsolutePath {
285+
switch self {
286+
case .sourceTree(let path):
287+
return path
288+
case .external(let path):
289+
return path
290+
}
291+
}
292+
}
293+
294+
struct Signing {
295+
let required: Bool
296+
let format: SignatureFormat
297+
var signingIdentity: String?
298+
var privateKeyPath: AbsolutePath?
299+
var certificateChainPaths: [AbsolutePath]
300+
}
301+
}
302+
249303
enum SignatureFormat: ExpressibleByArgument {
250304
case CMS_1_0_0
251305

0 commit comments

Comments
 (0)