@@ -33,13 +33,13 @@ extension SwiftPackageRegistryTool {
33
33
@OptionGroup ( visibility: . hidden)
34
34
var globalOptions : GlobalOptions
35
35
36
- @Option ( name: . customLong( " id " ) , help: " The package identity " )
36
+ @Option ( name: [ . customLong( " id " ) , . customLong ( " package-id " ) ] , help: " The package identity " )
37
37
var packageIdentity : PackageIdentity
38
38
39
- @Option ( name: . customLong( " version " ) , help: " The package version " )
39
+ @Option ( name: [ . customLong( " version " ) , . customLong ( " package-version " ) ] , help: " The package version " )
40
40
var packageVersion : Version
41
41
42
- @Option ( name: . customLong( " url " ) , help: " The registry URL " )
42
+ @Option ( name: [ . customLong( " url " ) , . customLong ( " registry-url " ) ] , help: " The registry URL " )
43
43
var registryURL : URL ?
44
44
45
45
@Option (
@@ -66,7 +66,7 @@ extension SwiftPackageRegistryTool {
66
66
@Option (
67
67
help: " Paths to all of the certificates (DER-encoded) in the chain. The certificate used for signing must be listed first and the root certificate last. "
68
68
)
69
- var certificateChainPaths : [ AbsolutePath ]
69
+ var certificateChainPaths : [ AbsolutePath ] = [ ]
70
70
71
71
func run( _ swiftTool: SwiftTool ) throws {
72
72
let configuration = try getRegistriesConfig ( swiftTool) . configuration
@@ -106,6 +106,12 @@ extension SwiftPackageRegistryTool {
106
106
}
107
107
}
108
108
109
+ let workingDirectory = customWorkingDirectory ?? Workspace . DefaultLocations
110
+ . scratchDirectory ( forRootPackage: packageDirectory) . appending ( components: [ " registry " , " publish " ] )
111
+ if localFileSystem. exists ( workingDirectory) {
112
+ try localFileSystem. removeFileTree ( workingDirectory)
113
+ }
114
+
109
115
// validate custom metadata path
110
116
if let customMetadataPath = self . customMetadataPath {
111
117
guard localFileSystem. exists ( customMetadataPath) else {
@@ -124,39 +130,37 @@ extension SwiftPackageRegistryTool {
124
130
authorizationProvider: authorizationProvider
125
131
)
126
132
127
- // step 1: get registry publishing requirements
128
- swiftTool. observabilityScope. emit ( info: " retrieving ' \( registryURL) ' publishing requirements " )
129
- let publishRequirements = try tsc_await { callback in
130
- registryClient. getPublishRequirements (
131
- registryURL: registryURL,
132
- observabilityScope: swiftTool. observabilityScope,
133
- callbackQueue: . sharedConcurrent,
134
- completion: callback
135
- )
136
- }
137
-
138
- // step 2: generate source archive for the package release
133
+ // step 1: publishing configuration
139
134
let metadataPath = self . customMetadataPath ?? packageDirectory. appending ( component: Self . metadataFilename)
140
135
guard localFileSystem. exists ( metadataPath) else {
141
136
throw StringError (
142
137
" Publishing to ' \( registryURL) ' requires metadata file but none was found at ' \( metadataPath) '. "
143
138
)
144
139
}
145
140
141
+ let publishConfiguration = RegistryClient . PublishConfiguration (
142
+ signing: . init(
143
+ required: self . signingIdentity != nil || self . privateKeyPath != nil ,
144
+ acceptedSignatureFormats: [ . CMS_1_0_0] ,
145
+ trustedRootCertificates: [ ]
146
+ )
147
+ )
148
+
149
+ // step 2: generate source archive for the package release
150
+
146
151
swiftTool. observabilityScope. emit ( info: " archiving the source at ' \( packageDirectory) ' " )
147
152
let archivePath = try self . archiveSource (
148
153
packageIdentity: self . packageIdentity,
149
154
packageVersion: self . packageVersion,
150
155
packageDirectory: packageDirectory,
151
- metadataPath: publishRequirements. metadata. location. contains ( . archive) ? metadataPath : . none,
152
- customWorkingDirectory: self . customWorkingDirectory,
156
+ workingDirectory: workingDirectory,
153
157
cancellator: swiftTool. cancellator,
154
158
observabilityScope: swiftTool. observabilityScope
155
159
)
156
160
157
161
// step 3: sign the source archive if needed
158
162
var signature : Data ? = . none
159
- if publishRequirements . signing. required {
163
+ if publishConfiguration . signing. required {
160
164
swiftTool. observabilityScope. emit ( info: " signing the archive at ' \( archivePath) ' " )
161
165
signature = try self . sign (
162
166
archivePath: archivePath,
@@ -177,7 +181,7 @@ extension SwiftPackageRegistryTool {
177
181
packageIdentity: self . packageIdentity,
178
182
packageVersion: self . packageVersion,
179
183
packageArchive: archivePath,
180
- packageMetadata: publishRequirements . metadata . location . contains ( . request ) ? metadataPath : . none ,
184
+ packageMetadata: self . customMetadataPath ,
181
185
signature: signature,
182
186
fileSystem: localFileSystem,
183
187
observabilityScope: swiftTool. observabilityScope,
@@ -200,14 +204,10 @@ extension SwiftPackageRegistryTool {
200
204
packageIdentity: PackageIdentity ,
201
205
packageVersion: Version ,
202
206
packageDirectory: AbsolutePath ,
203
- metadataPath: AbsolutePath ? ,
204
- customWorkingDirectory: AbsolutePath ? ,
207
+ workingDirectory: AbsolutePath ,
205
208
cancellator: Cancellator ? ,
206
209
observabilityScope: ObservabilityScope
207
210
) throws -> AbsolutePath {
208
- let workingDirectory = customWorkingDirectory ?? Workspace . DefaultLocations
209
- . scratchDirectory ( forRootPackage: packageDirectory) . appending ( components: [ " registry " , " publish " ] )
210
-
211
211
let archivePath = workingDirectory. appending ( component: " \( packageIdentity) - \( packageVersion) .zip " )
212
212
213
213
// create temp location for sources
@@ -224,16 +224,6 @@ extension SwiftPackageRegistryTool {
224
224
)
225
225
}
226
226
227
- // include metadata from non-standard location in the archive
228
- if let metadataPath = metadataPath,
229
- metadataPath != packageDirectory. appending ( component: Self . metadataFilename)
230
- {
231
- try localFileSystem. copy (
232
- from: metadataPath,
233
- to: sourceDirectory. appending ( component: Self . metadataFilename)
234
- )
235
- }
236
-
237
227
try SwiftPackageTool . archiveSource (
238
228
at: sourceDirectory,
239
229
to: archivePath,
0 commit comments