@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.
Files changed (59) hide show
  1. package/assets/templates/npm/.package.json +1 -1
  2. package/assets/templates/service/.package.json +1 -1
  3. package/assets/templates/wcc/.package.json +1 -1
  4. package/assets/templates/website/.package.json +1 -1
  5. package/dist_ts/00_commitinfo_data.js +1 -1
  6. package/dist_ts/helpers.versionsource.d.ts +23 -5
  7. package/dist_ts/helpers.versionsource.js +115 -37
  8. package/dist_ts/helpers.workflow.d.ts +60 -17
  9. package/dist_ts/helpers.workflow.js +156 -51
  10. package/dist_ts/mod_config/index.js +98 -31
  11. package/dist_ts/mod_release/classes.releasejournal.d.ts +63 -8
  12. package/dist_ts/mod_release/classes.releasejournal.js +283 -124
  13. package/dist_ts/mod_release/helpers.cargorelease.d.ts +4 -3
  14. package/dist_ts/mod_release/helpers.cargorelease.js +5 -4
  15. package/dist_ts/mod_release/helpers.fossglobalassets.d.ts +61 -0
  16. package/dist_ts/mod_release/helpers.fossglobalassets.js +580 -0
  17. package/dist_ts/mod_release/helpers.giteaassets.d.ts +15 -51
  18. package/dist_ts/mod_release/helpers.giteaassets.js +40 -507
  19. package/dist_ts/mod_release/helpers.releaseassets.d.ts +40 -0
  20. package/dist_ts/mod_release/helpers.releaseassets.js +349 -0
  21. package/dist_ts/mod_release/helpers.releaseassettransfer.d.ts +67 -0
  22. package/dist_ts/mod_release/helpers.releaseassettransfer.js +239 -0
  23. package/dist_ts/mod_release/helpers.releasecheck.js +3 -2
  24. package/dist_ts/mod_release/helpers.releasepreparation.d.ts +7 -6
  25. package/dist_ts/mod_release/helpers.releasepreparation.js +34 -7
  26. package/dist_ts/mod_release/helpers.releasepublication.d.ts +8 -2
  27. package/dist_ts/mod_release/helpers.releasepublication.js +218 -54
  28. package/dist_ts/mod_release/helpers.releaseversionsource.d.ts +7 -5
  29. package/dist_ts/mod_release/helpers.releaseversionsource.js +9 -7
  30. package/dist_ts/mod_release/index.d.ts +1 -1
  31. package/dist_ts/mod_release/index.js +109 -68
  32. package/dist_ts/mod_release/interfaces.fossglobalassets.d.ts +108 -0
  33. package/dist_ts/mod_release/interfaces.fossglobalassets.js +2 -0
  34. package/dist_ts/mod_release/interfaces.giteaassets.d.ts +9 -43
  35. package/dist_ts/mod_release/interfaces.releaseassets.d.ts +68 -0
  36. package/dist_ts/mod_release/interfaces.releaseassets.js +2 -0
  37. package/dist_ts/plugins.d.ts +1 -0
  38. package/dist_ts/plugins.js +1 -1
  39. package/package.json +3 -2
  40. package/readme.md +338 -40
  41. package/ts/00_commitinfo_data.ts +1 -1
  42. package/ts/helpers.versionsource.ts +176 -45
  43. package/ts/helpers.workflow.ts +288 -78
  44. package/ts/mod_config/index.ts +130 -38
  45. package/ts/mod_release/classes.releasejournal.ts +499 -180
  46. package/ts/mod_release/helpers.cargorelease.ts +8 -3
  47. package/ts/mod_release/helpers.fossglobalassets.ts +886 -0
  48. package/ts/mod_release/helpers.giteaassets.ts +127 -694
  49. package/ts/mod_release/helpers.releaseassets.ts +516 -0
  50. package/ts/mod_release/helpers.releaseassettransfer.ts +339 -0
  51. package/ts/mod_release/helpers.releasecheck.ts +3 -1
  52. package/ts/mod_release/helpers.releasepreparation.ts +55 -12
  53. package/ts/mod_release/helpers.releasepublication.ts +351 -69
  54. package/ts/mod_release/helpers.releaseversionsource.ts +11 -7
  55. package/ts/mod_release/index.ts +151 -90
  56. package/ts/mod_release/interfaces.fossglobalassets.ts +127 -0
  57. package/ts/mod_release/interfaces.giteaassets.ts +14 -47
  58. package/ts/mod_release/interfaces.releaseassets.ts +96 -0
  59. package/ts/plugins.ts +3 -0
@@ -10,10 +10,12 @@ import {
10
10
  getReleaseCargo,
11
11
  getReleaseCargoRegistries,
12
12
  hasReleasePackages,
13
+ getReleaseAssets,
13
14
  type IReleaseCrateArtifact,
14
15
  type TReleaseJournal,
15
16
  type IReleaseJournalV2,
16
- type IReleaseJournalV4,
17
+ type IReleaseFossglobalAssetsJournal,
18
+ type IReleaseGiteaAssetsJournal,
17
19
  type IReleaseNpmRegistryJournal,
18
20
  type IReleaseTargetStatus,
19
21
  type TReleaseErrorCode,
@@ -26,16 +28,31 @@ import {
26
28
  defaultGiteaAssetConcurrency,
27
29
  maximumGiteaAssetConcurrency,
28
30
  validateGiteaAssets,
29
- type IGiteaAssetTransferLimits,
30
- type IGiteaFrozenAsset,
31
31
  type IGiteaRelease,
32
32
  } from "./helpers.giteaassets.js";
33
+ import {
34
+ FossglobalAssetsClient,
35
+ type IFossglobalAssetsClient,
36
+ type IFossglobalPresentAsset,
37
+ type IFossglobalRelease,
38
+ type IFossglobalReleaseClaim,
39
+ } from "./helpers.fossglobalassets.js";
40
+ import {
41
+ ReleaseAssetConflictError,
42
+ readReleaseAssetCredential,
43
+ releaseAssetTargets,
44
+ validateReleaseAssets,
45
+ type IReleaseAssetTransferLimits,
46
+ type IReleaseFrozenAsset,
47
+ type TReleaseAssetTargetName,
48
+ } from "./helpers.releaseassets.js";
33
49
  import {
34
50
  formatReleaseDuration,
35
51
  printReleasePhase,
36
52
  } from "./helpers.releasephase.js";
37
53
  import {
38
54
  assertGiteaAssetsGitDestination,
55
+ assertReleaseAssetsGitDestination,
39
56
  defaultCargoVerificationWindowMinutes,
40
57
  } from "../helpers.workflow.js";
41
58
  import {
@@ -123,10 +140,14 @@ export function buildReleaseGitPushArgs(
123
140
  return args;
124
141
  }
125
142
 
143
+ /** The release or one asset of a journal's release asset section. */
144
+ type TReleaseAssetSelector =
145
+ | { kind: "asset-release"; target: TReleaseAssetTargetName }
146
+ | { kind: "asset"; target: TReleaseAssetTargetName; name: string };
147
+
126
148
  type TReleaseTargetSelector =
127
149
  | { kind: "git" }
128
- | { kind: "gitea-release" }
129
- | { kind: "gitea-asset"; name: string }
150
+ | TReleaseAssetSelector
130
151
  | { kind: "npm"; registry: string; packageName?: string }
131
152
  | { kind: "cargo"; registry: string; crate: string }
132
153
  | { kind: "docker-qualification" }
@@ -161,9 +182,13 @@ export interface IReleasePublicationOptions {
161
182
  npmVerificationWindowMs?: number;
162
183
  tsdocker?: ITsdockerReleaseClient;
163
184
  /** Transfer bounds for the Gitea client built from the journal's destination. */
164
- giteaAssetTransfer?: IGiteaAssetTransferLimits;
185
+ giteaAssetTransfer?: IReleaseAssetTransferLimits;
165
186
  /** Attachments of a draft in progress at the same time (1 or 2); default 1. */
166
187
  giteaAssetConcurrency?: number;
188
+ /** Transfer bounds for the foss.global client built from the journal's destination. */
189
+ fossglobalAssetTransfer?: IReleaseAssetTransferLimits;
190
+ /** Replaces the foss.global client built from the journal's destination and credential. */
191
+ fossglobalAssets?: IFossglobalAssetsClient;
167
192
  /** Bound and retries of the Git target's remote commands. */
168
193
  gitRemotePolicy?: IReleaseGitRemotePolicy;
169
194
  /** The rsrepo engine that publishes and probes the journal's crates. */
@@ -199,18 +224,17 @@ const getTargetStatus = (
199
224
  if (selectorArg.kind === "git") {
200
225
  return journalArg.git;
201
226
  }
202
- if (
203
- selectorArg.kind === "gitea-release" ||
204
- selectorArg.kind === "gitea-asset"
205
- ) {
206
- if (journalArg.schemaVersion !== 4)
207
- throw new Error("Release journal has no Gitea assets.");
208
- if (selectorArg.kind === "gitea-release")
209
- return journalArg.giteaAssets.release;
210
- const entry = journalArg.giteaAssets.assets.find(
227
+ if (isReleaseAssetSelector(selectorArg)) {
228
+ const releaseAssets = getReleaseAssets(journalArg);
229
+ const { label } = releaseAssetTargets[selectorArg.target];
230
+ if (releaseAssets?.target !== selectorArg.target)
231
+ throw new Error(`Release journal has no ${label} assets.`);
232
+ if (selectorArg.kind === "asset-release")
233
+ return releaseAssets.section.release;
234
+ const entry = releaseAssets.section.assets.find(
211
235
  (entry) => entry.asset.name === selectorArg.name,
212
236
  );
213
- if (!entry) throw new Error("Release journal has no matching Gitea asset.");
237
+ if (!entry) throw new Error(`Release journal has no matching ${label} asset.`);
214
238
  return entry;
215
239
  }
216
240
  if (selectorArg.kind === "docker-qualification") {
@@ -291,17 +315,20 @@ const updateTarget = async (
291
315
  }
292
316
  updateArg(status);
293
317
  const finalized = finalizeJournalCompletion(currentArg);
294
- // A Gitea target never completes a journal on its own: completion is
295
- // recorded only after the complete attachment set verified.
296
- return isGiteaSelector(selectorArg) && currentArg.completedAt === null
318
+ // A release asset target never completes a journal on its own:
319
+ // completion is recorded only after the complete asset set verified.
320
+ return isReleaseAssetSelector(selectorArg) &&
321
+ currentArg.completedAt === null
297
322
  ? { ...finalized, completedAt: null }
298
323
  : finalized;
299
324
  },
300
325
  );
301
326
  };
302
327
 
303
- const isGiteaSelector = (selectorArg: TReleaseTargetSelector): boolean =>
304
- selectorArg.kind === "gitea-release" || selectorArg.kind === "gitea-asset";
328
+ const isReleaseAssetSelector = (
329
+ selectorArg: TReleaseTargetSelector,
330
+ ): selectorArg is TReleaseAssetSelector =>
331
+ selectorArg.kind === "asset-release" || selectorArg.kind === "asset";
305
332
 
306
333
  const claimTarget = async (
307
334
  storeArg: ReleaseJournalStore,
@@ -1279,10 +1306,19 @@ const finishDockerQualification = async (
1279
1306
  )) as IReleaseJournalV2;
1280
1307
  };
1281
1308
 
1309
+ interface IDockerCleanupOptions {
1310
+ /**
1311
+ * Keeps `completedAt` unset: the caller records the completion later,
1312
+ * after the release asset set's final verification.
1313
+ */
1314
+ deferCompletion?: boolean;
1315
+ }
1316
+
1282
1317
  const finishDockerCleanup = async (
1283
1318
  optionsArg: IReleasePublicationOptions,
1284
1319
  journalArg: IReleaseJournalV2,
1285
1320
  resultArg: IReleaseJournalV2["docker"]["cleanup"]["result"],
1321
+ cleanupOptionsArg: IDockerCleanupOptions,
1286
1322
  ): Promise<IReleaseJournalV2> => {
1287
1323
  const attemptId = journalArg.docker.cleanup.attempt?.id;
1288
1324
  if (!attemptId) {
@@ -1303,7 +1339,11 @@ const finishDockerCleanup = async (
1303
1339
  cleanup.attempt = null;
1304
1340
  cleanup.error = null;
1305
1341
  cleanup.result = resultArg;
1306
- return finalizeJournalCompletion(currentArg);
1342
+ const finalized = finalizeJournalCompletion(currentArg);
1343
+ return cleanupOptionsArg.deferCompletion &&
1344
+ currentArg.completedAt === null
1345
+ ? { ...finalized, completedAt: null }
1346
+ : finalized;
1307
1347
  },
1308
1348
  )) as IReleaseJournalV2;
1309
1349
  };
@@ -1311,6 +1351,7 @@ const finishDockerCleanup = async (
1311
1351
  const runClaimedDockerCleanup = async (
1312
1352
  optionsArg: IReleasePublicationOptions,
1313
1353
  journalArg: IReleaseJournalV2,
1354
+ cleanupOptionsArg: IDockerCleanupOptions,
1314
1355
  ): Promise<IReleaseJournalV2> => {
1315
1356
  const client = requireTsdocker(optionsArg);
1316
1357
  const ownerId = journalArg.docker.cleanup.attempt?.id;
@@ -1334,12 +1375,13 @@ const runClaimedDockerCleanup = async (
1334
1375
  assertReleaseCleanupResult(valueArg, journalArg.docker.request),
1335
1376
  );
1336
1377
  }
1337
- return finishDockerCleanup(optionsArg, journalArg, result);
1378
+ return finishDockerCleanup(optionsArg, journalArg, result, cleanupOptionsArg);
1338
1379
  };
1339
1380
 
1340
1381
  const executeDockerCleanup = async (
1341
1382
  optionsArg: IReleasePublicationOptions,
1342
1383
  journalArg: IReleaseJournalV2,
1384
+ cleanupOptionsArg: IDockerCleanupOptions = {},
1343
1385
  ): Promise<IReleaseJournalV2> => {
1344
1386
  let journal = journalArg;
1345
1387
  if (journal.docker.cleanup.state === "verified") return journal;
@@ -1380,7 +1422,7 @@ const executeDockerCleanup = async (
1380
1422
  journal = (await claimTarget(optionsArg.store, journal, {
1381
1423
  kind: "docker-cleanup",
1382
1424
  })) as IReleaseJournalV2;
1383
- return runClaimedDockerCleanup(optionsArg, journal);
1425
+ return runClaimedDockerCleanup(optionsArg, journal, cleanupOptionsArg);
1384
1426
  };
1385
1427
 
1386
1428
  const cleanupIncompleteQualificationPreparation = async (
@@ -1865,26 +1907,43 @@ const createReleaseJournalWriter = (
1865
1907
  };
1866
1908
  };
1867
1909
 
1868
- const requireGiteaJournal = (
1910
+ /** The Gitea asset section of a schema 4 or schema 2 journal. */
1911
+ const requireGiteaAssets = (
1869
1912
  journalArg: TReleaseJournal,
1870
- ): IReleaseJournalV4 => {
1871
- if (journalArg.schemaVersion !== 4)
1913
+ ): IReleaseGiteaAssetsJournal => {
1914
+ const releaseAssets = getReleaseAssets(journalArg);
1915
+ if (releaseAssets?.target !== "giteaAssets")
1872
1916
  throw new Error("Release journal has no Gitea assets.");
1873
- return journalArg;
1917
+ return releaseAssets.section;
1874
1918
  };
1875
1919
 
1876
- const executeGiteaTarget = async (
1920
+ /** A recorded destination conflict is terminal; no run asks the destination again. */
1921
+ const recordedReleaseAssetConflict = (
1922
+ targetArg: TReleaseAssetTargetName,
1923
+ ): Error =>
1924
+ new Error(
1925
+ `${releaseAssetTargets[targetArg].label} publication has a recorded destination conflict.`,
1926
+ );
1927
+
1928
+ /**
1929
+ * Publishes one release or asset of a release asset target: inspect first, so
1930
+ * a target already present is verified; otherwise claim one attempt, perform
1931
+ * its single mutation and inspect again. A conflict is terminal, and a
1932
+ * verified target that disappears becomes one.
1933
+ */
1934
+ const executeReleaseAssetTarget = async (
1877
1935
  options: IReleasePublicationOptions,
1878
1936
  writer: IReleaseJournalWriter,
1879
- selector: TReleaseTargetSelector,
1937
+ selector: TReleaseAssetSelector,
1880
1938
  /** `verifyBytes` is false only for a target the journal already recorded as verified. */
1881
1939
  inspect: (verifyBytes: boolean) => Promise<boolean>,
1882
1940
  publish: () => Promise<void>,
1883
1941
  onVerified?: (target: IReleaseTargetStatus) => void,
1884
1942
  ): Promise<void> => {
1943
+ const { label, hostAssetNoun } = releaseAssetTargets[selector.target];
1885
1944
  const status = getTargetStatus(writer.current(), selector);
1886
1945
  if (status.state === "conflict")
1887
- throw new Error("Gitea publication has a recorded destination conflict.");
1946
+ throw recordedReleaseAssetConflict(selector.target);
1888
1947
  const mark = async (
1889
1948
  state: "verified" | "failed" | "conflict",
1890
1949
  error: TReleaseErrorCode | null,
@@ -1908,11 +1967,11 @@ const executeGiteaTarget = async (
1908
1967
  };
1909
1968
  let present: boolean;
1910
1969
  try {
1911
- // A recorded verification already proved these bytes; the complete-set
1912
- // verification before npm downloads every attachment once more.
1970
+ // A recorded verification already proved this target; the complete-set
1971
+ // verification before npm checks every asset once more.
1913
1972
  present = await inspect(status.state !== "verified");
1914
1973
  } catch (error) {
1915
- if (error instanceof GiteaAssetConflictError)
1974
+ if (error instanceof ReleaseAssetConflictError)
1916
1975
  await mark("conflict", "destination-conflict");
1917
1976
  throw error;
1918
1977
  }
@@ -1923,7 +1982,7 @@ const executeGiteaTarget = async (
1923
1982
  if (status.state === "verified") {
1924
1983
  await mark("conflict", "destination-conflict");
1925
1984
  throw new Error(
1926
- "A previously verified Gitea release or attachment is missing.",
1985
+ `A previously verified ${label} release or ${hostAssetNoun} is missing.`,
1927
1986
  );
1928
1987
  }
1929
1988
  if (status.state === "publishing") {
@@ -1941,7 +2000,7 @@ const executeGiteaTarget = async (
1941
2000
  claimTarget(options.store, journal, selector),
1942
2001
  );
1943
2002
  // One mutation per claimed attempt. Reconcile an accepted request even when
1944
- // its response was lost; never overwrite an attachment or recreate a tag.
2003
+ // its response was lost; never overwrite an asset or recreate a tag.
1945
2004
  let publicationError: unknown;
1946
2005
  try {
1947
2006
  await publish();
@@ -1952,8 +2011,8 @@ const executeGiteaTarget = async (
1952
2011
  present = await inspect(true);
1953
2012
  } catch (error) {
1954
2013
  await mark(
1955
- error instanceof GiteaAssetConflictError ? "conflict" : "failed",
1956
- error instanceof GiteaAssetConflictError
2014
+ error instanceof ReleaseAssetConflictError ? "conflict" : "failed",
2015
+ error instanceof ReleaseAssetConflictError
1957
2016
  ? "destination-conflict"
1958
2017
  : "verification-inconclusive",
1959
2018
  );
@@ -1964,8 +2023,10 @@ const executeGiteaTarget = async (
1964
2023
  return;
1965
2024
  }
1966
2025
  await mark(
1967
- publicationError instanceof GiteaAssetConflictError ? "conflict" : "failed",
1968
- publicationError instanceof GiteaAssetConflictError
2026
+ publicationError instanceof ReleaseAssetConflictError
2027
+ ? "conflict"
2028
+ : "failed",
2029
+ publicationError instanceof ReleaseAssetConflictError
1969
2030
  ? "destination-conflict"
1970
2031
  : publicationError
1971
2032
  ? "command-failed"
@@ -1973,7 +2034,7 @@ const executeGiteaTarget = async (
1973
2034
  );
1974
2035
  // Client errors carry no URL or credential; keep the stall/timeout cause visible.
1975
2036
  throw new Error(
1976
- `Gitea publication could not be verified; npm publication remains blocked. Inspect the retained journal before resuming.${publicationError instanceof Error ? ` Attempt: ${publicationError.message}` : ""}`,
2037
+ `${label} publication could not be verified; npm publication remains blocked. Inspect the retained journal before resuming.${publicationError instanceof Error ? ` Attempt: ${publicationError.message}` : ""}`,
1977
2038
  );
1978
2039
  };
1979
2040
 
@@ -2046,24 +2107,24 @@ const resolveGiteaAssetConcurrency = (valueArg: number | undefined): number => {
2046
2107
 
2047
2108
  const executeGiteaAssets = async (
2048
2109
  options: IReleasePublicationOptions,
2049
- journalArg: IReleaseJournalV4,
2110
+ journalArg: TReleaseJournal,
2050
2111
  client: NonNullable<IReleasePublicationOptions["giteaAssets"]>,
2051
- ): Promise<IReleaseJournalV4> => {
2112
+ ): Promise<TReleaseJournal> => {
2052
2113
  const concurrency = resolveGiteaAssetConcurrency(
2053
2114
  options.giteaAssetConcurrency,
2054
2115
  );
2055
2116
  const writer = createReleaseJournalWriter(journalArg);
2056
- let releaseId = journalArg.giteaAssets.release.id;
2117
+ let releaseId = requireGiteaAssets(journalArg).release.id;
2057
2118
  const observed: {
2058
2119
  /** The release as Gitea last reported it; never the state this run intended. */
2059
2120
  release: IGiteaRelease | null;
2060
2121
  createdHere: boolean;
2061
2122
  } = { release: null, createdHere: false };
2062
2123
  printReleasePhase("Gitea release");
2063
- await executeGiteaTarget(
2124
+ await executeReleaseAssetTarget(
2064
2125
  options,
2065
2126
  writer,
2066
- { kind: "gitea-release" },
2127
+ { kind: "asset-release", target: "giteaAssets" },
2067
2128
  async () => {
2068
2129
  const release = await client.inspectRelease();
2069
2130
  if (!release) return false;
@@ -2096,9 +2157,12 @@ const executeGiteaAssets = async (
2096
2157
  `Gitea release ${journalArg.release.tag} was created public instead of as a draft; no attachment was uploaded. A resume continues it as a published release, one attachment at a time in manifest order.`,
2097
2158
  );
2098
2159
  const releaseIsDraft = release.draft;
2099
- const journal = requireGiteaJournal(writer.current());
2100
- const expected = journal.giteaAssets.assets.map((entry) => entry.asset);
2101
- const directory = options.store.getReleaseDirectory(journal.release.version);
2160
+ const expected = requireGiteaAssets(writer.current()).assets.map(
2161
+ (entry) => entry.asset,
2162
+ );
2163
+ const directory = options.store.getReleaseDirectory(
2164
+ journalArg.release.version,
2165
+ );
2102
2166
  // Order and concurrency follow the state Gitea reported. A draft stays
2103
2167
  // invisible until every attachment verified, so no attachment is public
2104
2168
  // before the notices and sources beside it, and every upload first checks
@@ -2134,12 +2198,12 @@ const executeGiteaAssets = async (
2134
2198
  await runBoundedInOrder(
2135
2199
  order,
2136
2200
  effectiveConcurrency,
2137
- async (asset: IGiteaFrozenAsset) => {
2201
+ async (asset: IReleaseFrozenAsset) => {
2138
2202
  let startedAt: number | undefined;
2139
- await executeGiteaTarget(
2203
+ await executeReleaseAssetTarget(
2140
2204
  options,
2141
2205
  writer,
2142
- { kind: "gitea-asset", name: asset.name },
2206
+ { kind: "asset", target: "giteaAssets", name: asset.name },
2143
2207
  async (verifyBytes) => {
2144
2208
  const inspection = await downloadSlot(() =>
2145
2209
  client.inspectAssets(
@@ -2197,7 +2261,7 @@ const executeGiteaAssets = async (
2197
2261
  markUnclaimedTarget(
2198
2262
  options.store,
2199
2263
  current,
2200
- { kind: "gitea-release" },
2264
+ { kind: "asset-release", target: "giteaAssets" },
2201
2265
  ["verified"],
2202
2266
  "conflict",
2203
2267
  "destination-conflict",
@@ -2206,8 +2270,18 @@ const executeGiteaAssets = async (
2206
2270
  }
2207
2271
  throw error;
2208
2272
  }
2209
- // Only now may a journal whose last target was a Gitea attachment record
2210
- // its completion.
2273
+ await recordReleaseAssetsCompletion(options, writer);
2274
+ return writer.current();
2275
+ };
2276
+
2277
+ /**
2278
+ * Only once the complete asset set is published and proven may a journal
2279
+ * whose last target was a release asset record its completion.
2280
+ */
2281
+ const recordReleaseAssetsCompletion = async (
2282
+ options: IReleasePublicationOptions,
2283
+ writer: IReleaseJournalWriter,
2284
+ ): Promise<void> => {
2211
2285
  const verified = writer.current();
2212
2286
  if (
2213
2287
  verified.completedAt === null &&
@@ -2220,7 +2294,192 @@ const executeGiteaAssets = async (
2220
2294
  (latest) => finalizeJournalCompletion(latest),
2221
2295
  ),
2222
2296
  );
2223
- return requireGiteaJournal(writer.current());
2297
+ };
2298
+
2299
+ /** The foss.global asset section of a schema 4 or schema 2 journal. */
2300
+ const requireFossglobalAssets = (
2301
+ journalArg: TReleaseJournal,
2302
+ ): IReleaseFossglobalAssetsJournal => {
2303
+ const releaseAssets = getReleaseAssets(journalArg);
2304
+ if (releaseAssets?.target !== "fossglobalAssets")
2305
+ throw new Error("Release journal has no foss.global assets.");
2306
+ return releaseAssets.section;
2307
+ };
2308
+
2309
+ /** What the journal's fossglobalAssets section claims at the code host. */
2310
+ const fossglobalReleaseClaim = (
2311
+ journalArg: TReleaseJournal,
2312
+ ): IFossglobalReleaseClaim => {
2313
+ const section = requireFossglobalAssets(journalArg);
2314
+ return {
2315
+ tagObjectId: journalArg.release.tagOid,
2316
+ releaseId: section.release.releaseId,
2317
+ assets: section.assets.map(({ asset, assetId }) => ({
2318
+ asset,
2319
+ assetId,
2320
+ })),
2321
+ };
2322
+ };
2323
+
2324
+ /**
2325
+ * Proves the journal's foss.global destination before Git or any registry can
2326
+ * change: the Git destination, the frozen files, and through the release list
2327
+ * the credential's repository access and that nothing but this release's own
2328
+ * draft holds the tag. A recorded conflict stops it first, whatever the code
2329
+ * host shows now. Returns the client the publication then uses.
2330
+ */
2331
+ const preflightFossglobalAssets = async (
2332
+ options: IReleasePublicationOptions,
2333
+ journalArg: TReleaseJournal,
2334
+ ): Promise<IFossglobalAssetsClient> => {
2335
+ const { destination, tokenEnv, manifestPath, release, assets } =
2336
+ requireFossglobalAssets(journalArg);
2337
+ if ([release, ...assets].some((status) => status.state === "conflict"))
2338
+ throw recordedReleaseAssetConflict("fossglobalAssets");
2339
+ assertReleaseAssetsGitDestination(
2340
+ "fossglobalAssets",
2341
+ { ...destination, tokenEnv, manifestPath },
2342
+ options.pushUrl || "",
2343
+ );
2344
+ await validateReleaseAssets(
2345
+ "fossglobalAssets",
2346
+ options.store.getReleaseDirectory(journalArg.release.version),
2347
+ assets.map((entry) => entry.asset),
2348
+ );
2349
+ const client =
2350
+ options.fossglobalAssets ??
2351
+ new FossglobalAssetsClient({
2352
+ ...options.fossglobalAssetTransfer,
2353
+ destination,
2354
+ tag: journalArg.release.tag,
2355
+ token: readReleaseAssetCredential("fossglobalAssets", tokenEnv),
2356
+ });
2357
+ await client.preflight(fossglobalReleaseClaim(journalArg));
2358
+ return client;
2359
+ };
2360
+
2361
+ /**
2362
+ * Publishes the journal's foss.global release through the claim/inspect
2363
+ * executor: the draft for the pushed tag (created, or adopted when a crash
2364
+ * left it unrecorded), then each frozen asset, one at a time in manifest
2365
+ * order, then one check of the complete set, its publication and the
2366
+ * anonymous proof of every asset. Each id is recorded once, from the listing
2367
+ * that verifies its target, which must agree with this run's create or
2368
+ * upload answer. Nothing retries or waits: an inconclusive outcome stops the
2369
+ * run and the next resume inspects again.
2370
+ */
2371
+ const executeFossglobalAssets = async (
2372
+ options: IReleasePublicationOptions,
2373
+ journalArg: TReleaseJournal,
2374
+ client: IFossglobalAssetsClient,
2375
+ ): Promise<TReleaseJournal> => {
2376
+ const { label } = releaseAssetTargets.fossglobalAssets;
2377
+ const tag = journalArg.release.tag;
2378
+ const writer = createReleaseJournalWriter(journalArg);
2379
+ const claim = (): IFossglobalReleaseClaim =>
2380
+ fossglobalReleaseClaim(writer.current());
2381
+ const releaseSelector: TReleaseAssetSelector = {
2382
+ kind: "asset-release",
2383
+ target: "fossglobalAssets",
2384
+ };
2385
+ const observed: {
2386
+ /** The release as the code host last listed it. */
2387
+ release: IFossglobalRelease | null;
2388
+ /** The asset of the current step as the code host last listed it. */
2389
+ asset: IFossglobalPresentAsset | null;
2390
+ } = { release: null, asset: null };
2391
+ printReleasePhase(`${label} release`);
2392
+ await executeReleaseAssetTarget(
2393
+ options,
2394
+ writer,
2395
+ releaseSelector,
2396
+ async () => {
2397
+ observed.release = await client.inspectRelease(claim());
2398
+ return observed.release !== null;
2399
+ },
2400
+ async () => {
2401
+ printReleasePhase(`${label} release: creating the draft for ${tag}`);
2402
+ await client.createRelease(claim());
2403
+ },
2404
+ (target) => {
2405
+ if (observed.release && "releaseId" in target)
2406
+ target.releaseId = observed.release.releaseId;
2407
+ },
2408
+ );
2409
+ const directory = options.store.getReleaseDirectory(
2410
+ journalArg.release.version,
2411
+ );
2412
+ const expected = requireFossglobalAssets(journalArg).assets.map(
2413
+ (entry) => entry.asset,
2414
+ );
2415
+ // The draft stays invisible until every asset verified, so no asset is
2416
+ // public before the notices and sources beside it. The client never
2417
+ // uploads into a published release.
2418
+ printReleasePhase(
2419
+ `${label} assets: ${expected.length} assets, one at a time in manifest order`,
2420
+ );
2421
+ for (const asset of expected) {
2422
+ let startedAt: number | undefined;
2423
+ await executeReleaseAssetTarget(
2424
+ options,
2425
+ writer,
2426
+ { kind: "asset", target: "fossglobalAssets", name: asset.name },
2427
+ async () => {
2428
+ const inspection = await client.inspectAssets(claim());
2429
+ observed.asset =
2430
+ inspection.present.find((entry) => entry.asset.name === asset.name) ??
2431
+ null;
2432
+ return observed.asset !== null;
2433
+ },
2434
+ async () => {
2435
+ startedAt = Date.now();
2436
+ printReleasePhase(
2437
+ `${label} asset ${asset.name}: uploading ${asset.size} bytes`,
2438
+ );
2439
+ await client.uploadAsset(claim(), asset, directory);
2440
+ },
2441
+ (target) => {
2442
+ if (observed.asset && "assetId" in target)
2443
+ target.assetId = observed.asset.assetId;
2444
+ },
2445
+ );
2446
+ if (startedAt !== undefined)
2447
+ printReleasePhase(
2448
+ `${label} asset ${asset.name}: uploaded and stored with its frozen SHA-256 in ${formatReleaseDuration(Date.now() - startedAt)}`,
2449
+ );
2450
+ }
2451
+ // One check of the complete set immediately before publishing it and
2452
+ // before npm, then the publication and the anonymous proof. Publishing is
2453
+ // observable, so it needs no journal attempt: a resume after a crash or an
2454
+ // inconclusive answer finds the release published, verifies and proves it.
2455
+ printReleasePhase(`${label} assets: verifying the complete asset set`);
2456
+ let published: IFossglobalRelease;
2457
+ try {
2458
+ published = await client.verifyComplete(claim());
2459
+ printReleasePhase(
2460
+ published.draft
2461
+ ? `${label} release: publishing the verified draft, then proving each asset anonymously`
2462
+ : `${label} release: proving each asset of the published release anonymously`,
2463
+ );
2464
+ await client.publishRelease(claim());
2465
+ } catch (error) {
2466
+ if (error instanceof ReleaseAssetConflictError) {
2467
+ await writer.write((current) =>
2468
+ markUnclaimedTarget(
2469
+ options.store,
2470
+ current,
2471
+ releaseSelector,
2472
+ ["verified"],
2473
+ "conflict",
2474
+ "destination-conflict",
2475
+ ),
2476
+ );
2477
+ }
2478
+ throw error;
2479
+ }
2480
+ printReleasePhase(`${label} release ${tag} is published: ${published.htmlUrl}`);
2481
+ await recordReleaseAssetsCompletion(options, writer);
2482
+ return writer.current();
2224
2483
  };
2225
2484
 
2226
2485
  // ---------------------------------------------------------------------------
@@ -2641,6 +2900,7 @@ export const executeReleasePublication = async (
2641
2900
  optionsArg: IReleasePublicationOptions,
2642
2901
  ): Promise<TReleaseJournal> => {
2643
2902
  let journal = optionsArg.journal;
2903
+ const releaseAssetTarget = getReleaseAssets(journal)?.target;
2644
2904
  // Validate the whole stored set before Git or any registry can change.
2645
2905
  for (const artifact of getReleaseArtifacts(journal)) {
2646
2906
  await verifyStoredNpmArtifact(
@@ -2654,9 +2914,12 @@ export const executeReleasePublication = async (
2654
2914
  crate,
2655
2915
  );
2656
2916
  }
2917
+ // The asset destination is proven before Docker qualification and before
2918
+ // Git or any registry can change.
2657
2919
  let giteaClient = optionsArg.giteaAssets;
2658
- if (journal.schemaVersion === 4) {
2659
- const { destination, tokenEnv, manifestPath, assets } = journal.giteaAssets;
2920
+ if (releaseAssetTarget === "giteaAssets") {
2921
+ const { destination, tokenEnv, manifestPath, assets } =
2922
+ requireGiteaAssets(journal);
2660
2923
  assertGiteaAssetsGitDestination(
2661
2924
  { ...destination, tokenEnv, manifestPath },
2662
2925
  optionsArg.pushUrl || "",
@@ -2666,21 +2929,20 @@ export const executeReleasePublication = async (
2666
2929
  assets.map((entry) => entry.asset),
2667
2930
  );
2668
2931
  if (!giteaClient) {
2669
- const token = process.env[tokenEnv];
2670
- if (!token)
2671
- throw new Error(
2672
- `Gitea assets require the configured credential in ${tokenEnv}.`,
2673
- );
2674
2932
  giteaClient = new GiteaAssetsClient({
2675
2933
  ...optionsArg.giteaAssetTransfer,
2676
2934
  destination,
2677
- token,
2935
+ token: readReleaseAssetCredential("giteaAssets", tokenEnv),
2678
2936
  tag: journal.release.tag,
2679
2937
  commit: journal.release.mainOid,
2680
2938
  });
2681
2939
  }
2682
2940
  await giteaClient.preflight();
2683
2941
  }
2942
+ const fossglobalClient =
2943
+ releaseAssetTarget === "fossglobalAssets"
2944
+ ? await preflightFossglobalAssets(optionsArg, journal)
2945
+ : undefined;
2684
2946
  if (journal.schemaVersion === 2) {
2685
2947
  printReleasePhase("Docker qualification");
2686
2948
  journal = await executeDockerQualification(optionsArg, journal);
@@ -2694,13 +2956,24 @@ export const executeReleasePublication = async (
2694
2956
  journal.docker.cleanup.state === "publishing" ||
2695
2957
  journal.docker.cleanup.state === "failed"
2696
2958
  ) {
2697
- journal = await executeDockerCleanup(optionsArg, journal);
2959
+ // An interrupted final cleanup runs before Git. With release assets it
2960
+ // never records the completion: only the asset step below does, once
2961
+ // the complete asset set verified again in this run.
2962
+ journal = await executeDockerCleanup(optionsArg, journal, {
2963
+ deferCompletion: releaseAssetTarget !== undefined,
2964
+ });
2698
2965
  }
2699
2966
  }
2700
2967
  printReleasePhase("Git target");
2701
2968
  journal = await executeGitTarget(optionsArg, journal);
2702
- if (journal.schemaVersion === 4)
2969
+ if (releaseAssetTarget === "giteaAssets")
2703
2970
  journal = await executeGiteaAssets(optionsArg, journal, giteaClient!);
2971
+ if (fossglobalClient)
2972
+ journal = await executeFossglobalAssets(
2973
+ optionsArg,
2974
+ journal,
2975
+ fossglobalClient,
2976
+ );
2704
2977
  const expectedRemoteMainOid =
2705
2978
  journal.git.state === "verified"
2706
2979
  ? journal.release.mainOid
@@ -2735,12 +3008,21 @@ export const executeReleasePublication = async (
2735
3008
  );
2736
3009
  }
2737
3010
  }
2738
- if (getReleaseCargo(journal)) {
2739
- journal = await executeCargoPublication(optionsArg, journal);
2740
- }
2741
3011
  const npmAwaitingAvailability = journal.npm.registries.some(
2742
3012
  (registryArg) => registryArg.state === "accepted",
2743
3013
  );
3014
+ if (getReleaseCargo(journal)) {
3015
+ if (npmAwaitingAvailability) {
3016
+ // Crates follow verified npm publication, as Docker destinations do: a
3017
+ // release whose npm package never becomes readable must not have pushed
3018
+ // immutable crate versions first. Resume continues from here.
3019
+ console.log(
3020
+ `Cargo publication waits for the accepted npm target to become readable. Nothing is republished: run \`gitzone release resume ${journal.release.version} -y\` later.`,
3021
+ );
3022
+ } else {
3023
+ journal = await executeCargoPublication(optionsArg, journal);
3024
+ }
3025
+ }
2744
3026
  if (
2745
3027
  journal.schemaVersion === 2 &&
2746
3028
  journal.docker.cleanup.state !== "verified" &&