@git.zone/cli 8.3.2 → 8.5.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/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/helpers.workflow.d.ts +29 -0
- package/dist_ts/helpers.workflow.js +37 -2
- package/dist_ts/mod_config/index.js +45 -3
- package/dist_ts/mod_release/classes.releasejournal.d.ts +19 -3
- package/dist_ts/mod_release/classes.releasejournal.js +108 -13
- package/dist_ts/mod_release/helpers.giteaassets.d.ts +47 -1
- package/dist_ts/mod_release/helpers.giteaassets.js +236 -56
- package/dist_ts/mod_release/helpers.npmartifact.d.ts +68 -7
- package/dist_ts/mod_release/helpers.npmartifact.js +192 -26
- package/dist_ts/mod_release/helpers.releasebranch.d.ts +11 -0
- package/dist_ts/mod_release/helpers.releasebranch.js +88 -61
- package/dist_ts/mod_release/helpers.releaseline.d.ts +60 -0
- package/dist_ts/mod_release/helpers.releaseline.js +129 -0
- package/dist_ts/mod_release/helpers.releasephase.d.ts +9 -0
- package/dist_ts/mod_release/helpers.releasephase.js +25 -0
- package/dist_ts/mod_release/helpers.releasepreparation.js +6 -3
- package/dist_ts/mod_release/helpers.releasepublication.d.ts +12 -1
- package/dist_ts/mod_release/helpers.releasepublication.js +235 -52
- package/dist_ts/mod_release/helpers.releaseversion.d.ts +2 -0
- package/dist_ts/mod_release/helpers.releaseversion.js +4 -2
- package/dist_ts/mod_release/index.js +149 -44
- package/dist_ts/mod_release/interfaces.giteaassets.d.ts +16 -0
- package/package.json +5 -5
- package/readme.md +224 -17
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/helpers.workflow.ts +87 -0
- package/ts/mod_config/index.ts +50 -1
- package/ts/mod_release/classes.releasejournal.ts +165 -14
- package/ts/mod_release/helpers.giteaassets.ts +319 -64
- package/ts/mod_release/helpers.npmartifact.ts +302 -22
- package/ts/mod_release/helpers.releasebranch.ts +120 -45
- package/ts/mod_release/helpers.releaseline.ts +214 -0
- package/ts/mod_release/helpers.releasephase.ts +26 -0
- package/ts/mod_release/helpers.releasepreparation.ts +12 -3
- package/ts/mod_release/helpers.releasepublication.ts +425 -78
- package/ts/mod_release/helpers.releaseversion.ts +5 -1
- package/ts/mod_release/index.ts +213 -32
- package/ts/mod_release/interfaces.giteaassets.ts +19 -0
|
@@ -85,6 +85,15 @@ export const defaultGiteaAssetTransferLimits: Readonly<IGiteaAssetTransferLimits
|
|
|
85
85
|
minimumBytesPerSecond: 256 * 1024,
|
|
86
86
|
});
|
|
87
87
|
|
|
88
|
+
/** Attachments a release publishes at the same time unless configured otherwise. */
|
|
89
|
+
export const defaultGiteaAssetConcurrency = 2;
|
|
90
|
+
/**
|
|
91
|
+
* Upper bound of `release.targets.giteaAssets.concurrency`. Every transfer has
|
|
92
|
+
* to hold the rate floor on its own, so N concurrent transfers need N times the
|
|
93
|
+
* floor of the link.
|
|
94
|
+
*/
|
|
95
|
+
export const maximumGiteaAssetConcurrency = 6;
|
|
96
|
+
|
|
88
97
|
const maximumTransferTimeoutMs = 60 * 60_000;
|
|
89
98
|
const maximumBytesPerSecond = 1024 * 1024 * 1024;
|
|
90
99
|
/** Node fires longer timers immediately; a ceiling this far out never binds. */
|
|
@@ -715,6 +724,12 @@ export const prepareGiteaAssets = async (
|
|
|
715
724
|
return assets;
|
|
716
725
|
};
|
|
717
726
|
|
|
727
|
+
interface IGiteaAttachmentIdentity {
|
|
728
|
+
id: number;
|
|
729
|
+
/** Absent only for a server that does not report attachment UUIDs. */
|
|
730
|
+
uuid: string | undefined;
|
|
731
|
+
}
|
|
732
|
+
|
|
718
733
|
/** No method retries a remote mutation. The release journal owns attempt admission. */
|
|
719
734
|
export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
720
735
|
private readonly destination: IGiteaAssetDestination;
|
|
@@ -724,6 +739,12 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
724
739
|
private readonly fetchImplementation: typeof fetch;
|
|
725
740
|
private readonly limits: IGiteaAssetTransferLimits;
|
|
726
741
|
private readonly repositoryApiPath: string;
|
|
742
|
+
/**
|
|
743
|
+
* The attachment identity this client downloaded and hashed against each
|
|
744
|
+
* frozen asset, by name. Only this process's own downloads count, so a
|
|
745
|
+
* resume, which builds a new client, downloads every attachment again.
|
|
746
|
+
*/
|
|
747
|
+
readonly #bytesVerified = new Map<string, IGiteaAttachmentIdentity>();
|
|
727
748
|
|
|
728
749
|
constructor(options: IGiteaAssetsClientOptions) {
|
|
729
750
|
this.destination = normalizeGiteaAssetDestination(options.destination);
|
|
@@ -757,7 +778,7 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
757
778
|
path: string,
|
|
758
779
|
authenticated: boolean,
|
|
759
780
|
options: {
|
|
760
|
-
method?: "GET" | "POST";
|
|
781
|
+
method?: "GET" | "POST" | "PATCH";
|
|
761
782
|
body?: string;
|
|
762
783
|
/** Streams exactly `size` bytes of the open file; progress means accepted by the transport. */
|
|
763
784
|
upload?: {
|
|
@@ -978,7 +999,7 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
978
999
|
const publicUrl = `${this.destination.apiOrigin}/${this.destination.owner}/${this.destination.repository}/releases/tag/${encodeURIComponent(this.tag)}`;
|
|
979
1000
|
if (
|
|
980
1001
|
release.tag_name !== this.tag ||
|
|
981
|
-
release.draft !==
|
|
1002
|
+
typeof release.draft !== "boolean" ||
|
|
982
1003
|
release.prerelease !== false ||
|
|
983
1004
|
release.html_url !== publicUrl ||
|
|
984
1005
|
release.url !==
|
|
@@ -987,7 +1008,7 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
987
1008
|
throw new GiteaAssetConflictError(
|
|
988
1009
|
"Gitea release identity conflicts with the exact public release.",
|
|
989
1010
|
);
|
|
990
|
-
return { id, tag: this.tag, publicUrl };
|
|
1011
|
+
return { id, tag: this.tag, publicUrl, draft: release.draft };
|
|
991
1012
|
}
|
|
992
1013
|
|
|
993
1014
|
public async inspectRelease(): Promise<IGiteaRelease | null> {
|
|
@@ -998,12 +1019,25 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
998
1019
|
});
|
|
999
1020
|
const anonymous = await this.requestJson(path, false, { allow404: true });
|
|
1000
1021
|
if (authenticated === null && anonymous === null) return null;
|
|
1001
|
-
if (authenticated === null
|
|
1022
|
+
if (authenticated === null)
|
|
1002
1023
|
throw new Error(
|
|
1003
1024
|
"Gitea release visibility is inconclusive; public and authenticated lookups differ.",
|
|
1004
1025
|
);
|
|
1005
1026
|
const found = this.release(authenticated);
|
|
1006
|
-
|
|
1027
|
+
// Gitea shows a draft only to writers.
|
|
1028
|
+
if (found.draft) {
|
|
1029
|
+
if (anonymous !== null)
|
|
1030
|
+
throw new Error(
|
|
1031
|
+
"Gitea release visibility is inconclusive; a draft is publicly visible.",
|
|
1032
|
+
);
|
|
1033
|
+
return found;
|
|
1034
|
+
}
|
|
1035
|
+
if (anonymous === null)
|
|
1036
|
+
throw new Error(
|
|
1037
|
+
"Gitea release visibility is inconclusive; public and authenticated lookups differ.",
|
|
1038
|
+
);
|
|
1039
|
+
const published = this.release(anonymous);
|
|
1040
|
+
if (published.id !== found.id || published.draft)
|
|
1007
1041
|
throw new GiteaAssetConflictError(
|
|
1008
1042
|
"Gitea release is not anonymously available with the same identity.",
|
|
1009
1043
|
);
|
|
@@ -1022,7 +1056,8 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1022
1056
|
tag_name: this.tag,
|
|
1023
1057
|
target_commitish: this.commit,
|
|
1024
1058
|
name: this.tag,
|
|
1025
|
-
|
|
1059
|
+
// Nothing is public before every attachment verified; see publishRelease.
|
|
1060
|
+
draft: true,
|
|
1026
1061
|
prerelease: false,
|
|
1027
1062
|
}),
|
|
1028
1063
|
headers: { "Content-Type": "application/json" },
|
|
@@ -1041,7 +1076,151 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1041
1076
|
return result;
|
|
1042
1077
|
}
|
|
1043
1078
|
|
|
1044
|
-
|
|
1079
|
+
/**
|
|
1080
|
+
* Publishes a draft whose complete attachment set verified, then proves the
|
|
1081
|
+
* published release, its attachment set and every attachment's anonymous
|
|
1082
|
+
* download. Every listed attachment must be the one this client hashed, so
|
|
1083
|
+
* call verifyComplete first; anything else stays a draft. Gitea serves a draft's attachments to nobody without write
|
|
1084
|
+
* access, so no attachment was public before this moment. Setting
|
|
1085
|
+
* `draft: false` is idempotent: a release that is already published is only
|
|
1086
|
+
* verified.
|
|
1087
|
+
*/
|
|
1088
|
+
public async publishRelease(
|
|
1089
|
+
releaseId: number,
|
|
1090
|
+
expected: IGiteaFrozenAsset[],
|
|
1091
|
+
): Promise<void> {
|
|
1092
|
+
positiveId(releaseId);
|
|
1093
|
+
const { inspection, attachments, release } =
|
|
1094
|
+
await this.inspectAssetsWithIds(releaseId, expected, []);
|
|
1095
|
+
if (inspection.missing.length !== 0)
|
|
1096
|
+
throw new Error(
|
|
1097
|
+
"Gitea attachment set is incomplete; the release stays a draft.",
|
|
1098
|
+
);
|
|
1099
|
+
// Only attachments this run hashed may become public: each listed
|
|
1100
|
+
// attachment must be the exact one hashed, by id and UUID. A server that
|
|
1101
|
+
// reports no UUIDs is held to the id alone; its attachments were all
|
|
1102
|
+
// downloaded again by verifyComplete, and Gitea never replaces an
|
|
1103
|
+
// attachment's bytes under its id.
|
|
1104
|
+
for (const asset of expected) {
|
|
1105
|
+
const listed = attachments.get(asset.name);
|
|
1106
|
+
const hashed = this.#bytesVerified.get(asset.name);
|
|
1107
|
+
if (
|
|
1108
|
+
listed === undefined ||
|
|
1109
|
+
hashed === undefined ||
|
|
1110
|
+
listed.id !== hashed.id ||
|
|
1111
|
+
listed.uuid !== hashed.uuid
|
|
1112
|
+
)
|
|
1113
|
+
throw new GiteaAssetConflictError(
|
|
1114
|
+
`Gitea attachment ${asset.name} is not the one this run downloaded and hashed; the release stays ${release.draft ? "a draft" : "as it is"}.`,
|
|
1115
|
+
);
|
|
1116
|
+
}
|
|
1117
|
+
if (release.draft) {
|
|
1118
|
+
const updated = this.release(
|
|
1119
|
+
await this.requestJson(
|
|
1120
|
+
`${this.repositoryApiPath}/releases/${releaseId}`,
|
|
1121
|
+
true,
|
|
1122
|
+
{
|
|
1123
|
+
method: "PATCH",
|
|
1124
|
+
body: JSON.stringify({ draft: false }),
|
|
1125
|
+
headers: { "Content-Type": "application/json" },
|
|
1126
|
+
},
|
|
1127
|
+
),
|
|
1128
|
+
);
|
|
1129
|
+
if (updated.id !== releaseId || updated.draft)
|
|
1130
|
+
throw new GiteaAssetConflictError(
|
|
1131
|
+
"Published Gitea release identity cannot be verified.",
|
|
1132
|
+
);
|
|
1133
|
+
}
|
|
1134
|
+
const published = await this.inspectRelease();
|
|
1135
|
+
if (!published || published.id !== releaseId || published.draft)
|
|
1136
|
+
throw new Error(
|
|
1137
|
+
"Published Gitea release visibility is inconclusive; inspect before another mutation.",
|
|
1138
|
+
);
|
|
1139
|
+
const anonymousSet = await this.requestJson(
|
|
1140
|
+
`${this.repositoryApiPath}/releases/${releaseId}/assets`,
|
|
1141
|
+
false,
|
|
1142
|
+
);
|
|
1143
|
+
if (!Array.isArray(anonymousSet) || anonymousSet.length !== expected.length)
|
|
1144
|
+
throw new GiteaAssetConflictError(
|
|
1145
|
+
"Published Gitea attachment set differs from the verified set.",
|
|
1146
|
+
);
|
|
1147
|
+
const publicNames = new Set<string>();
|
|
1148
|
+
const publicIds = new Set<number>();
|
|
1149
|
+
for (const value of anonymousSet) {
|
|
1150
|
+
const asset = expected.find((entry) => entry.name === record(value).name);
|
|
1151
|
+
const verified = asset ? attachments.get(asset.name) : undefined;
|
|
1152
|
+
if (!asset || !verified || publicNames.has(asset.name))
|
|
1153
|
+
throw new GiteaAssetConflictError(
|
|
1154
|
+
"Published Gitea attachment set differs from the verified set.",
|
|
1155
|
+
);
|
|
1156
|
+
const identity = this.attachment(value, asset);
|
|
1157
|
+
if (
|
|
1158
|
+
publicIds.has(identity.id) ||
|
|
1159
|
+
identity.id !== verified.id ||
|
|
1160
|
+
identity.uuid !== verified.uuid
|
|
1161
|
+
)
|
|
1162
|
+
throw new GiteaAssetConflictError(
|
|
1163
|
+
"Published Gitea attachment set differs from the verified set.",
|
|
1164
|
+
);
|
|
1165
|
+
publicNames.add(asset.name);
|
|
1166
|
+
publicIds.add(identity.id);
|
|
1167
|
+
}
|
|
1168
|
+
for (const asset of expected) await this.verifyAnonymousAvailability(asset);
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
/**
|
|
1172
|
+
* Requests an attachment's download URL and follows at most five HTTPS
|
|
1173
|
+
* redirects. An authenticated request, which a draft needs, sends the token
|
|
1174
|
+
* only to the configured Gitea origin and never along a redirect elsewhere.
|
|
1175
|
+
*/
|
|
1176
|
+
private async openAttachment(
|
|
1177
|
+
asset: IGiteaFrozenAsset,
|
|
1178
|
+
authenticated: boolean,
|
|
1179
|
+
watchdog: GiteaTransferWatchdog,
|
|
1180
|
+
onStatus: (status: number | undefined) => void,
|
|
1181
|
+
): Promise<Response> {
|
|
1182
|
+
let url = new URL(asset.publicUrl);
|
|
1183
|
+
for (let redirects = 0; ; redirects++) {
|
|
1184
|
+
if (
|
|
1185
|
+
url.protocol !== "https:" ||
|
|
1186
|
+
url.username ||
|
|
1187
|
+
url.password ||
|
|
1188
|
+
url.hash
|
|
1189
|
+
)
|
|
1190
|
+
throw new GiteaAssetConflictError("Unsafe asset download redirect.");
|
|
1191
|
+
watchdog.awaitResponse();
|
|
1192
|
+
onStatus(undefined);
|
|
1193
|
+
const response = await this.fetchImplementation(url.href, {
|
|
1194
|
+
redirect: "manual",
|
|
1195
|
+
signal: watchdog.signal,
|
|
1196
|
+
headers: {
|
|
1197
|
+
"Accept-Encoding": "identity",
|
|
1198
|
+
...(authenticated && url.origin === this.destination.apiOrigin
|
|
1199
|
+
? { Authorization: `token ${this.#token}` }
|
|
1200
|
+
: {}),
|
|
1201
|
+
},
|
|
1202
|
+
});
|
|
1203
|
+
onStatus(response.status);
|
|
1204
|
+
watchdog.progress("received", 0);
|
|
1205
|
+
if (![301, 302, 303, 307, 308].includes(response.status))
|
|
1206
|
+
return response;
|
|
1207
|
+
const location = response.headers.get("location");
|
|
1208
|
+
await response.body?.cancel();
|
|
1209
|
+
if (redirects >= 5 || !location)
|
|
1210
|
+
throw new GiteaAssetConflictError("Invalid asset download redirect.");
|
|
1211
|
+
url = new URL(location, url);
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
/**
|
|
1216
|
+
* Downloads and hashes one attachment. A published release's attachment is
|
|
1217
|
+
* downloaded anonymously; a draft's attachment is not public yet, so it is
|
|
1218
|
+
* downloaded with the token. Both serve the same stored object.
|
|
1219
|
+
*/
|
|
1220
|
+
private async verifyAttachmentBytes(
|
|
1221
|
+
asset: IGiteaFrozenAsset,
|
|
1222
|
+
authenticated: boolean,
|
|
1223
|
+
): Promise<void> {
|
|
1045
1224
|
const watchdog = new GiteaTransferWatchdog(
|
|
1046
1225
|
"download",
|
|
1047
1226
|
this.limits,
|
|
@@ -1052,45 +1231,26 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1052
1231
|
let status: number | undefined;
|
|
1053
1232
|
let size = 0;
|
|
1054
1233
|
try {
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
throw new GiteaAssetConflictError("Unsafe anonymous asset redirect.");
|
|
1064
|
-
watchdog.awaitResponse();
|
|
1065
|
-
status = undefined;
|
|
1066
|
-
response = await this.fetchImplementation(url.href, {
|
|
1067
|
-
redirect: "manual",
|
|
1068
|
-
signal: watchdog.signal,
|
|
1069
|
-
headers: { "Accept-Encoding": "identity" },
|
|
1070
|
-
});
|
|
1071
|
-
status = response.status;
|
|
1072
|
-
watchdog.progress("received", 0);
|
|
1073
|
-
if (![301, 302, 303, 307, 308].includes(response.status)) break;
|
|
1074
|
-
if (redirects >= 5 || !response.headers.get("location"))
|
|
1075
|
-
throw new GiteaAssetConflictError(
|
|
1076
|
-
"Invalid anonymous asset redirect.",
|
|
1077
|
-
);
|
|
1078
|
-
const next = new URL(response.headers.get("location")!, url);
|
|
1079
|
-
await response.body?.cancel();
|
|
1080
|
-
url = next;
|
|
1081
|
-
}
|
|
1234
|
+
response = await this.openAttachment(
|
|
1235
|
+
asset,
|
|
1236
|
+
authenticated,
|
|
1237
|
+
watchdog,
|
|
1238
|
+
(value) => {
|
|
1239
|
+
status = value;
|
|
1240
|
+
},
|
|
1241
|
+
);
|
|
1082
1242
|
if (
|
|
1083
1243
|
response.status !== 200 ||
|
|
1084
1244
|
!response.body ||
|
|
1085
1245
|
(response.headers.get("content-encoding") ?? "identity") !== "identity"
|
|
1086
1246
|
)
|
|
1087
|
-
throw new Error("Asset is not
|
|
1247
|
+
throw new Error("Asset is not downloadable.");
|
|
1088
1248
|
const length = response.headers.get("content-length");
|
|
1089
1249
|
if (
|
|
1090
1250
|
length !== null &&
|
|
1091
1251
|
(!/^\d+$/.test(length) || Number(length) !== asset.size)
|
|
1092
1252
|
)
|
|
1093
|
-
throw new GiteaAssetConflictError("
|
|
1253
|
+
throw new GiteaAssetConflictError("Downloaded asset size mismatch.");
|
|
1094
1254
|
const hash = plugins.crypto.createHash("sha256");
|
|
1095
1255
|
const reader = response.body.getReader();
|
|
1096
1256
|
try {
|
|
@@ -1101,7 +1261,7 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1101
1261
|
size += next.value.byteLength;
|
|
1102
1262
|
if (size > asset.size)
|
|
1103
1263
|
throw new GiteaAssetConflictError(
|
|
1104
|
-
"
|
|
1264
|
+
"Downloaded asset exceeds its frozen size.",
|
|
1105
1265
|
);
|
|
1106
1266
|
hash.update(next.value);
|
|
1107
1267
|
}
|
|
@@ -1110,12 +1270,12 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1110
1270
|
reader.releaseLock();
|
|
1111
1271
|
}
|
|
1112
1272
|
if (size !== asset.size || hash.digest("hex") !== asset.sha256)
|
|
1113
|
-
throw new GiteaAssetConflictError("
|
|
1273
|
+
throw new GiteaAssetConflictError("Downloaded asset bytes mismatch.");
|
|
1114
1274
|
} catch (error) {
|
|
1115
1275
|
if (watchdog.failure) throw watchdog.failure;
|
|
1116
1276
|
if (error instanceof GiteaAssetConflictError) throw error;
|
|
1117
1277
|
throw new GiteaAssetInconclusiveError(
|
|
1118
|
-
`Gitea public asset verification is inconclusive ${describeGiteaRequestFailure(
|
|
1278
|
+
`Gitea ${authenticated ? "draft" : "public"} asset verification is inconclusive ${describeGiteaRequestFailure(
|
|
1119
1279
|
error,
|
|
1120
1280
|
{ status, progress: `${size} of ${asset.size} bytes received` },
|
|
1121
1281
|
)}; inspect availability before publication.`,
|
|
@@ -1127,42 +1287,122 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1127
1287
|
}
|
|
1128
1288
|
}
|
|
1129
1289
|
|
|
1130
|
-
|
|
1290
|
+
/**
|
|
1291
|
+
* Proves an attachment of a published release is served anonymously with
|
|
1292
|
+
* its frozen size, without downloading its bytes again: the bytes were
|
|
1293
|
+
* hashed from the same stored object while the release was a draft.
|
|
1294
|
+
*/
|
|
1295
|
+
private async verifyAnonymousAvailability(
|
|
1296
|
+
asset: IGiteaFrozenAsset,
|
|
1297
|
+
): Promise<void> {
|
|
1298
|
+
const watchdog = new GiteaTransferWatchdog(
|
|
1299
|
+
"download",
|
|
1300
|
+
this.limits,
|
|
1301
|
+
maximumMetadataBytes,
|
|
1302
|
+
);
|
|
1303
|
+
let response: Response | undefined;
|
|
1304
|
+
let status: number | undefined;
|
|
1305
|
+
try {
|
|
1306
|
+
response = await this.openAttachment(asset, false, watchdog, (value) => {
|
|
1307
|
+
status = value;
|
|
1308
|
+
});
|
|
1309
|
+
const length = response.headers.get("content-length");
|
|
1310
|
+
if (
|
|
1311
|
+
response.status !== 200 ||
|
|
1312
|
+
(response.headers.get("content-encoding") ?? "identity") !==
|
|
1313
|
+
"identity" ||
|
|
1314
|
+
length === null ||
|
|
1315
|
+
!/^\d+$/.test(length)
|
|
1316
|
+
)
|
|
1317
|
+
throw new Error("Asset is not anonymously downloadable.");
|
|
1318
|
+
if (Number(length) !== asset.size)
|
|
1319
|
+
throw new GiteaAssetConflictError("Anonymous asset size mismatch.");
|
|
1320
|
+
} catch (error) {
|
|
1321
|
+
if (watchdog.failure) throw watchdog.failure;
|
|
1322
|
+
if (error instanceof GiteaAssetConflictError) throw error;
|
|
1323
|
+
throw new GiteaAssetInconclusiveError(
|
|
1324
|
+
`Gitea public asset availability is inconclusive ${describeGiteaRequestFailure(
|
|
1325
|
+
error,
|
|
1326
|
+
{ status, progress: "headers only" },
|
|
1327
|
+
)}; inspect the published release.`,
|
|
1328
|
+
);
|
|
1329
|
+
} finally {
|
|
1330
|
+
watchdog.close();
|
|
1331
|
+
if (response?.body) await response.body.cancel().catch(() => undefined);
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
/**
|
|
1336
|
+
* The attachment's identity once its metadata matches the frozen asset.
|
|
1337
|
+
* Gitea stores an attachment's bytes under its UUID and its API can only
|
|
1338
|
+
* rename an attachment, so an unchanged id and UUID mean unchanged bytes.
|
|
1339
|
+
*/
|
|
1340
|
+
private attachment(
|
|
1341
|
+
value: unknown,
|
|
1342
|
+
asset: IGiteaFrozenAsset,
|
|
1343
|
+
): IGiteaAttachmentIdentity {
|
|
1131
1344
|
const attachment = record(value);
|
|
1132
1345
|
const id = positiveId(attachment.id);
|
|
1133
1346
|
if (
|
|
1134
1347
|
attachment.name !== asset.name ||
|
|
1135
1348
|
attachment.size !== asset.size ||
|
|
1136
|
-
attachment.browser_download_url !== asset.publicUrl
|
|
1349
|
+
attachment.browser_download_url !== asset.publicUrl ||
|
|
1350
|
+
(attachment.uuid !== undefined && typeof attachment.uuid !== "string")
|
|
1137
1351
|
)
|
|
1138
1352
|
throw new GiteaAssetConflictError(
|
|
1139
1353
|
"Gitea attachment metadata conflicts with the frozen asset.",
|
|
1140
1354
|
);
|
|
1141
|
-
return
|
|
1355
|
+
return {
|
|
1356
|
+
id,
|
|
1357
|
+
uuid: typeof attachment.uuid === "string" ? attachment.uuid : undefined,
|
|
1358
|
+
};
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
/**
|
|
1362
|
+
* Whether this client downloaded and hashed exactly this attachment, proven
|
|
1363
|
+
* by an unchanged id and UUID. Without a UUID, bytes are never taken as
|
|
1364
|
+
* verified: the download is repeated.
|
|
1365
|
+
*/
|
|
1366
|
+
private bytesVerified(
|
|
1367
|
+
asset: IGiteaFrozenAsset,
|
|
1368
|
+
identity: IGiteaAttachmentIdentity,
|
|
1369
|
+
): boolean {
|
|
1370
|
+
const verified = this.#bytesVerified.get(asset.name);
|
|
1371
|
+
return (
|
|
1372
|
+
verified !== undefined &&
|
|
1373
|
+
identity.uuid !== undefined &&
|
|
1374
|
+
verified.id === identity.id &&
|
|
1375
|
+
verified.uuid === identity.uuid
|
|
1376
|
+
);
|
|
1142
1377
|
}
|
|
1143
1378
|
|
|
1144
1379
|
private async inspectAssetsWithIds(
|
|
1145
1380
|
releaseId: number,
|
|
1146
1381
|
expected: IGiteaFrozenAsset[],
|
|
1147
1382
|
verify: readonly IGiteaFrozenAsset[],
|
|
1383
|
+
/** Skip the download of an attachment this client already verified, unchanged. */
|
|
1384
|
+
reuseVerifiedBytes = false,
|
|
1148
1385
|
): Promise<{
|
|
1149
1386
|
inspection: IGiteaAssetInspection;
|
|
1150
|
-
|
|
1387
|
+
attachments: Map<string, IGiteaAttachmentIdentity>;
|
|
1388
|
+
release: IGiteaRelease;
|
|
1151
1389
|
}> {
|
|
1152
1390
|
positiveId(releaseId);
|
|
1153
1391
|
assertGiteaFrozenAssets(expected, this.destination, this.tag);
|
|
1154
|
-
|
|
1392
|
+
const release = await this.inspectRelease();
|
|
1393
|
+
if (!release || release.id !== releaseId)
|
|
1155
1394
|
throw new GiteaAssetConflictError("Gitea release identifier changed.");
|
|
1395
|
+
// A draft's attachments are visible to writers only.
|
|
1156
1396
|
const values = await this.requestJson(
|
|
1157
1397
|
`${this.repositoryApiPath}/releases/${releaseId}/assets`,
|
|
1158
|
-
|
|
1398
|
+
release.draft,
|
|
1159
1399
|
);
|
|
1160
1400
|
if (!Array.isArray(values) || values.length > maximumAssets)
|
|
1161
1401
|
throw new Error("Invalid Gitea attachment list.");
|
|
1162
1402
|
const present: IGiteaFrozenAsset[] = [];
|
|
1163
1403
|
const seenNames = new Set<string>();
|
|
1164
1404
|
const seenIds = new Set<number>();
|
|
1165
|
-
const
|
|
1405
|
+
const attachments = new Map<string, IGiteaAttachmentIdentity>();
|
|
1166
1406
|
for (const value of values) {
|
|
1167
1407
|
const name = record(value).name;
|
|
1168
1408
|
const asset = expected.find((candidate) => candidate.name === name);
|
|
@@ -1170,16 +1410,23 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1170
1410
|
throw new GiteaAssetConflictError(
|
|
1171
1411
|
"Unexpected or duplicate Gitea release attachment.",
|
|
1172
1412
|
);
|
|
1173
|
-
const
|
|
1174
|
-
if (seenIds.has(id))
|
|
1413
|
+
const identity = this.attachment(value, asset);
|
|
1414
|
+
if (seenIds.has(identity.id))
|
|
1175
1415
|
throw new GiteaAssetConflictError(
|
|
1176
1416
|
"Duplicate Gitea release attachment identifier.",
|
|
1177
1417
|
);
|
|
1178
1418
|
seenNames.add(asset.name);
|
|
1179
|
-
seenIds.add(id);
|
|
1180
|
-
|
|
1181
|
-
if (
|
|
1182
|
-
|
|
1419
|
+
seenIds.add(identity.id);
|
|
1420
|
+
attachments.set(asset.name, identity);
|
|
1421
|
+
if (
|
|
1422
|
+
verify.some((candidate) => candidate.name === asset.name) &&
|
|
1423
|
+
!(reuseVerifiedBytes && this.bytesVerified(asset, identity))
|
|
1424
|
+
) {
|
|
1425
|
+
await this.verifyAttachmentBytes(asset, release.draft);
|
|
1426
|
+
// The final listing must still show this identity before the
|
|
1427
|
+
// download stands for it; verifyComplete and publishRelease check that.
|
|
1428
|
+
this.#bytesVerified.set(asset.name, identity);
|
|
1429
|
+
}
|
|
1183
1430
|
present.push(asset);
|
|
1184
1431
|
}
|
|
1185
1432
|
return {
|
|
@@ -1187,7 +1434,8 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1187
1434
|
present,
|
|
1188
1435
|
missing: expected.filter((asset) => !seenNames.has(asset.name)),
|
|
1189
1436
|
},
|
|
1190
|
-
|
|
1437
|
+
attachments,
|
|
1438
|
+
release,
|
|
1191
1439
|
};
|
|
1192
1440
|
}
|
|
1193
1441
|
|
|
@@ -1220,9 +1468,10 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1220
1468
|
throw new GiteaAssetConflictError(
|
|
1221
1469
|
"Gitea release identifier changed before upload.",
|
|
1222
1470
|
);
|
|
1471
|
+
// Authenticated: a writer also sees the attachments of a draft.
|
|
1223
1472
|
const listed = await this.requestJson(
|
|
1224
1473
|
`${this.repositoryApiPath}/releases/${releaseId}/assets`,
|
|
1225
|
-
|
|
1474
|
+
true,
|
|
1226
1475
|
);
|
|
1227
1476
|
if (!Array.isArray(listed))
|
|
1228
1477
|
throw new Error("Invalid Gitea attachment list.");
|
|
@@ -1244,6 +1493,8 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1244
1493
|
);
|
|
1245
1494
|
// The caller's inspection downloads and hashes the accepted attachment.
|
|
1246
1495
|
this.attachment(result, asset);
|
|
1496
|
+
// A new attachment replaces whatever this name was verified as before.
|
|
1497
|
+
this.#bytesVerified.delete(asset.name);
|
|
1247
1498
|
} finally {
|
|
1248
1499
|
await handle.close();
|
|
1249
1500
|
}
|
|
@@ -1253,23 +1504,21 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1253
1504
|
releaseId: number,
|
|
1254
1505
|
expected: IGiteaFrozenAsset[],
|
|
1255
1506
|
): Promise<void> {
|
|
1256
|
-
const { inspection,
|
|
1257
|
-
releaseId,
|
|
1258
|
-
expected,
|
|
1259
|
-
expected,
|
|
1260
|
-
);
|
|
1507
|
+
const { inspection, attachments, release } =
|
|
1508
|
+
await this.inspectAssetsWithIds(releaseId, expected, expected, true);
|
|
1261
1509
|
if (inspection.missing.length !== 0)
|
|
1262
1510
|
throw new Error(
|
|
1263
1511
|
"Gitea attachment set is incomplete; npm publication is blocked.",
|
|
1264
1512
|
);
|
|
1265
1513
|
// Recheck release/tag identity after potentially long full downloads.
|
|
1266
|
-
|
|
1514
|
+
const after = await this.inspectRelease();
|
|
1515
|
+
if (!after || after.id !== releaseId || after.draft !== release.draft)
|
|
1267
1516
|
throw new GiteaAssetConflictError(
|
|
1268
1517
|
"Gitea release changed during verification.",
|
|
1269
1518
|
);
|
|
1270
1519
|
const finalSet = await this.requestJson(
|
|
1271
1520
|
`${this.repositoryApiPath}/releases/${releaseId}/assets`,
|
|
1272
|
-
|
|
1521
|
+
release.draft,
|
|
1273
1522
|
);
|
|
1274
1523
|
if (!Array.isArray(finalSet) || finalSet.length !== expected.length)
|
|
1275
1524
|
throw new GiteaAssetConflictError(
|
|
@@ -1283,13 +1532,19 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1283
1532
|
throw new GiteaAssetConflictError(
|
|
1284
1533
|
"Gitea attachment set changed during verification.",
|
|
1285
1534
|
);
|
|
1286
|
-
const
|
|
1287
|
-
|
|
1535
|
+
const identity = this.attachment(value, asset);
|
|
1536
|
+
const listed = attachments.get(asset.name);
|
|
1537
|
+
if (
|
|
1538
|
+
ids.has(identity.id) ||
|
|
1539
|
+
listed === undefined ||
|
|
1540
|
+
listed.id !== identity.id ||
|
|
1541
|
+
listed.uuid !== identity.uuid
|
|
1542
|
+
)
|
|
1288
1543
|
throw new GiteaAssetConflictError(
|
|
1289
1544
|
"Gitea attachment set changed during verification.",
|
|
1290
1545
|
);
|
|
1291
1546
|
names.add(asset.name);
|
|
1292
|
-
ids.add(id);
|
|
1547
|
+
ids.add(identity.id);
|
|
1293
1548
|
}
|
|
1294
1549
|
}
|
|
1295
1550
|
}
|