@git.zone/cli 12.1.1 → 12.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/templates/npm/.package.json +1 -1
- package/assets/templates/service/.package.json +1 -1
- package/assets/templates/wcc/.package.json +1 -1
- package/assets/templates/website/.package.json +1 -1
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/helpers.tssea.d.ts +2 -7
- package/dist_ts/helpers.tssea.js +20 -10
- package/dist_ts/helpers.versionsource.d.ts +23 -5
- package/dist_ts/helpers.versionsource.js +115 -37
- package/dist_ts/helpers.workflow.d.ts +60 -17
- package/dist_ts/helpers.workflow.js +156 -51
- package/dist_ts/mod_config/index.js +98 -31
- package/dist_ts/mod_release/classes.releasejournal.d.ts +63 -8
- package/dist_ts/mod_release/classes.releasejournal.js +283 -124
- package/dist_ts/mod_release/helpers.cargorelease.d.ts +4 -3
- package/dist_ts/mod_release/helpers.cargorelease.js +5 -4
- package/dist_ts/mod_release/helpers.fossglobalassets.d.ts +61 -0
- package/dist_ts/mod_release/helpers.fossglobalassets.js +580 -0
- package/dist_ts/mod_release/helpers.giteaassets.d.ts +15 -51
- package/dist_ts/mod_release/helpers.giteaassets.js +40 -507
- package/dist_ts/mod_release/helpers.releaseassets.d.ts +40 -0
- package/dist_ts/mod_release/helpers.releaseassets.js +349 -0
- package/dist_ts/mod_release/helpers.releaseassettransfer.d.ts +67 -0
- package/dist_ts/mod_release/helpers.releaseassettransfer.js +239 -0
- package/dist_ts/mod_release/helpers.releasecheck.js +3 -2
- package/dist_ts/mod_release/helpers.releasepreparation.d.ts +7 -6
- package/dist_ts/mod_release/helpers.releasepreparation.js +34 -7
- package/dist_ts/mod_release/helpers.releasepublication.d.ts +8 -2
- package/dist_ts/mod_release/helpers.releasepublication.js +218 -54
- package/dist_ts/mod_release/helpers.releaseversionsource.d.ts +7 -5
- package/dist_ts/mod_release/helpers.releaseversionsource.js +9 -7
- package/dist_ts/mod_release/index.d.ts +1 -1
- package/dist_ts/mod_release/index.js +109 -68
- package/dist_ts/mod_release/interfaces.fossglobalassets.d.ts +108 -0
- package/dist_ts/mod_release/interfaces.fossglobalassets.js +2 -0
- package/dist_ts/mod_release/interfaces.giteaassets.d.ts +9 -43
- package/dist_ts/mod_release/interfaces.releaseassets.d.ts +68 -0
- package/dist_ts/mod_release/interfaces.releaseassets.js +2 -0
- package/dist_ts/plugins.d.ts +1 -0
- package/dist_ts/plugins.js +1 -1
- package/package.json +3 -2
- package/readme.md +339 -41
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/helpers.tssea.ts +31 -10
- package/ts/helpers.versionsource.ts +176 -45
- package/ts/helpers.workflow.ts +288 -78
- package/ts/mod_config/index.ts +130 -38
- package/ts/mod_release/classes.releasejournal.ts +499 -180
- package/ts/mod_release/helpers.cargorelease.ts +8 -3
- package/ts/mod_release/helpers.fossglobalassets.ts +886 -0
- package/ts/mod_release/helpers.giteaassets.ts +127 -694
- package/ts/mod_release/helpers.releaseassets.ts +516 -0
- package/ts/mod_release/helpers.releaseassettransfer.ts +339 -0
- package/ts/mod_release/helpers.releasecheck.ts +3 -1
- package/ts/mod_release/helpers.releasepreparation.ts +55 -12
- package/ts/mod_release/helpers.releasepublication.ts +351 -69
- package/ts/mod_release/helpers.releaseversionsource.ts +11 -7
- package/ts/mod_release/index.ts +151 -90
- package/ts/mod_release/interfaces.fossglobalassets.ts +127 -0
- package/ts/mod_release/interfaces.giteaassets.ts +14 -47
- package/ts/mod_release/interfaces.releaseassets.ts +96 -0
- package/ts/plugins.ts +3 -0
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import {
|
|
2
|
+
releaseAssetTargets,
|
|
3
|
+
type TReleaseAssetFileHandle,
|
|
4
|
+
} from "./helpers.releaseassets.js";
|
|
5
|
+
import type {
|
|
6
|
+
IReleaseAssetTransferFailures,
|
|
7
|
+
IReleaseAssetTransferLimits,
|
|
8
|
+
TReleaseAssetRequestFailureReason,
|
|
9
|
+
TReleaseAssetTargetName,
|
|
10
|
+
TReleaseAssetTransferDirection,
|
|
11
|
+
} from "./interfaces.releaseassets.js";
|
|
12
|
+
|
|
13
|
+
/** A duration as transfer messages print it: seconds with one decimal. */
|
|
14
|
+
export const formatReleaseAssetSeconds = (milliseconds: number): string =>
|
|
15
|
+
`${Math.round(milliseconds / 100) / 10} s`;
|
|
16
|
+
|
|
17
|
+
const requestFailurePhrases: Readonly<
|
|
18
|
+
Record<TReleaseAssetRequestFailureReason, (label: string) => string>
|
|
19
|
+
> = Object.freeze({
|
|
20
|
+
"oversized-response": (label) => `Oversized ${label} response.`,
|
|
21
|
+
"missing-response-body": (label) => `Missing ${label} response body.`,
|
|
22
|
+
"asset-changed-during-upload": (label) =>
|
|
23
|
+
`${label} asset changed during upload.`,
|
|
24
|
+
"asset-not-downloadable": () => "Asset is not downloadable.",
|
|
25
|
+
"asset-not-anonymously-downloadable": () =>
|
|
26
|
+
"Asset is not anonymously downloadable.",
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A request failure gitzone detected itself. Its message is the target's
|
|
31
|
+
* label in the fixed phrase of its reason and nothing else, so it carries no
|
|
32
|
+
* URL, header, body or token, and a request failure description prints it in
|
|
33
|
+
* full. The name stays `Error`; the message says what failed.
|
|
34
|
+
*/
|
|
35
|
+
export class ReleaseAssetRequestError extends Error {
|
|
36
|
+
constructor(
|
|
37
|
+
target: TReleaseAssetTargetName,
|
|
38
|
+
readonly reason: TReleaseAssetRequestFailureReason,
|
|
39
|
+
) {
|
|
40
|
+
super(requestFailurePhrases[reason](releaseAssetTargets[target].label));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const safeErrorName = /^[A-Za-z][A-Za-z0-9]{0,63}$/;
|
|
45
|
+
const safeErrorCode = /^[A-Z][A-Z0-9_]{1,63}$/;
|
|
46
|
+
/** Plain words only: no digit, colon, slash or dot inside can carry a URL or token. */
|
|
47
|
+
const safeErrorMessage = /^[A-Za-z][A-Za-z ]{0,79}\.?$/;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Names why a request ended: the HTTP status it reached, each error of the
|
|
51
|
+
* cause chain by name and code, and how far the transfer got. A message is
|
|
52
|
+
* printed in full when gitzone raised it (a ReleaseAssetRequestError);
|
|
53
|
+
* any other error's message only when it is plain words ("terminated",
|
|
54
|
+
* "fetch failed", "other side closed"), since its text may carry a URL.
|
|
55
|
+
*/
|
|
56
|
+
export const describeReleaseAssetRequestFailure = (
|
|
57
|
+
error: unknown,
|
|
58
|
+
evidence: { status?: number; progress: string },
|
|
59
|
+
): string => {
|
|
60
|
+
const parts: string[] = [];
|
|
61
|
+
if (evidence.status !== undefined) parts.push(`HTTP ${evidence.status}`);
|
|
62
|
+
let current = error;
|
|
63
|
+
for (let depth = 0; depth < 4 && current instanceof Error; depth++) {
|
|
64
|
+
const name = safeErrorName.test(current.name) ? current.name : "Error";
|
|
65
|
+
const code = (current as NodeJS.ErrnoException).code;
|
|
66
|
+
const codeText =
|
|
67
|
+
typeof code === "string" && safeErrorCode.test(code) ? ` [${code}]` : "";
|
|
68
|
+
const messageText =
|
|
69
|
+
current instanceof ReleaseAssetRequestError ||
|
|
70
|
+
safeErrorMessage.test(current.message)
|
|
71
|
+
? `: ${current.message}`
|
|
72
|
+
: "";
|
|
73
|
+
parts.push(`${name}${codeText}${messageText}`);
|
|
74
|
+
current = current.cause;
|
|
75
|
+
}
|
|
76
|
+
parts.push(evidence.progress);
|
|
77
|
+
return `(${parts.join("; ")})`;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const defaultReleaseAssetTransferLimits: Readonly<IReleaseAssetTransferLimits> =
|
|
81
|
+
Object.freeze({
|
|
82
|
+
responseTimeoutMs: 2 * 60_000,
|
|
83
|
+
stallTimeoutMs: 60_000,
|
|
84
|
+
minimumBytesPerSecond: 256 * 1024,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const maximumTransferTimeoutMs = 60 * 60_000;
|
|
88
|
+
const maximumBytesPerSecond = 1024 * 1024 * 1024;
|
|
89
|
+
/** Node fires longer timers immediately; a ceiling this far out never binds. */
|
|
90
|
+
const maximumTimerMs = 2_147_483_647;
|
|
91
|
+
|
|
92
|
+
export const assertReleaseAssetTransferLimits = (
|
|
93
|
+
target: TReleaseAssetTargetName,
|
|
94
|
+
limits: IReleaseAssetTransferLimits,
|
|
95
|
+
): IReleaseAssetTransferLimits => {
|
|
96
|
+
const { label } = releaseAssetTargets[target];
|
|
97
|
+
for (const value of [limits.responseTimeoutMs, limits.stallTimeoutMs])
|
|
98
|
+
if (
|
|
99
|
+
!Number.isSafeInteger(value) ||
|
|
100
|
+
value <= 0 ||
|
|
101
|
+
value > maximumTransferTimeoutMs
|
|
102
|
+
)
|
|
103
|
+
throw new Error(`Invalid ${label} asset request timeout.`);
|
|
104
|
+
if (
|
|
105
|
+
!Number.isSafeInteger(limits.minimumBytesPerSecond) ||
|
|
106
|
+
limits.minimumBytesPerSecond <= 0 ||
|
|
107
|
+
limits.minimumBytesPerSecond > maximumBytesPerSecond
|
|
108
|
+
)
|
|
109
|
+
throw new Error(`Invalid ${label} asset minimum transfer rate.`);
|
|
110
|
+
return limits;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
type TWatchdogPhase = "response" | "stall" | "acknowledgement";
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Bounds one request by progress instead of wall-clock time: the response
|
|
117
|
+
* bound covers waiting for headers, the stall bound restarts on every byte,
|
|
118
|
+
* an upload's acknowledgement wait scales with its size, and a ceiling of
|
|
119
|
+
* expected bytes at the rate floor ends a trickle. The target's failures
|
|
120
|
+
* name the bound that ended it.
|
|
121
|
+
*/
|
|
122
|
+
export class ReleaseAssetTransferWatchdog<TFailure extends Error> {
|
|
123
|
+
readonly #controller = new AbortController();
|
|
124
|
+
readonly #started = Date.now();
|
|
125
|
+
readonly #ceiling: NodeJS.Timeout;
|
|
126
|
+
/** Servers process and store a large upload before answering; allow its size at the floor. */
|
|
127
|
+
readonly #acknowledgementMs: number;
|
|
128
|
+
#timer: NodeJS.Timeout | undefined;
|
|
129
|
+
#phase: TWatchdogPhase | undefined;
|
|
130
|
+
#direction: TReleaseAssetTransferDirection = "sent";
|
|
131
|
+
#bytes = 0;
|
|
132
|
+
#failure: TFailure | undefined;
|
|
133
|
+
/** A late body pull or chunk after close must never re-arm a timer. */
|
|
134
|
+
#closed = false;
|
|
135
|
+
|
|
136
|
+
constructor(
|
|
137
|
+
private readonly failures: IReleaseAssetTransferFailures<TFailure>,
|
|
138
|
+
private readonly operation: string,
|
|
139
|
+
private readonly limits: IReleaseAssetTransferLimits,
|
|
140
|
+
/** Bytes the request moves in total, including an upload body. */
|
|
141
|
+
private readonly expectedBytes: number,
|
|
142
|
+
private readonly uploadBytes = 0,
|
|
143
|
+
) {
|
|
144
|
+
const atFloor = (bytes: number) =>
|
|
145
|
+
Math.ceil((bytes * 1000) / limits.minimumBytesPerSecond);
|
|
146
|
+
this.#acknowledgementMs = Math.max(
|
|
147
|
+
limits.responseTimeoutMs,
|
|
148
|
+
atFloor(uploadBytes),
|
|
149
|
+
);
|
|
150
|
+
const ceilingMs = Math.min(
|
|
151
|
+
maximumTimerMs,
|
|
152
|
+
limits.responseTimeoutMs +
|
|
153
|
+
limits.stallTimeoutMs +
|
|
154
|
+
atFloor(expectedBytes) +
|
|
155
|
+
(uploadBytes ? this.#acknowledgementMs : 0),
|
|
156
|
+
);
|
|
157
|
+
this.#ceiling = setTimeout(
|
|
158
|
+
() =>
|
|
159
|
+
this.#fail(
|
|
160
|
+
failures.tooSlow(
|
|
161
|
+
operation,
|
|
162
|
+
Date.now() - this.#started,
|
|
163
|
+
this.#bytes,
|
|
164
|
+
expectedBytes,
|
|
165
|
+
limits.minimumBytesPerSecond,
|
|
166
|
+
),
|
|
167
|
+
),
|
|
168
|
+
ceilingMs,
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
get signal(): AbortSignal {
|
|
173
|
+
return this.#controller.signal;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
get failure(): TFailure | undefined {
|
|
177
|
+
return this.#failure;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Bytes sent and received so far. */
|
|
181
|
+
get bytes(): number {
|
|
182
|
+
return this.#bytes;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Wait for response headers; every redirect hop starts a new wait. */
|
|
186
|
+
awaitResponse(): void {
|
|
187
|
+
this.#arm("response");
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** The whole upload body is sent; wait for the server to store and answer it. */
|
|
191
|
+
awaitAcknowledgement(): void {
|
|
192
|
+
this.#arm("acknowledgement");
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** Record moved bytes; the stall bound restarts from this moment. */
|
|
196
|
+
progress(direction: TReleaseAssetTransferDirection, bytes: number): void {
|
|
197
|
+
if (this.#closed) return;
|
|
198
|
+
this.#direction = direction;
|
|
199
|
+
this.#bytes += bytes;
|
|
200
|
+
this.#arm("stall");
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
close(): void {
|
|
204
|
+
this.#closed = true;
|
|
205
|
+
clearTimeout(this.#ceiling);
|
|
206
|
+
clearTimeout(this.#timer);
|
|
207
|
+
this.#controller.abort();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
#arm(phase: TWatchdogPhase): void {
|
|
211
|
+
if (this.#failure || this.#closed) return;
|
|
212
|
+
if (this.#timer && this.#phase === phase) {
|
|
213
|
+
this.#timer.refresh();
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
clearTimeout(this.#timer);
|
|
217
|
+
this.#phase = phase;
|
|
218
|
+
const bounds: Record<TWatchdogPhase, [number, () => TFailure]> = {
|
|
219
|
+
response: [
|
|
220
|
+
this.limits.responseTimeoutMs,
|
|
221
|
+
() =>
|
|
222
|
+
this.failures.responseTimeout(
|
|
223
|
+
this.operation,
|
|
224
|
+
this.limits.responseTimeoutMs,
|
|
225
|
+
),
|
|
226
|
+
],
|
|
227
|
+
stall: [
|
|
228
|
+
this.limits.stallTimeoutMs,
|
|
229
|
+
() =>
|
|
230
|
+
this.failures.stalled(
|
|
231
|
+
this.operation,
|
|
232
|
+
this.#direction,
|
|
233
|
+
this.limits.stallTimeoutMs,
|
|
234
|
+
this.#bytes,
|
|
235
|
+
),
|
|
236
|
+
],
|
|
237
|
+
acknowledgement: [
|
|
238
|
+
this.#acknowledgementMs,
|
|
239
|
+
() =>
|
|
240
|
+
this.failures.notAcknowledged(
|
|
241
|
+
this.uploadBytes,
|
|
242
|
+
this.#acknowledgementMs,
|
|
243
|
+
this.limits.minimumBytesPerSecond,
|
|
244
|
+
),
|
|
245
|
+
],
|
|
246
|
+
};
|
|
247
|
+
const [milliseconds, failure] = bounds[phase];
|
|
248
|
+
this.#timer = setTimeout(
|
|
249
|
+
() => this.#fail(failure()),
|
|
250
|
+
Math.min(maximumTimerMs, milliseconds),
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
#fail(error: TFailure): void {
|
|
255
|
+
if (this.#failure) return;
|
|
256
|
+
this.#failure = error;
|
|
257
|
+
clearTimeout(this.#ceiling);
|
|
258
|
+
clearTimeout(this.#timer);
|
|
259
|
+
this.#controller.abort();
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Streams exactly `size` bytes of the open file as a request body, pulled: the
|
|
265
|
+
* next chunk is read only when fetch has taken the last one, so progress means
|
|
266
|
+
* bytes the transport accepted. Sent with a `Content-Length` header, fetch
|
|
267
|
+
* (undici) writes that fixed length, never chunked transfer encoding, and
|
|
268
|
+
* fails the request when the body yields more or fewer bytes.
|
|
269
|
+
*/
|
|
270
|
+
export const createReleaseAssetUploadBody = <TFailure extends Error>(
|
|
271
|
+
target: TReleaseAssetTargetName,
|
|
272
|
+
handle: TReleaseAssetFileHandle,
|
|
273
|
+
size: number,
|
|
274
|
+
watchdog: ReleaseAssetTransferWatchdog<TFailure>,
|
|
275
|
+
): ReadableStream<Uint8Array> => {
|
|
276
|
+
let position = 0;
|
|
277
|
+
return new ReadableStream<Uint8Array>(
|
|
278
|
+
{
|
|
279
|
+
pull: async (controller) => {
|
|
280
|
+
if (position === size) {
|
|
281
|
+
watchdog.awaitAcknowledgement();
|
|
282
|
+
controller.close();
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
const chunk = Buffer.allocUnsafe(Math.min(64 * 1024, size - position));
|
|
286
|
+
const { bytesRead } = await handle.read(
|
|
287
|
+
chunk,
|
|
288
|
+
0,
|
|
289
|
+
chunk.length,
|
|
290
|
+
position,
|
|
291
|
+
);
|
|
292
|
+
if (bytesRead === 0)
|
|
293
|
+
throw new ReleaseAssetRequestError(
|
|
294
|
+
target,
|
|
295
|
+
"asset-changed-during-upload",
|
|
296
|
+
);
|
|
297
|
+
position += bytesRead;
|
|
298
|
+
watchdog.progress("sent", bytesRead);
|
|
299
|
+
controller.enqueue(chunk.subarray(0, bytesRead));
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
{ highWaterMark: 0 },
|
|
303
|
+
);
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
/** Reads a whole response body of at most `maximum` bytes; every chunk is progress. */
|
|
307
|
+
export const readReleaseAssetResponse = async <TFailure extends Error>(
|
|
308
|
+
target: TReleaseAssetTargetName,
|
|
309
|
+
response: Response,
|
|
310
|
+
maximum: number,
|
|
311
|
+
watchdog: ReleaseAssetTransferWatchdog<TFailure>,
|
|
312
|
+
): Promise<Buffer> => {
|
|
313
|
+
if (!response.body)
|
|
314
|
+
throw new ReleaseAssetRequestError(target, "missing-response-body");
|
|
315
|
+
const declared = response.headers.get("content-length");
|
|
316
|
+
if (
|
|
317
|
+
declared !== null &&
|
|
318
|
+
(!/^\d+$/.test(declared) || Number(declared) > maximum)
|
|
319
|
+
)
|
|
320
|
+
throw new ReleaseAssetRequestError(target, "oversized-response");
|
|
321
|
+
const reader = response.body.getReader();
|
|
322
|
+
const chunks: Buffer[] = [];
|
|
323
|
+
let size = 0;
|
|
324
|
+
try {
|
|
325
|
+
while (true) {
|
|
326
|
+
const result = await reader.read();
|
|
327
|
+
if (result.done) break;
|
|
328
|
+
watchdog.progress("received", result.value.byteLength);
|
|
329
|
+
size += result.value.byteLength;
|
|
330
|
+
if (size > maximum)
|
|
331
|
+
throw new ReleaseAssetRequestError(target, "oversized-response");
|
|
332
|
+
chunks.push(Buffer.from(result.value));
|
|
333
|
+
}
|
|
334
|
+
} finally {
|
|
335
|
+
await reader.cancel().catch(() => undefined);
|
|
336
|
+
reader.releaseLock();
|
|
337
|
+
}
|
|
338
|
+
return Buffer.concat(chunks, size);
|
|
339
|
+
};
|
|
@@ -107,6 +107,8 @@ const notCheckedReasons: Partial<Record<TReleaseTarget, string>> = {
|
|
|
107
107
|
"tSDocker builds and qualifies the images during the release; `release check` packs no image",
|
|
108
108
|
giteaAssets:
|
|
109
109
|
"the Gitea asset manifest is frozen during the release; `release check` uploads and freezes nothing",
|
|
110
|
+
fossglobalAssets:
|
|
111
|
+
"the foss.global asset manifest is frozen during the release; `release check` uploads and freezes nothing",
|
|
110
112
|
};
|
|
111
113
|
|
|
112
114
|
/**
|
|
@@ -330,7 +332,7 @@ export const runReleaseCheck = async (
|
|
|
330
332
|
repositoryCwd: optionsArg.cwd,
|
|
331
333
|
mainOid: report.sourceOid,
|
|
332
334
|
...(workflow.runBuild ? { buildCommand: workflow.buildCommand } : {}),
|
|
333
|
-
cargo: workflow.
|
|
335
|
+
cargo: workflow.cargoWorkspace,
|
|
334
336
|
},
|
|
335
337
|
async (checkout) => {
|
|
336
338
|
if (report.build) report.build.passed = true;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import * as plugins from "./mod.plugins.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
IResolvedReleaseWorkflow,
|
|
4
|
+
TReleaseCargoWorkspace,
|
|
5
|
+
} from "../helpers.workflow.js";
|
|
6
|
+
import {
|
|
7
|
+
findInternalRustWorkspaceDirectory,
|
|
8
|
+
internalRustWorkspaceDirectories,
|
|
9
|
+
} from "../helpers.versionsource.js";
|
|
3
10
|
import { logger } from "../gitzone.logging.js";
|
|
4
11
|
import { readPendingChangelog } from "../helpers.changelog.js";
|
|
5
12
|
import { InterProcessLock } from "../mod_services/classes.interprocesslock.js";
|
|
@@ -363,10 +370,45 @@ const fetchLockedCargoDependencies = async (
|
|
|
363
370
|
);
|
|
364
371
|
};
|
|
365
372
|
|
|
373
|
+
/**
|
|
374
|
+
* The directory of the versioned Cargo workspace in a commit, relative to the
|
|
375
|
+
* project and ending in `/` (empty for the root workspace): the root for
|
|
376
|
+
* projectType "rust", otherwise the first of `rust/` and `ts_rust/` the commit
|
|
377
|
+
* carries a Cargo.toml in, the order rsrepo discovers them in.
|
|
378
|
+
*/
|
|
379
|
+
const findCommittedCargoWorkspace = async (
|
|
380
|
+
options: IReleaseSourceCommit,
|
|
381
|
+
workspaceArg: TReleaseCargoWorkspace,
|
|
382
|
+
): Promise<string> => {
|
|
383
|
+
if (workspaceArg === "root") return "";
|
|
384
|
+
for (const directory of internalRustWorkspaceDirectories) {
|
|
385
|
+
if (await commitCarriesBlob(options, `${directory}/Cargo.toml`))
|
|
386
|
+
return `${directory}/`;
|
|
387
|
+
}
|
|
388
|
+
throw new Error(
|
|
389
|
+
`The release versions the internal Cargo workspace, but commit ${options.sourceOid} carries no rust/Cargo.toml or ts_rust/Cargo.toml. Commit the workspace — it must not be ignored — and release again.`,
|
|
390
|
+
);
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
/** The versioned Cargo workspace of a checkout that holds exactly one commit. */
|
|
394
|
+
const findCheckoutCargoWorkspace = async (
|
|
395
|
+
checkoutArg: string,
|
|
396
|
+
workspaceArg: TReleaseCargoWorkspace,
|
|
397
|
+
): Promise<string> => {
|
|
398
|
+
if (workspaceArg === "root") return checkoutArg;
|
|
399
|
+
const directory = await findInternalRustWorkspaceDirectory(checkoutArg);
|
|
400
|
+
if (!directory)
|
|
401
|
+
throw new Error(
|
|
402
|
+
"The release checkout carries no rust/Cargo.toml or ts_rust/Cargo.toml, but the release versions the internal Cargo workspace.",
|
|
403
|
+
);
|
|
404
|
+
return plugins.path.join(checkoutArg, directory);
|
|
405
|
+
};
|
|
406
|
+
|
|
366
407
|
/**
|
|
367
408
|
* The isolated release checkout installs with `pnpm install --frozen-lockfile`
|
|
368
409
|
* when the release commit carries a package.json, and fetches with
|
|
369
|
-
* `cargo fetch --locked`
|
|
410
|
+
* `cargo fetch --locked` in the Cargo workspace that carries the release
|
|
411
|
+
* version, at the root or in `rust/` or `ts_rust/`. A manifest or
|
|
370
412
|
* lockfile that the release commit does not carry, or a lockfile that no
|
|
371
413
|
* longer matches its manifest, would fail a release that already created its
|
|
372
414
|
* commit and tag, so preflight proves them before anything is created. The
|
|
@@ -381,15 +423,16 @@ const fetchLockedCargoDependencies = async (
|
|
|
381
423
|
*/
|
|
382
424
|
export const assertReleaseCheckoutInstallable = async (
|
|
383
425
|
options: IReleaseSourceCommit & {
|
|
384
|
-
/**
|
|
385
|
-
cargo
|
|
426
|
+
/** The Cargo workspace that carries the version, if any. */
|
|
427
|
+
cargo?: TReleaseCargoWorkspace;
|
|
386
428
|
},
|
|
387
429
|
): Promise<void> => {
|
|
388
430
|
if (options.cargo) {
|
|
431
|
+
const directory = await findCommittedCargoWorkspace(options, options.cargo);
|
|
389
432
|
for (const file of ["Cargo.toml", cargoLockfileName]) {
|
|
390
|
-
if (!(await commitCarriesBlob(options, file))) {
|
|
433
|
+
if (!(await commitCarriesBlob(options, `${directory}${file}`))) {
|
|
391
434
|
throw new Error(
|
|
392
|
-
`The release fetches the locked Cargo dependencies of its release commit with \`cargo fetch --locked\`, but commit ${options.sourceOid} carries no root ${file}. Commit it — it must not be ignored — and release again.`,
|
|
435
|
+
`The release fetches the locked Cargo dependencies of its release commit with \`cargo fetch --locked\`, but commit ${options.sourceOid} carries no ${directory ? `${directory}${file}` : `root ${file}`}. Commit it — it must not be ignored — and release again.`,
|
|
393
436
|
);
|
|
394
437
|
}
|
|
395
438
|
}
|
|
@@ -399,8 +442,8 @@ export const assertReleaseCheckoutInstallable = async (
|
|
|
399
442
|
);
|
|
400
443
|
await fetchLockedCargoDependencies(
|
|
401
444
|
options.smartshell,
|
|
402
|
-
options.cwd,
|
|
403
|
-
`\`cargo fetch --locked\` rejects the committed ${cargoLockfileName}, so the release checkout could not fetch it. Run \`cargo update --workspace\`, commit the updated lockfile, and release again.`,
|
|
445
|
+
plugins.path.join(options.cwd, directory),
|
|
446
|
+
`\`cargo fetch --locked\` rejects the committed ${directory}${cargoLockfileName}, so the release checkout could not fetch it. Run \`cargo update --workspace\`, commit the updated lockfile, and release again.`,
|
|
404
447
|
);
|
|
405
448
|
}
|
|
406
449
|
if (!(await commitCarriesBlob(options, "package.json"))) {
|
|
@@ -472,8 +515,8 @@ export interface IIsolatedReleaseCheckoutOptions {
|
|
|
472
515
|
testCommand?: string;
|
|
473
516
|
/** Configured build command, when the checkout must build. */
|
|
474
517
|
buildCommand?: string;
|
|
475
|
-
/**
|
|
476
|
-
cargo?:
|
|
518
|
+
/** Fetch the locked Cargo dependencies of the workspace that carries the version. */
|
|
519
|
+
cargo?: TReleaseCargoWorkspace;
|
|
477
520
|
/**
|
|
478
521
|
* Install the npm dependencies of a commit that carries a package.json;
|
|
479
522
|
* default true. A checkout that only publishes crates needs none.
|
|
@@ -575,7 +618,7 @@ export const withIsolatedReleaseCheckout = async <T>(
|
|
|
575
618
|
if (options.cargo)
|
|
576
619
|
await fetchLockedCargoDependencies(
|
|
577
620
|
options.smartshell,
|
|
578
|
-
checkout,
|
|
621
|
+
await findCheckoutCargoWorkspace(checkout, options.cargo),
|
|
579
622
|
"Release checkout Cargo dependency fetch failed.",
|
|
580
623
|
);
|
|
581
624
|
if (options.testCommand)
|
|
@@ -658,7 +701,7 @@ export const withReleasePreparationRecovery = async <T>(
|
|
|
658
701
|
...(options.workflow.runBuild
|
|
659
702
|
? { buildCommand: options.workflow.buildCommand }
|
|
660
703
|
: {}),
|
|
661
|
-
cargo: options.workflow.
|
|
704
|
+
cargo: options.workflow.cargoWorkspace,
|
|
662
705
|
},
|
|
663
706
|
async (checkout) => {
|
|
664
707
|
await ensureState();
|