@git.zone/cli 12.2.0 → 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.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 +338 -40
- package/ts/00_commitinfo_data.ts +1 -1
- 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
|
@@ -1,16 +1,40 @@
|
|
|
1
1
|
import * as plugins from "./mod.plugins.js";
|
|
2
2
|
import type {
|
|
3
|
-
IGiteaAssetDestination,
|
|
4
|
-
IGiteaFrozenAsset,
|
|
5
|
-
IPrepareGiteaAssetsOptions,
|
|
6
3
|
IGiteaAssetsClientOptions,
|
|
7
4
|
IGiteaAssetInspection,
|
|
8
5
|
IGiteaAssetPreflight,
|
|
9
6
|
IGiteaRelease,
|
|
10
7
|
IGiteaAssetsClient,
|
|
11
|
-
IGiteaAssetTransferLimits,
|
|
12
8
|
} from "./interfaces.giteaassets.js";
|
|
13
9
|
export type * from "./interfaces.giteaassets.js";
|
|
10
|
+
import {
|
|
11
|
+
ReleaseAssetConflictError,
|
|
12
|
+
assertReleaseAssetRecord,
|
|
13
|
+
assertReleaseAssetTag,
|
|
14
|
+
assertReleaseFrozenAssets,
|
|
15
|
+
normalizeReleaseAssetDestination,
|
|
16
|
+
openReleaseAssetFile,
|
|
17
|
+
prepareReleaseAssets,
|
|
18
|
+
releaseAssetTargets,
|
|
19
|
+
validateReleaseAssets,
|
|
20
|
+
verifyReleaseAssetFile,
|
|
21
|
+
type IPrepareReleaseAssetsOptions,
|
|
22
|
+
type IReleaseAssetDestination,
|
|
23
|
+
type IReleaseAssetTransferFailures,
|
|
24
|
+
type IReleaseAssetTransferLimits,
|
|
25
|
+
type IReleaseFrozenAsset,
|
|
26
|
+
type TReleaseAssetFileHandle,
|
|
27
|
+
} from "./helpers.releaseassets.js";
|
|
28
|
+
import {
|
|
29
|
+
ReleaseAssetRequestError,
|
|
30
|
+
ReleaseAssetTransferWatchdog,
|
|
31
|
+
assertReleaseAssetTransferLimits,
|
|
32
|
+
createReleaseAssetUploadBody,
|
|
33
|
+
defaultReleaseAssetTransferLimits,
|
|
34
|
+
describeReleaseAssetRequestFailure,
|
|
35
|
+
formatReleaseAssetSeconds,
|
|
36
|
+
readReleaseAssetResponse,
|
|
37
|
+
} from "./helpers.releaseassettransfer.js";
|
|
14
38
|
// The tag-processing wait is shared with the sealed release workflow, which runs a rendered copy.
|
|
15
39
|
import {
|
|
16
40
|
awaitGiteaTagProcessed,
|
|
@@ -20,14 +44,9 @@ import {
|
|
|
20
44
|
GiteaReleasePageCheckError,
|
|
21
45
|
} from "../../assets/templates/asset_tspack_release_gitea/scripts/gitzone-gitea-tag.mjs";
|
|
22
46
|
|
|
23
|
-
const maximumManifestBytes = 4 * 1024 * 1024;
|
|
24
47
|
const maximumMetadataBytes = 8 * 1024 * 1024;
|
|
25
|
-
const maximumAssetBytes = 32 * 1024 * 1024 * 1024;
|
|
26
|
-
const maximumAssets = 1024;
|
|
27
|
-
const canonicalName = /^[A-Za-z0-9][A-Za-z0-9._-]{0,199}$/;
|
|
28
|
-
const sha256Pattern = /^[a-f0-9]{64}$/;
|
|
29
48
|
|
|
30
|
-
export class GiteaAssetConflictError extends
|
|
49
|
+
export class GiteaAssetConflictError extends ReleaseAssetConflictError {
|
|
31
50
|
constructor(message: string) {
|
|
32
51
|
super(message);
|
|
33
52
|
this.name = "GiteaAssetConflictError";
|
|
@@ -78,46 +97,6 @@ export class GiteaTagProcessingTimeoutError extends Error {
|
|
|
78
97
|
}
|
|
79
98
|
}
|
|
80
99
|
|
|
81
|
-
const safeErrorName = /^[A-Za-z][A-Za-z0-9]{0,63}$/;
|
|
82
|
-
const safeErrorCode = /^[A-Z][A-Z0-9_]{1,63}$/;
|
|
83
|
-
/** Plain words only: no digit, colon, slash or dot inside can carry a URL or token. */
|
|
84
|
-
const safeErrorMessage = /^[A-Za-z][A-Za-z ]{0,79}\.?$/;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Names why a request ended: the HTTP status it reached, each error of the
|
|
88
|
-
* cause chain by name and code, its message only when it is plain words
|
|
89
|
-
* ("terminated", "fetch failed", "other side closed"), and how far the
|
|
90
|
-
* transfer got.
|
|
91
|
-
*/
|
|
92
|
-
export const describeGiteaRequestFailure = (
|
|
93
|
-
error: unknown,
|
|
94
|
-
evidence: { status?: number; progress: string },
|
|
95
|
-
): string => {
|
|
96
|
-
const parts: string[] = [];
|
|
97
|
-
if (evidence.status !== undefined) parts.push(`HTTP ${evidence.status}`);
|
|
98
|
-
let current = error;
|
|
99
|
-
for (let depth = 0; depth < 4 && current instanceof Error; depth++) {
|
|
100
|
-
const name = safeErrorName.test(current.name) ? current.name : "Error";
|
|
101
|
-
const code = (current as NodeJS.ErrnoException).code;
|
|
102
|
-
const codeText =
|
|
103
|
-
typeof code === "string" && safeErrorCode.test(code) ? ` [${code}]` : "";
|
|
104
|
-
const messageText = safeErrorMessage.test(current.message)
|
|
105
|
-
? `: ${current.message}`
|
|
106
|
-
: "";
|
|
107
|
-
parts.push(`${name}${codeText}${messageText}`);
|
|
108
|
-
current = current.cause;
|
|
109
|
-
}
|
|
110
|
-
parts.push(evidence.progress);
|
|
111
|
-
return `(${parts.join("; ")})`;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
export const defaultGiteaAssetTransferLimits: Readonly<IGiteaAssetTransferLimits> =
|
|
115
|
-
Object.freeze({
|
|
116
|
-
responseTimeoutMs: 2 * 60_000,
|
|
117
|
-
stallTimeoutMs: 60_000,
|
|
118
|
-
minimumBytesPerSecond: 256 * 1024,
|
|
119
|
-
});
|
|
120
|
-
|
|
121
100
|
/**
|
|
122
101
|
* Attachments a release has in progress at the same time unless configured
|
|
123
102
|
* otherwise: one, so every attachment uploads and verifies alone, as fast as
|
|
@@ -139,14 +118,8 @@ export const defaultGiteaTagProcessingTimeoutMs = giteaTagProcessingTimeoutMs;
|
|
|
139
118
|
export const defaultGiteaTagProcessingPollIntervalMs =
|
|
140
119
|
giteaTagProcessingPollIntervalMs;
|
|
141
120
|
const maximumTagProcessingTimeoutMs = 6 * 60 * 60_000;
|
|
142
|
-
const maximumTransferTimeoutMs = 60 * 60_000;
|
|
143
|
-
const maximumBytesPerSecond = 1024 * 1024 * 1024;
|
|
144
|
-
/** Node fires longer timers immediately; a ceiling this far out never binds. */
|
|
145
|
-
const maximumTimerMs = 2_147_483_647;
|
|
146
121
|
const inconclusive =
|
|
147
122
|
"the result is inconclusive; inspect the retained release before another mutation.";
|
|
148
|
-
const formatSeconds = (milliseconds: number): string =>
|
|
149
|
-
`${Math.round(milliseconds / 100) / 10} s`;
|
|
150
123
|
|
|
151
124
|
/** A Gitea request ended by a transfer bound; messages carry no URL or credential. */
|
|
152
125
|
export class GiteaAssetTimeoutError extends Error {
|
|
@@ -160,7 +133,7 @@ export class GiteaAssetTimeoutError extends Error {
|
|
|
160
133
|
export class GiteaAssetResponseTimeoutError extends GiteaAssetTimeoutError {
|
|
161
134
|
constructor(operation: string, limitMs: number) {
|
|
162
135
|
super(
|
|
163
|
-
`Gitea asset ${operation} received no response within ${
|
|
136
|
+
`Gitea asset ${operation} received no response within ${formatReleaseAssetSeconds(limitMs)}; ${inconclusive}`,
|
|
164
137
|
);
|
|
165
138
|
this.name = "GiteaAssetResponseTimeoutError";
|
|
166
139
|
}
|
|
@@ -175,7 +148,7 @@ export class GiteaAssetTransferStalledError extends GiteaAssetTimeoutError {
|
|
|
175
148
|
bytes: number,
|
|
176
149
|
) {
|
|
177
150
|
super(
|
|
178
|
-
`Gitea asset ${operation} stalled: no bytes ${direction} for ${
|
|
151
|
+
`Gitea asset ${operation} stalled: no bytes ${direction} for ${formatReleaseAssetSeconds(limitMs)} after ${bytes} bytes; ${inconclusive}`,
|
|
179
152
|
);
|
|
180
153
|
this.name = "GiteaAssetTransferStalledError";
|
|
181
154
|
}
|
|
@@ -185,7 +158,7 @@ export class GiteaAssetTransferStalledError extends GiteaAssetTimeoutError {
|
|
|
185
158
|
export class GiteaAssetUploadNotAcknowledgedError extends GiteaAssetTimeoutError {
|
|
186
159
|
constructor(bytes: number, limitMs: number, minimumBytesPerSecond: number) {
|
|
187
160
|
super(
|
|
188
|
-
`Gitea asset upload was not acknowledged: all ${bytes} bytes were sent, but no response arrived within ${
|
|
161
|
+
`Gitea asset upload was not acknowledged: all ${bytes} bytes were sent, but no response arrived within ${formatReleaseAssetSeconds(limitMs)}, the allowance for its size at ${Math.round(minimumBytesPerSecond / 1024)} KiB/s; ${inconclusive}`,
|
|
189
162
|
);
|
|
190
163
|
this.name = "GiteaAssetUploadNotAcknowledgedError";
|
|
191
164
|
}
|
|
@@ -201,194 +174,49 @@ export class GiteaAssetTransferTooSlowError extends GiteaAssetTimeoutError {
|
|
|
201
174
|
minimumBytesPerSecond: number,
|
|
202
175
|
) {
|
|
203
176
|
super(
|
|
204
|
-
`Gitea asset ${operation} was still progressing but too slow: ${bytes} of ${expectedBytes} bytes after ${
|
|
177
|
+
`Gitea asset ${operation} was still progressing but too slow: ${bytes} of ${expectedBytes} bytes after ${formatReleaseAssetSeconds(elapsedMs)}, below the ${Math.round(minimumBytesPerSecond / 1024)} KiB/s floor; ${inconclusive}`,
|
|
205
178
|
);
|
|
206
179
|
this.name = "GiteaAssetTransferTooSlowError";
|
|
207
180
|
}
|
|
208
181
|
}
|
|
209
182
|
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Bounds one request by progress instead of wall-clock time: the response
|
|
233
|
-
* bound covers waiting for headers, the stall bound restarts on every byte,
|
|
234
|
-
* an upload's acknowledgement wait scales with its size, and a ceiling of
|
|
235
|
-
* expected bytes at the rate floor ends a trickle.
|
|
236
|
-
*/
|
|
237
|
-
export class GiteaTransferWatchdog {
|
|
238
|
-
readonly #controller = new AbortController();
|
|
239
|
-
readonly #started = Date.now();
|
|
240
|
-
readonly #ceiling: NodeJS.Timeout;
|
|
241
|
-
/** Servers process and store a large upload before answering; allow its size at the floor. */
|
|
242
|
-
readonly #acknowledgementMs: number;
|
|
243
|
-
#timer: NodeJS.Timeout | undefined;
|
|
244
|
-
#phase: TWatchdogPhase | undefined;
|
|
245
|
-
#direction: "sent" | "received" = "sent";
|
|
246
|
-
#bytes = 0;
|
|
247
|
-
#failure: GiteaAssetTimeoutError | undefined;
|
|
248
|
-
/** A late body pull or chunk after close must never re-arm a timer. */
|
|
249
|
-
#closed = false;
|
|
183
|
+
const giteaTransferFailures: IReleaseAssetTransferFailures<GiteaAssetTimeoutError> =
|
|
184
|
+
{
|
|
185
|
+
responseTimeout: (operation, limitMs) =>
|
|
186
|
+
new GiteaAssetResponseTimeoutError(operation, limitMs),
|
|
187
|
+
stalled: (operation, direction, limitMs, bytes) =>
|
|
188
|
+
new GiteaAssetTransferStalledError(operation, direction, limitMs, bytes),
|
|
189
|
+
notAcknowledged: (bytes, limitMs, minimumBytesPerSecond) =>
|
|
190
|
+
new GiteaAssetUploadNotAcknowledgedError(
|
|
191
|
+
bytes,
|
|
192
|
+
limitMs,
|
|
193
|
+
minimumBytesPerSecond,
|
|
194
|
+
),
|
|
195
|
+
tooSlow: (operation, elapsedMs, bytes, expectedBytes, minimumBytesPerSecond) =>
|
|
196
|
+
new GiteaAssetTransferTooSlowError(
|
|
197
|
+
operation,
|
|
198
|
+
elapsedMs,
|
|
199
|
+
bytes,
|
|
200
|
+
expectedBytes,
|
|
201
|
+
minimumBytesPerSecond,
|
|
202
|
+
),
|
|
203
|
+
};
|
|
250
204
|
|
|
205
|
+
/** The transfer watchdog that ends a Gitea request with Gitea's timeout errors. */
|
|
206
|
+
export class GiteaTransferWatchdog extends ReleaseAssetTransferWatchdog<GiteaAssetTimeoutError> {
|
|
251
207
|
constructor(
|
|
252
|
-
|
|
253
|
-
|
|
208
|
+
operation: string,
|
|
209
|
+
limits: IReleaseAssetTransferLimits,
|
|
254
210
|
/** Bytes the request moves in total, including an upload body. */
|
|
255
|
-
|
|
256
|
-
|
|
211
|
+
expectedBytes: number,
|
|
212
|
+
uploadBytes = 0,
|
|
257
213
|
) {
|
|
258
|
-
|
|
259
|
-
Math.ceil((bytes * 1000) / limits.minimumBytesPerSecond);
|
|
260
|
-
this.#acknowledgementMs = Math.max(
|
|
261
|
-
limits.responseTimeoutMs,
|
|
262
|
-
atFloor(uploadBytes),
|
|
263
|
-
);
|
|
264
|
-
const ceilingMs = Math.min(
|
|
265
|
-
maximumTimerMs,
|
|
266
|
-
limits.responseTimeoutMs +
|
|
267
|
-
limits.stallTimeoutMs +
|
|
268
|
-
atFloor(expectedBytes) +
|
|
269
|
-
(uploadBytes ? this.#acknowledgementMs : 0),
|
|
270
|
-
);
|
|
271
|
-
this.#ceiling = setTimeout(
|
|
272
|
-
() =>
|
|
273
|
-
this.#fail(
|
|
274
|
-
new GiteaAssetTransferTooSlowError(
|
|
275
|
-
operation,
|
|
276
|
-
Date.now() - this.#started,
|
|
277
|
-
this.#bytes,
|
|
278
|
-
expectedBytes,
|
|
279
|
-
limits.minimumBytesPerSecond,
|
|
280
|
-
),
|
|
281
|
-
),
|
|
282
|
-
ceilingMs,
|
|
283
|
-
);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
get signal(): AbortSignal {
|
|
287
|
-
return this.#controller.signal;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
get failure(): GiteaAssetTimeoutError | undefined {
|
|
291
|
-
return this.#failure;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/** Bytes sent and received so far. */
|
|
295
|
-
get bytes(): number {
|
|
296
|
-
return this.#bytes;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/** Wait for response headers; every redirect hop starts a new wait. */
|
|
300
|
-
awaitResponse(): void {
|
|
301
|
-
this.#arm("response");
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
/** The whole upload body is sent; wait for the server to store and answer it. */
|
|
305
|
-
awaitAcknowledgement(): void {
|
|
306
|
-
this.#arm("acknowledgement");
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/** Record moved bytes; the stall bound restarts from this moment. */
|
|
310
|
-
progress(direction: "sent" | "received", bytes: number): void {
|
|
311
|
-
if (this.#closed) return;
|
|
312
|
-
this.#direction = direction;
|
|
313
|
-
this.#bytes += bytes;
|
|
314
|
-
this.#arm("stall");
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
close(): void {
|
|
318
|
-
this.#closed = true;
|
|
319
|
-
clearTimeout(this.#ceiling);
|
|
320
|
-
clearTimeout(this.#timer);
|
|
321
|
-
this.#controller.abort();
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
#arm(phase: TWatchdogPhase): void {
|
|
325
|
-
if (this.#failure || this.#closed) return;
|
|
326
|
-
if (this.#timer && this.#phase === phase) {
|
|
327
|
-
this.#timer.refresh();
|
|
328
|
-
return;
|
|
329
|
-
}
|
|
330
|
-
clearTimeout(this.#timer);
|
|
331
|
-
this.#phase = phase;
|
|
332
|
-
const bounds: Record<
|
|
333
|
-
TWatchdogPhase,
|
|
334
|
-
[number, () => GiteaAssetTimeoutError]
|
|
335
|
-
> = {
|
|
336
|
-
response: [
|
|
337
|
-
this.limits.responseTimeoutMs,
|
|
338
|
-
() =>
|
|
339
|
-
new GiteaAssetResponseTimeoutError(
|
|
340
|
-
this.operation,
|
|
341
|
-
this.limits.responseTimeoutMs,
|
|
342
|
-
),
|
|
343
|
-
],
|
|
344
|
-
stall: [
|
|
345
|
-
this.limits.stallTimeoutMs,
|
|
346
|
-
() =>
|
|
347
|
-
new GiteaAssetTransferStalledError(
|
|
348
|
-
this.operation,
|
|
349
|
-
this.#direction,
|
|
350
|
-
this.limits.stallTimeoutMs,
|
|
351
|
-
this.#bytes,
|
|
352
|
-
),
|
|
353
|
-
],
|
|
354
|
-
acknowledgement: [
|
|
355
|
-
this.#acknowledgementMs,
|
|
356
|
-
() =>
|
|
357
|
-
new GiteaAssetUploadNotAcknowledgedError(
|
|
358
|
-
this.uploadBytes,
|
|
359
|
-
this.#acknowledgementMs,
|
|
360
|
-
this.limits.minimumBytesPerSecond,
|
|
361
|
-
),
|
|
362
|
-
],
|
|
363
|
-
};
|
|
364
|
-
const [milliseconds, failure] = bounds[phase];
|
|
365
|
-
this.#timer = setTimeout(
|
|
366
|
-
() => this.#fail(failure()),
|
|
367
|
-
Math.min(maximumTimerMs, milliseconds),
|
|
368
|
-
);
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
#fail(error: GiteaAssetTimeoutError): void {
|
|
372
|
-
if (this.#failure) return;
|
|
373
|
-
this.#failure = error;
|
|
374
|
-
clearTimeout(this.#ceiling);
|
|
375
|
-
clearTimeout(this.#timer);
|
|
376
|
-
this.#controller.abort();
|
|
214
|
+
super(giteaTransferFailures, operation, limits, expectedBytes, uploadBytes);
|
|
377
215
|
}
|
|
378
216
|
}
|
|
379
217
|
|
|
380
|
-
const record = (value: unknown): Record<string, unknown> =>
|
|
381
|
-
|
|
382
|
-
throw new Error("Invalid Gitea asset object.");
|
|
383
|
-
}
|
|
384
|
-
return value as Record<string, unknown>;
|
|
385
|
-
};
|
|
386
|
-
|
|
387
|
-
const exactKeys = (value: Record<string, unknown>, keys: string[]): void => {
|
|
388
|
-
if (Object.keys(value).sort().join("\0") !== [...keys].sort().join("\0")) {
|
|
389
|
-
throw new Error("Unexpected Gitea asset manifest fields.");
|
|
390
|
-
}
|
|
391
|
-
};
|
|
218
|
+
const record = (value: unknown): Record<string, unknown> =>
|
|
219
|
+
assertReleaseAssetRecord("giteaAssets", value);
|
|
392
220
|
|
|
393
221
|
const positiveId = (value: unknown): number => {
|
|
394
222
|
if (!Number.isSafeInteger(value) || (value as number) <= 0) {
|
|
@@ -397,377 +225,29 @@ const positiveId = (value: unknown): number => {
|
|
|
397
225
|
return value as number;
|
|
398
226
|
};
|
|
399
227
|
|
|
400
|
-
const assertName = (value: unknown): string => {
|
|
401
|
-
if (typeof value !== "string" || !canonicalName.test(value)) {
|
|
402
|
-
throw new Error(
|
|
403
|
-
"Gitea asset names must be canonical single path components.",
|
|
404
|
-
);
|
|
405
|
-
}
|
|
406
|
-
return value;
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
const assertTag = (value: string): void => {
|
|
410
|
-
if (
|
|
411
|
-
!canonicalName.test(value) ||
|
|
412
|
-
value.endsWith(".") ||
|
|
413
|
-
value.endsWith(".lock") ||
|
|
414
|
-
value.includes("..")
|
|
415
|
-
) {
|
|
416
|
-
throw new Error(
|
|
417
|
-
"Gitea asset publication requires a canonical release tag.",
|
|
418
|
-
);
|
|
419
|
-
}
|
|
420
|
-
};
|
|
421
|
-
|
|
422
|
-
const assertSizeAndHash = (value: Record<string, unknown>): void => {
|
|
423
|
-
if (
|
|
424
|
-
!Number.isSafeInteger(value.size) ||
|
|
425
|
-
(value.size as number) < 0 ||
|
|
426
|
-
(value.size as number) > maximumAssetBytes ||
|
|
427
|
-
typeof value.sha256 !== "string" ||
|
|
428
|
-
!sha256Pattern.test(value.sha256)
|
|
429
|
-
) {
|
|
430
|
-
throw new Error("Invalid Gitea asset size or SHA256.");
|
|
431
|
-
}
|
|
432
|
-
};
|
|
433
|
-
|
|
434
228
|
export const normalizeGiteaAssetDestination = (
|
|
435
|
-
value:
|
|
436
|
-
):
|
|
437
|
-
|
|
438
|
-
exactKeys(candidate, ["apiOrigin", "owner", "repository"]);
|
|
439
|
-
let url: URL;
|
|
440
|
-
try {
|
|
441
|
-
url = new URL(candidate.apiOrigin as string);
|
|
442
|
-
} catch {
|
|
443
|
-
throw new Error("Invalid Gitea API origin.");
|
|
444
|
-
}
|
|
445
|
-
if (
|
|
446
|
-
url.protocol !== "https:" ||
|
|
447
|
-
url.username ||
|
|
448
|
-
url.password ||
|
|
449
|
-
url.search ||
|
|
450
|
-
url.hash ||
|
|
451
|
-
url.pathname !== "/" ||
|
|
452
|
-
![url.origin, `${url.origin}/`].includes(candidate.apiOrigin as string)
|
|
453
|
-
) {
|
|
454
|
-
throw new Error(
|
|
455
|
-
"Gitea API origin must be credential-free canonical HTTPS.",
|
|
456
|
-
);
|
|
457
|
-
}
|
|
458
|
-
return {
|
|
459
|
-
apiOrigin: url.origin,
|
|
460
|
-
owner: assertName(candidate.owner),
|
|
461
|
-
repository: assertName(candidate.repository),
|
|
462
|
-
};
|
|
463
|
-
};
|
|
464
|
-
|
|
465
|
-
export const giteaAssetFileName = (name: string): string =>
|
|
466
|
-
`asset.${plugins.crypto.createHash("sha256").update(assertName(name)).digest("hex")}.bin`;
|
|
467
|
-
|
|
468
|
-
export const giteaAssetPublicUrl = (
|
|
469
|
-
destination: IGiteaAssetDestination,
|
|
470
|
-
tag: string,
|
|
471
|
-
name: string,
|
|
472
|
-
): string => {
|
|
473
|
-
const normalized = normalizeGiteaAssetDestination(destination);
|
|
474
|
-
assertTag(tag);
|
|
475
|
-
return `${normalized.apiOrigin}/${normalized.owner}/${normalized.repository}/releases/download/${encodeURIComponent(tag)}/${assertName(name)}`;
|
|
476
|
-
};
|
|
477
|
-
|
|
478
|
-
const assertRelativeAssetPath = (value: unknown): string => {
|
|
479
|
-
if (
|
|
480
|
-
typeof value !== "string" ||
|
|
481
|
-
value.length > 4096 ||
|
|
482
|
-
value
|
|
483
|
-
.split("/")
|
|
484
|
-
.some(
|
|
485
|
-
(part) =>
|
|
486
|
-
!canonicalName.test(part) ||
|
|
487
|
-
/^(?:node_modules|coverage|secrets?|credentials?|runtime|data|tmp|temp|id_rsa|id_ed25519)(?:\..*)?$/i.test(
|
|
488
|
-
part,
|
|
489
|
-
) ||
|
|
490
|
-
/\.(?:pem|key|p12|pfx)$/i.test(part),
|
|
491
|
-
)
|
|
492
|
-
) {
|
|
493
|
-
throw new Error(
|
|
494
|
-
"Asset inputs require canonical repository paths outside credential/runtime directories.",
|
|
495
|
-
);
|
|
496
|
-
}
|
|
497
|
-
return value;
|
|
498
|
-
};
|
|
499
|
-
|
|
500
|
-
/** Reject symlinks in every component, including the caller-provided root. */
|
|
501
|
-
const assertRegularPath = async (
|
|
502
|
-
absolutePath: string,
|
|
503
|
-
directory = false,
|
|
504
|
-
): Promise<void> => {
|
|
505
|
-
const resolved = plugins.path.resolve(absolutePath);
|
|
506
|
-
const parsed = plugins.path.parse(resolved);
|
|
507
|
-
let current = parsed.root;
|
|
508
|
-
const parts = resolved
|
|
509
|
-
.slice(parsed.root.length)
|
|
510
|
-
.split(plugins.path.sep)
|
|
511
|
-
.filter(Boolean);
|
|
512
|
-
for (let index = 0; index < parts.length; index++) {
|
|
513
|
-
current = plugins.path.join(current, parts[index]);
|
|
514
|
-
const stat = await plugins.fs.lstat(current);
|
|
515
|
-
const expectDirectory = index < parts.length - 1 || directory;
|
|
516
|
-
if (
|
|
517
|
-
stat.isSymbolicLink() ||
|
|
518
|
-
(expectDirectory ? !stat.isDirectory() : !stat.isFile())
|
|
519
|
-
) {
|
|
520
|
-
throw new Error(
|
|
521
|
-
"Gitea asset paths must use regular files and directories without symlinks.",
|
|
522
|
-
);
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
};
|
|
526
|
-
|
|
527
|
-
const openRegularFile = async (path: string) => {
|
|
528
|
-
await assertRegularPath(path);
|
|
529
|
-
const handle = await plugins.fs.open(
|
|
530
|
-
path,
|
|
531
|
-
plugins.fsConstants.O_RDONLY | plugins.fsConstants.O_NOFOLLOW,
|
|
532
|
-
);
|
|
533
|
-
try {
|
|
534
|
-
if (!(await handle.stat()).isFile())
|
|
535
|
-
throw new Error("Gitea asset input is not a regular file.");
|
|
536
|
-
return handle;
|
|
537
|
-
} catch (error) {
|
|
538
|
-
await handle.close();
|
|
539
|
-
throw error;
|
|
540
|
-
}
|
|
541
|
-
};
|
|
542
|
-
|
|
543
|
-
const readBoundedFile = async (
|
|
544
|
-
path: string,
|
|
545
|
-
maximum: number,
|
|
546
|
-
): Promise<Buffer> => {
|
|
547
|
-
const handle = await openRegularFile(path);
|
|
548
|
-
try {
|
|
549
|
-
if ((await handle.stat()).size > maximum)
|
|
550
|
-
throw new Error("Gitea asset metadata exceeds its size limit.");
|
|
551
|
-
const chunks: Buffer[] = [];
|
|
552
|
-
let size = 0;
|
|
553
|
-
for await (const chunk of handle.createReadStream({
|
|
554
|
-
autoClose: false,
|
|
555
|
-
highWaterMark: 64 * 1024,
|
|
556
|
-
})) {
|
|
557
|
-
size += chunk.length;
|
|
558
|
-
if (size > maximum)
|
|
559
|
-
throw new Error("Gitea asset metadata exceeds its size limit.");
|
|
560
|
-
chunks.push(chunk);
|
|
561
|
-
}
|
|
562
|
-
return Buffer.concat(chunks, size);
|
|
563
|
-
} finally {
|
|
564
|
-
await handle.close();
|
|
565
|
-
}
|
|
566
|
-
};
|
|
567
|
-
|
|
568
|
-
const verifyHandle = async (
|
|
569
|
-
handle: Awaited<ReturnType<typeof openRegularFile>>,
|
|
570
|
-
asset: IGiteaFrozenAsset,
|
|
571
|
-
): Promise<void> => {
|
|
572
|
-
const before = await handle.stat();
|
|
573
|
-
if (before.size !== asset.size)
|
|
574
|
-
throw new Error(
|
|
575
|
-
"Stored Gitea asset size conflicts with its frozen identity.",
|
|
576
|
-
);
|
|
577
|
-
const hash = plugins.crypto.createHash("sha256");
|
|
578
|
-
let size = 0;
|
|
579
|
-
for await (const chunk of handle.createReadStream({
|
|
580
|
-
autoClose: false,
|
|
581
|
-
start: 0,
|
|
582
|
-
highWaterMark: 64 * 1024,
|
|
583
|
-
})) {
|
|
584
|
-
size += chunk.length;
|
|
585
|
-
if (size > asset.size)
|
|
586
|
-
throw new Error("Stored Gitea asset exceeds its frozen size.");
|
|
587
|
-
hash.update(chunk);
|
|
588
|
-
}
|
|
589
|
-
const after = await handle.stat();
|
|
590
|
-
if (
|
|
591
|
-
size !== asset.size ||
|
|
592
|
-
hash.digest("hex") !== asset.sha256 ||
|
|
593
|
-
before.mtimeMs !== after.mtimeMs ||
|
|
594
|
-
before.ctimeMs !== after.ctimeMs
|
|
595
|
-
) {
|
|
596
|
-
throw new Error(
|
|
597
|
-
"Stored Gitea asset bytes conflict with their frozen identity.",
|
|
598
|
-
);
|
|
599
|
-
}
|
|
600
|
-
};
|
|
229
|
+
value: IReleaseAssetDestination,
|
|
230
|
+
): IReleaseAssetDestination =>
|
|
231
|
+
normalizeReleaseAssetDestination("giteaAssets", value);
|
|
601
232
|
|
|
602
233
|
export function assertGiteaFrozenAssets(
|
|
603
234
|
assets: unknown,
|
|
604
|
-
destination?:
|
|
235
|
+
destination?: IReleaseAssetDestination,
|
|
605
236
|
tag?: string,
|
|
606
|
-
): asserts assets is
|
|
607
|
-
|
|
608
|
-
!Array.isArray(assets) ||
|
|
609
|
-
assets.length === 0 ||
|
|
610
|
-
assets.length > maximumAssets
|
|
611
|
-
)
|
|
612
|
-
throw new Error("Invalid Gitea asset set.");
|
|
613
|
-
const names = new Set<string>();
|
|
614
|
-
for (const entry of assets) {
|
|
615
|
-
const asset = record(entry);
|
|
616
|
-
exactKeys(asset, ["name", "size", "sha256", "fileName", "publicUrl"]);
|
|
617
|
-
const name = assertName(asset.name);
|
|
618
|
-
assertSizeAndHash(asset);
|
|
619
|
-
if (names.has(name) || asset.fileName !== giteaAssetFileName(name))
|
|
620
|
-
throw new Error("Duplicate or invalid stored Gitea asset identity.");
|
|
621
|
-
names.add(name);
|
|
622
|
-
let url: URL;
|
|
623
|
-
try {
|
|
624
|
-
url = new URL(asset.publicUrl as string);
|
|
625
|
-
} catch {
|
|
626
|
-
throw new Error("Invalid frozen Gitea asset URL.");
|
|
627
|
-
}
|
|
628
|
-
if (
|
|
629
|
-
url.protocol !== "https:" ||
|
|
630
|
-
url.username ||
|
|
631
|
-
url.password ||
|
|
632
|
-
url.search ||
|
|
633
|
-
url.hash ||
|
|
634
|
-
url.href !== asset.publicUrl ||
|
|
635
|
-
(destination &&
|
|
636
|
-
tag &&
|
|
637
|
-
asset.publicUrl !== giteaAssetPublicUrl(destination, tag, name))
|
|
638
|
-
) {
|
|
639
|
-
throw new Error("Frozen Gitea asset URL conflicts with its destination.");
|
|
640
|
-
}
|
|
641
|
-
}
|
|
237
|
+
): asserts assets is IReleaseFrozenAsset[] {
|
|
238
|
+
assertReleaseFrozenAssets("giteaAssets", assets, destination, tag);
|
|
642
239
|
}
|
|
643
240
|
|
|
644
|
-
export const validateGiteaAssets =
|
|
241
|
+
export const validateGiteaAssets = (
|
|
645
242
|
artifactDirectory: string,
|
|
646
|
-
assets:
|
|
647
|
-
): Promise<void> =>
|
|
648
|
-
|
|
649
|
-
await assertRegularPath(artifactDirectory, true);
|
|
650
|
-
for (const asset of assets) {
|
|
651
|
-
const handle = await openRegularFile(
|
|
652
|
-
plugins.path.join(artifactDirectory, asset.fileName),
|
|
653
|
-
);
|
|
654
|
-
try {
|
|
655
|
-
await verifyHandle(handle, asset);
|
|
656
|
-
} finally {
|
|
657
|
-
await handle.close();
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
};
|
|
243
|
+
assets: IReleaseFrozenAsset[],
|
|
244
|
+
): Promise<void> =>
|
|
245
|
+
validateReleaseAssets("giteaAssets", artifactDirectory, assets);
|
|
661
246
|
|
|
662
|
-
export const prepareGiteaAssets =
|
|
663
|
-
options:
|
|
664
|
-
): Promise<
|
|
665
|
-
|
|
666
|
-
assertTag(options.tag);
|
|
667
|
-
if (
|
|
668
|
-
!/^\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?(?:\+[A-Za-z0-9.-]+)?$/.test(
|
|
669
|
-
options.version,
|
|
670
|
-
)
|
|
671
|
-
)
|
|
672
|
-
throw new Error("Invalid Gitea asset manifest release version.");
|
|
673
|
-
await assertRegularPath(options.repositoryRoot, true);
|
|
674
|
-
const manifestPath = plugins.path.join(
|
|
675
|
-
options.repositoryRoot,
|
|
676
|
-
assertRelativeAssetPath(options.manifestPath),
|
|
677
|
-
);
|
|
678
|
-
let manifest: Record<string, unknown>;
|
|
679
|
-
try {
|
|
680
|
-
manifest = record(
|
|
681
|
-
JSON.parse(
|
|
682
|
-
(await readBoundedFile(manifestPath, maximumManifestBytes)).toString(
|
|
683
|
-
"utf8",
|
|
684
|
-
),
|
|
685
|
-
),
|
|
686
|
-
);
|
|
687
|
-
} catch {
|
|
688
|
-
throw new Error("Unable to read a bounded regular Gitea asset manifest.");
|
|
689
|
-
}
|
|
690
|
-
exactKeys(manifest, ["schemaVersion", "version", "assets"]);
|
|
691
|
-
if (
|
|
692
|
-
manifest.schemaVersion !== 1 ||
|
|
693
|
-
manifest.version !== options.version ||
|
|
694
|
-
!Array.isArray(manifest.assets) ||
|
|
695
|
-
manifest.assets.length === 0 ||
|
|
696
|
-
manifest.assets.length > maximumAssets
|
|
697
|
-
)
|
|
698
|
-
throw new Error(
|
|
699
|
-
"Gitea asset manifest must match the exact release version and schema.",
|
|
700
|
-
);
|
|
701
|
-
const paths = new Set<string>();
|
|
702
|
-
const assets = manifest.assets.map((entry): IGiteaFrozenAsset => {
|
|
703
|
-
const input = record(entry);
|
|
704
|
-
exactKeys(input, ["name", "path", "size", "sha256"]);
|
|
705
|
-
const path = assertRelativeAssetPath(input.path);
|
|
706
|
-
if (paths.has(path))
|
|
707
|
-
throw new Error("Gitea asset input paths must be unique.");
|
|
708
|
-
paths.add(path);
|
|
709
|
-
const name = assertName(input.name);
|
|
710
|
-
assertSizeAndHash(input);
|
|
711
|
-
return {
|
|
712
|
-
name,
|
|
713
|
-
size: input.size as number,
|
|
714
|
-
sha256: input.sha256 as string,
|
|
715
|
-
fileName: giteaAssetFileName(name),
|
|
716
|
-
publicUrl: giteaAssetPublicUrl(destination, options.tag, name),
|
|
717
|
-
};
|
|
718
|
-
});
|
|
719
|
-
assertGiteaFrozenAssets(assets, destination, options.tag);
|
|
720
|
-
// The journal owner creates this directory; never follow/create an unexpected root here.
|
|
721
|
-
await assertRegularPath(options.artifactDirectory, true);
|
|
722
|
-
for (let index = 0; index < assets.length; index++) {
|
|
723
|
-
const asset = assets[index];
|
|
724
|
-
const inputPath = plugins.path.join(
|
|
725
|
-
options.repositoryRoot,
|
|
726
|
-
[...paths][index],
|
|
727
|
-
);
|
|
728
|
-
const input = await openRegularFile(inputPath);
|
|
729
|
-
try {
|
|
730
|
-
await verifyHandle(input, asset);
|
|
731
|
-
const outputPath = plugins.path.join(
|
|
732
|
-
options.artifactDirectory,
|
|
733
|
-
asset.fileName,
|
|
734
|
-
);
|
|
735
|
-
const output = await plugins.fs.open(outputPath, "wx", 0o600);
|
|
736
|
-
try {
|
|
737
|
-
let position = 0;
|
|
738
|
-
for await (const chunk of input.createReadStream({
|
|
739
|
-
autoClose: false,
|
|
740
|
-
start: 0,
|
|
741
|
-
highWaterMark: 64 * 1024,
|
|
742
|
-
})) {
|
|
743
|
-
if (position + chunk.length > asset.size)
|
|
744
|
-
throw new Error("Gitea asset changed during freezing.");
|
|
745
|
-
let written = 0;
|
|
746
|
-
while (written < chunk.length) {
|
|
747
|
-
const result = await output.write(
|
|
748
|
-
chunk,
|
|
749
|
-
written,
|
|
750
|
-
chunk.length - written,
|
|
751
|
-
position + written,
|
|
752
|
-
);
|
|
753
|
-
if (!result.bytesWritten)
|
|
754
|
-
throw new Error("Unable to freeze complete Gitea asset bytes.");
|
|
755
|
-
written += result.bytesWritten;
|
|
756
|
-
}
|
|
757
|
-
position += chunk.length;
|
|
758
|
-
}
|
|
759
|
-
await output.sync();
|
|
760
|
-
} finally {
|
|
761
|
-
await output.close();
|
|
762
|
-
}
|
|
763
|
-
// Includes detecting same-size mutation between the validation and copy passes.
|
|
764
|
-
await validateGiteaAssets(options.artifactDirectory, [asset]);
|
|
765
|
-
} finally {
|
|
766
|
-
await input.close();
|
|
767
|
-
}
|
|
768
|
-
}
|
|
769
|
-
return assets;
|
|
770
|
-
};
|
|
247
|
+
export const prepareGiteaAssets = (
|
|
248
|
+
options: IPrepareReleaseAssetsOptions,
|
|
249
|
+
): Promise<IReleaseFrozenAsset[]> =>
|
|
250
|
+
prepareReleaseAssets("giteaAssets", options);
|
|
771
251
|
|
|
772
252
|
interface IGiteaAttachmentIdentity {
|
|
773
253
|
id: number;
|
|
@@ -777,12 +257,12 @@ interface IGiteaAttachmentIdentity {
|
|
|
777
257
|
|
|
778
258
|
/** No method retries a remote mutation. The release journal owns attempt admission. */
|
|
779
259
|
export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
780
|
-
private readonly destination:
|
|
260
|
+
private readonly destination: IReleaseAssetDestination;
|
|
781
261
|
private readonly tag: string;
|
|
782
262
|
private readonly commit: string;
|
|
783
263
|
readonly #token: string;
|
|
784
264
|
private readonly fetchImplementation: typeof fetch;
|
|
785
|
-
private readonly limits:
|
|
265
|
+
private readonly limits: IReleaseAssetTransferLimits;
|
|
786
266
|
private readonly tagProcessingTimeoutMs: number;
|
|
787
267
|
private readonly tagProcessingPollIntervalMs: number;
|
|
788
268
|
private readonly repositoryApiPath: string;
|
|
@@ -795,7 +275,7 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
795
275
|
|
|
796
276
|
constructor(options: IGiteaAssetsClientOptions) {
|
|
797
277
|
this.destination = normalizeGiteaAssetDestination(options.destination);
|
|
798
|
-
|
|
278
|
+
assertReleaseAssetTag("giteaAssets", options.tag);
|
|
799
279
|
if (!/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(options.commit))
|
|
800
280
|
throw new Error("Gitea assets require the exact release commit.");
|
|
801
281
|
if (
|
|
@@ -808,15 +288,16 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
808
288
|
this.commit = options.commit;
|
|
809
289
|
this.#token = options.token;
|
|
810
290
|
this.fetchImplementation = options.fetchImplementation ?? fetch;
|
|
811
|
-
this.limits =
|
|
291
|
+
this.limits = assertReleaseAssetTransferLimits("giteaAssets", {
|
|
812
292
|
responseTimeoutMs:
|
|
813
293
|
options.responseTimeoutMs ??
|
|
814
|
-
|
|
294
|
+
defaultReleaseAssetTransferLimits.responseTimeoutMs,
|
|
815
295
|
stallTimeoutMs:
|
|
816
|
-
options.stallTimeoutMs ??
|
|
296
|
+
options.stallTimeoutMs ??
|
|
297
|
+
defaultReleaseAssetTransferLimits.stallTimeoutMs,
|
|
817
298
|
minimumBytesPerSecond:
|
|
818
299
|
options.minimumBytesPerSecond ??
|
|
819
|
-
|
|
300
|
+
defaultReleaseAssetTransferLimits.minimumBytesPerSecond,
|
|
820
301
|
});
|
|
821
302
|
this.tagProcessingTimeoutMs =
|
|
822
303
|
options.tagProcessingTimeoutMs ?? defaultGiteaTagProcessingTimeoutMs;
|
|
@@ -844,7 +325,7 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
844
325
|
body?: string;
|
|
845
326
|
/** Streams exactly `size` bytes of the open file; progress means accepted by the transport. */
|
|
846
327
|
upload?: {
|
|
847
|
-
handle:
|
|
328
|
+
handle: TReleaseAssetFileHandle;
|
|
848
329
|
size: number;
|
|
849
330
|
};
|
|
850
331
|
headers?: Record<string, string>;
|
|
@@ -862,7 +343,12 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
862
343
|
try {
|
|
863
344
|
let body: BodyInit | undefined = options.body;
|
|
864
345
|
if (options.upload) {
|
|
865
|
-
body =
|
|
346
|
+
body = createReleaseAssetUploadBody(
|
|
347
|
+
"giteaAssets",
|
|
348
|
+
options.upload.handle,
|
|
349
|
+
options.upload.size,
|
|
350
|
+
watchdog,
|
|
351
|
+
);
|
|
866
352
|
watchdog.progress("sent", 0);
|
|
867
353
|
} else {
|
|
868
354
|
watchdog.awaitResponse();
|
|
@@ -887,7 +373,8 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
887
373
|
if (response.status !== (method === "POST" ? 201 : 200)) {
|
|
888
374
|
throw new GiteaAssetHttpError(method, response.status);
|
|
889
375
|
}
|
|
890
|
-
const bytes = await
|
|
376
|
+
const bytes = await readReleaseAssetResponse(
|
|
377
|
+
"giteaAssets",
|
|
891
378
|
response,
|
|
892
379
|
maximumMetadataBytes,
|
|
893
380
|
watchdog,
|
|
@@ -898,7 +385,7 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
898
385
|
if (watchdog.failure) throw watchdog.failure;
|
|
899
386
|
if (error instanceof GiteaAssetHttpError) throw error;
|
|
900
387
|
throw new GiteaAssetInconclusiveError(
|
|
901
|
-
`Gitea asset ${method} result is inconclusive ${
|
|
388
|
+
`Gitea asset ${method} result is inconclusive ${describeReleaseAssetRequestFailure(
|
|
902
389
|
error,
|
|
903
390
|
{
|
|
904
391
|
status: response?.status,
|
|
@@ -913,70 +400,6 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
913
400
|
}
|
|
914
401
|
}
|
|
915
402
|
|
|
916
|
-
/** Pull-driven: the next chunk is read only when fetch has taken the last one. */
|
|
917
|
-
private uploadBody(
|
|
918
|
-
handle: Awaited<ReturnType<typeof openRegularFile>>,
|
|
919
|
-
size: number,
|
|
920
|
-
watchdog: GiteaTransferWatchdog,
|
|
921
|
-
): ReadableStream<Uint8Array> {
|
|
922
|
-
let position = 0;
|
|
923
|
-
return new ReadableStream<Uint8Array>(
|
|
924
|
-
{
|
|
925
|
-
pull: async (controller) => {
|
|
926
|
-
if (position === size) {
|
|
927
|
-
watchdog.awaitAcknowledgement();
|
|
928
|
-
controller.close();
|
|
929
|
-
return;
|
|
930
|
-
}
|
|
931
|
-
const chunk = Buffer.allocUnsafe(Math.min(64 * 1024, size - position));
|
|
932
|
-
const { bytesRead } = await handle.read(
|
|
933
|
-
chunk,
|
|
934
|
-
0,
|
|
935
|
-
chunk.length,
|
|
936
|
-
position,
|
|
937
|
-
);
|
|
938
|
-
if (bytesRead === 0)
|
|
939
|
-
throw new Error("Gitea asset changed during upload.");
|
|
940
|
-
position += bytesRead;
|
|
941
|
-
watchdog.progress("sent", bytesRead);
|
|
942
|
-
controller.enqueue(chunk.subarray(0, bytesRead));
|
|
943
|
-
},
|
|
944
|
-
},
|
|
945
|
-
{ highWaterMark: 0 },
|
|
946
|
-
);
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
private async readResponse(
|
|
950
|
-
response: Response,
|
|
951
|
-
maximum: number,
|
|
952
|
-
watchdog: GiteaTransferWatchdog,
|
|
953
|
-
): Promise<Buffer> {
|
|
954
|
-
if (!response.body) throw new Error("Missing Gitea response body.");
|
|
955
|
-
const declared = response.headers.get("content-length");
|
|
956
|
-
if (
|
|
957
|
-
declared !== null &&
|
|
958
|
-
(!/^\d+$/.test(declared) || Number(declared) > maximum)
|
|
959
|
-
)
|
|
960
|
-
throw new Error("Oversized Gitea response.");
|
|
961
|
-
const reader = response.body.getReader();
|
|
962
|
-
const chunks: Buffer[] = [];
|
|
963
|
-
let size = 0;
|
|
964
|
-
try {
|
|
965
|
-
while (true) {
|
|
966
|
-
const result = await reader.read();
|
|
967
|
-
if (result.done) break;
|
|
968
|
-
watchdog.progress("received", result.value.byteLength);
|
|
969
|
-
size += result.value.byteLength;
|
|
970
|
-
if (size > maximum) throw new Error("Oversized Gitea response.");
|
|
971
|
-
chunks.push(Buffer.from(result.value));
|
|
972
|
-
}
|
|
973
|
-
} finally {
|
|
974
|
-
await reader.cancel().catch(() => undefined);
|
|
975
|
-
reader.releaseLock();
|
|
976
|
-
}
|
|
977
|
-
return Buffer.concat(chunks, size);
|
|
978
|
-
}
|
|
979
|
-
|
|
980
403
|
private async admitRepository(
|
|
981
404
|
authenticated: boolean,
|
|
982
405
|
): Promise<Record<string, unknown>> {
|
|
@@ -1139,7 +562,7 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1139
562
|
error,
|
|
1140
563
|
watchdog.failure
|
|
1141
564
|
? `(${watchdog.failure.name}: ${watchdog.failure.message})`
|
|
1142
|
-
:
|
|
565
|
+
: describeReleaseAssetRequestFailure(error, {
|
|
1143
566
|
status: response?.status,
|
|
1144
567
|
progress: "headers only",
|
|
1145
568
|
}),
|
|
@@ -1170,7 +593,7 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1170
593
|
);
|
|
1171
594
|
if (result.outcome === "timeout")
|
|
1172
595
|
throw new GiteaTagProcessingTimeoutError(
|
|
1173
|
-
`Gitea has not processed the pushed tag ${this.tag} within ${
|
|
596
|
+
`Gitea has not processed the pushed tag ${this.tag} within ${formatReleaseAssetSeconds(result.elapsedMs)}; the draft release was not created, because Gitea publishes a draft it finds for the tag once it processes the push. Resume once Gitea shows the tag.` +
|
|
1174
597
|
(result.lastError
|
|
1175
598
|
? ` Last page check error: ${result.lastError}`
|
|
1176
599
|
: ""),
|
|
@@ -1223,7 +646,7 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1223
646
|
*/
|
|
1224
647
|
public async publishRelease(
|
|
1225
648
|
releaseId: number,
|
|
1226
|
-
expected:
|
|
649
|
+
expected: IReleaseFrozenAsset[],
|
|
1227
650
|
expectedDraft: boolean,
|
|
1228
651
|
): Promise<void> {
|
|
1229
652
|
positiveId(releaseId);
|
|
@@ -1317,7 +740,7 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1317
740
|
* only to the configured Gitea origin and never along a redirect elsewhere.
|
|
1318
741
|
*/
|
|
1319
742
|
private async openAttachment(
|
|
1320
|
-
asset:
|
|
743
|
+
asset: IReleaseFrozenAsset,
|
|
1321
744
|
authenticated: boolean,
|
|
1322
745
|
watchdog: GiteaTransferWatchdog,
|
|
1323
746
|
onStatus: (status: number | undefined) => void,
|
|
@@ -1361,7 +784,7 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1361
784
|
* downloaded with the token. Both serve the same stored object.
|
|
1362
785
|
*/
|
|
1363
786
|
private async verifyAttachmentBytes(
|
|
1364
|
-
asset:
|
|
787
|
+
asset: IReleaseFrozenAsset,
|
|
1365
788
|
authenticated: boolean,
|
|
1366
789
|
): Promise<void> {
|
|
1367
790
|
const watchdog = new GiteaTransferWatchdog(
|
|
@@ -1387,7 +810,10 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1387
810
|
!response.body ||
|
|
1388
811
|
(response.headers.get("content-encoding") ?? "identity") !== "identity"
|
|
1389
812
|
)
|
|
1390
|
-
throw new
|
|
813
|
+
throw new ReleaseAssetRequestError(
|
|
814
|
+
"giteaAssets",
|
|
815
|
+
"asset-not-downloadable",
|
|
816
|
+
);
|
|
1391
817
|
const length = response.headers.get("content-length");
|
|
1392
818
|
if (
|
|
1393
819
|
length !== null &&
|
|
@@ -1418,7 +844,7 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1418
844
|
if (watchdog.failure) throw watchdog.failure;
|
|
1419
845
|
if (error instanceof GiteaAssetConflictError) throw error;
|
|
1420
846
|
throw new GiteaAssetInconclusiveError(
|
|
1421
|
-
`Gitea ${authenticated ? "draft" : "public"} asset verification is inconclusive ${
|
|
847
|
+
`Gitea ${authenticated ? "draft" : "public"} asset verification is inconclusive ${describeReleaseAssetRequestFailure(
|
|
1422
848
|
error,
|
|
1423
849
|
{ status, progress: `${size} of ${asset.size} bytes received` },
|
|
1424
850
|
)}; inspect availability before publication.`,
|
|
@@ -1436,7 +862,7 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1436
862
|
* hashed from the same stored object while the release was a draft.
|
|
1437
863
|
*/
|
|
1438
864
|
private async verifyAnonymousAvailability(
|
|
1439
|
-
asset:
|
|
865
|
+
asset: IReleaseFrozenAsset,
|
|
1440
866
|
): Promise<void> {
|
|
1441
867
|
const watchdog = new GiteaTransferWatchdog(
|
|
1442
868
|
"download",
|
|
@@ -1457,14 +883,17 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1457
883
|
length === null ||
|
|
1458
884
|
!/^\d+$/.test(length)
|
|
1459
885
|
)
|
|
1460
|
-
throw new
|
|
886
|
+
throw new ReleaseAssetRequestError(
|
|
887
|
+
"giteaAssets",
|
|
888
|
+
"asset-not-anonymously-downloadable",
|
|
889
|
+
);
|
|
1461
890
|
if (Number(length) !== asset.size)
|
|
1462
891
|
throw new GiteaAssetConflictError("Anonymous asset size mismatch.");
|
|
1463
892
|
} catch (error) {
|
|
1464
893
|
if (watchdog.failure) throw watchdog.failure;
|
|
1465
894
|
if (error instanceof GiteaAssetConflictError) throw error;
|
|
1466
895
|
throw new GiteaAssetInconclusiveError(
|
|
1467
|
-
`Gitea public asset availability is inconclusive ${
|
|
896
|
+
`Gitea public asset availability is inconclusive ${describeReleaseAssetRequestFailure(
|
|
1468
897
|
error,
|
|
1469
898
|
{ status, progress: "headers only" },
|
|
1470
899
|
)}; inspect the published release.`,
|
|
@@ -1482,7 +911,7 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1482
911
|
*/
|
|
1483
912
|
private attachment(
|
|
1484
913
|
value: unknown,
|
|
1485
|
-
asset:
|
|
914
|
+
asset: IReleaseFrozenAsset,
|
|
1486
915
|
): IGiteaAttachmentIdentity {
|
|
1487
916
|
const attachment = record(value);
|
|
1488
917
|
const id = positiveId(attachment.id);
|
|
@@ -1507,7 +936,7 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1507
936
|
* verified: the download is repeated.
|
|
1508
937
|
*/
|
|
1509
938
|
private bytesVerified(
|
|
1510
|
-
asset:
|
|
939
|
+
asset: IReleaseFrozenAsset,
|
|
1511
940
|
identity: IGiteaAttachmentIdentity,
|
|
1512
941
|
): boolean {
|
|
1513
942
|
const verified = this.#bytesVerified.get(asset.name);
|
|
@@ -1521,8 +950,8 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1521
950
|
|
|
1522
951
|
private async inspectAssetsWithIds(
|
|
1523
952
|
releaseId: number,
|
|
1524
|
-
expected:
|
|
1525
|
-
verify: readonly
|
|
953
|
+
expected: IReleaseFrozenAsset[],
|
|
954
|
+
verify: readonly IReleaseFrozenAsset[],
|
|
1526
955
|
/** Skip the download of an attachment this client already verified, unchanged. */
|
|
1527
956
|
reuseVerifiedBytes = false,
|
|
1528
957
|
): Promise<{
|
|
@@ -1540,9 +969,12 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1540
969
|
`${this.repositoryApiPath}/releases/${releaseId}/assets`,
|
|
1541
970
|
release.draft,
|
|
1542
971
|
);
|
|
1543
|
-
if (
|
|
972
|
+
if (
|
|
973
|
+
!Array.isArray(values) ||
|
|
974
|
+
values.length > releaseAssetTargets.giteaAssets.maximumAssets
|
|
975
|
+
)
|
|
1544
976
|
throw new Error("Invalid Gitea attachment list.");
|
|
1545
|
-
const present:
|
|
977
|
+
const present: IReleaseFrozenAsset[] = [];
|
|
1546
978
|
const seenNames = new Set<string>();
|
|
1547
979
|
const seenIds = new Set<number>();
|
|
1548
980
|
const attachments = new Map<string, IGiteaAttachmentIdentity>();
|
|
@@ -1588,8 +1020,8 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1588
1020
|
*/
|
|
1589
1021
|
public async inspectAssets(
|
|
1590
1022
|
releaseId: number,
|
|
1591
|
-
expected:
|
|
1592
|
-
verify: readonly
|
|
1023
|
+
expected: IReleaseFrozenAsset[],
|
|
1024
|
+
verify: readonly IReleaseFrozenAsset[] = expected,
|
|
1593
1025
|
): Promise<IGiteaAssetInspection> {
|
|
1594
1026
|
return (await this.inspectAssetsWithIds(releaseId, expected, verify))
|
|
1595
1027
|
.inspection;
|
|
@@ -1597,17 +1029,18 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1597
1029
|
|
|
1598
1030
|
public async uploadAsset(
|
|
1599
1031
|
releaseId: number,
|
|
1600
|
-
asset:
|
|
1032
|
+
asset: IReleaseFrozenAsset,
|
|
1601
1033
|
artifactDirectory: string,
|
|
1602
1034
|
expectedDraft: boolean,
|
|
1603
1035
|
): Promise<void> {
|
|
1604
1036
|
positiveId(releaseId);
|
|
1605
1037
|
assertGiteaFrozenAssets([asset], this.destination, this.tag);
|
|
1606
|
-
const handle = await
|
|
1038
|
+
const handle = await openReleaseAssetFile(
|
|
1039
|
+
"giteaAssets",
|
|
1607
1040
|
plugins.path.join(artifactDirectory, asset.fileName),
|
|
1608
1041
|
);
|
|
1609
1042
|
try {
|
|
1610
|
-
await
|
|
1043
|
+
await verifyReleaseAssetFile("giteaAssets", handle, asset);
|
|
1611
1044
|
const release = await this.inspectRelease();
|
|
1612
1045
|
if (release?.id !== releaseId)
|
|
1613
1046
|
throw new GiteaAssetConflictError(
|
|
@@ -1653,7 +1086,7 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1653
1086
|
|
|
1654
1087
|
public async verifyComplete(
|
|
1655
1088
|
releaseId: number,
|
|
1656
|
-
expected:
|
|
1089
|
+
expected: IReleaseFrozenAsset[],
|
|
1657
1090
|
): Promise<void> {
|
|
1658
1091
|
const { inspection, attachments, release } =
|
|
1659
1092
|
await this.inspectAssetsWithIds(releaseId, expected, expected, true);
|