@git.zone/cli 8.10.1 → 9.0.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 (69) hide show
  1. package/assets/templates/{asset_deno_binary_installer → asset_binary_installer}/install.sh +2 -2
  2. package/assets/templates/{asset_deno_binary_postinstall → asset_binary_postinstall}/bin/wrapper.js +2 -2
  3. package/assets/templates/{asset_deno_binary_postinstall → asset_binary_postinstall}/scripts/install-binary.js +2 -2
  4. package/assets/templates/asset_binary_release_gitea/.gitea/workflows/release.yml +180 -0
  5. package/assets/templates/asset_tspack_release_gitea/.gitea/workflows/release.yml +7 -4
  6. package/assets/templates/asset_tspack_release_gitea/scripts/gitzone-gitea-tag.d.mts +9 -3
  7. package/assets/templates/asset_tspack_release_gitea/scripts/gitzone-gitea-tag.mjs +50 -6
  8. package/assets/templates/asset_tspack_release_gitea/scripts/gitzone-release-api.mjs +7 -6
  9. package/dist_ts/00_commitinfo_data.js +2 -2
  10. package/dist_ts/helpers.managedassets.d.ts +44 -0
  11. package/dist_ts/helpers.managedassets.js +166 -0
  12. package/dist_ts/helpers.ownerscopes.d.ts +4 -16
  13. package/dist_ts/helpers.ownerscopes.js +5 -16
  14. package/dist_ts/helpers.packagefiles.d.ts +2 -1
  15. package/dist_ts/helpers.packagefiles.js +7 -4
  16. package/dist_ts/helpers.sealedrelease.js +3 -3
  17. package/dist_ts/helpers.tssea.d.ts +11 -0
  18. package/dist_ts/helpers.tssea.js +81 -0
  19. package/dist_ts/helpers.workflow.d.ts +2 -3
  20. package/dist_ts/helpers.workflow.js +9 -19
  21. package/dist_ts/index.d.ts +1 -1
  22. package/dist_ts/index.js +2 -2
  23. package/dist_ts/mod_commit/mod.helpers.d.ts +8 -21
  24. package/dist_ts/mod_commit/mod.helpers.js +32 -83
  25. package/dist_ts/mod_commit/mod.ui.js +1 -5
  26. package/dist_ts/mod_config/index.js +41 -33
  27. package/dist_ts/mod_format/formatters/assets.formatter.js +42 -92
  28. package/dist_ts/mod_format/formatters/packagejson.formatter.js +3 -3
  29. package/dist_ts/mod_format/index.js +30 -11
  30. package/dist_ts/mod_format/interfaces.format.js +1 -2
  31. package/dist_ts/mod_release/classes.releasejournal.d.ts +63 -2
  32. package/dist_ts/mod_release/classes.releasejournal.js +247 -48
  33. package/dist_ts/mod_release/helpers.giteaassets.js +18 -9
  34. package/dist_ts/mod_release/helpers.releasepreparation.d.ts +6 -14
  35. package/dist_ts/mod_release/helpers.releasepreparation.js +27 -53
  36. package/dist_ts/mod_release/index.js +108 -13
  37. package/dist_ts/mod_services/classes.serviceconfiguration.d.ts +2 -2
  38. package/dist_ts/mod_services/classes.serviceoptions.d.ts +2 -2
  39. package/dist_ts/plugins.d.ts +3 -1
  40. package/dist_ts/plugins.js +4 -2
  41. package/package.json +3 -2
  42. package/readme.md +153 -74
  43. package/ts/00_commitinfo_data.ts +1 -1
  44. package/ts/helpers.managedassets.ts +215 -0
  45. package/ts/helpers.ownerscopes.ts +4 -15
  46. package/ts/helpers.packagefiles.ts +6 -3
  47. package/ts/helpers.sealedrelease.ts +2 -2
  48. package/ts/helpers.tssea.ts +102 -0
  49. package/ts/helpers.workflow.ts +12 -28
  50. package/ts/index.ts +1 -1
  51. package/ts/mod_commit/mod.helpers.ts +33 -94
  52. package/ts/mod_commit/mod.ui.ts +0 -4
  53. package/ts/mod_config/index.ts +47 -35
  54. package/ts/mod_format/formatters/assets.formatter.ts +47 -108
  55. package/ts/mod_format/formatters/packagejson.formatter.ts +2 -2
  56. package/ts/mod_format/index.ts +36 -10
  57. package/ts/mod_format/interfaces.format.ts +0 -1
  58. package/ts/mod_release/classes.releasejournal.ts +323 -52
  59. package/ts/mod_release/helpers.giteaassets.ts +19 -10
  60. package/ts/mod_release/helpers.releasepreparation.ts +36 -69
  61. package/ts/mod_release/index.ts +138 -18
  62. package/ts/mod_services/classes.serviceconfiguration.ts +2 -2
  63. package/ts/mod_services/classes.serviceoptions.ts +2 -2
  64. package/ts/plugins.ts +4 -0
  65. package/assets/templates/asset_deno_binary_release_gitea/.gitea/workflows/release.yml +0 -154
  66. package/assets/templates/multienv/deno.json +0 -8
  67. package/dist_ts/mod_format/formatters/deno.formatter.d.ts +0 -18
  68. package/dist_ts/mod_format/formatters/deno.formatter.js +0 -175
  69. package/ts/mod_format/formatters/deno.formatter.ts +0 -219
@@ -25,7 +25,6 @@ import { TemplatesFormatter } from "./formatters/templates.formatter.js";
25
25
  import { AssetsFormatter } from "./formatters/assets.formatter.js";
26
26
  import { GitignoreFormatter } from "./formatters/gitignore.formatter.js";
27
27
  import { TsconfigFormatter } from "./formatters/tsconfig.formatter.js";
28
- import { DenoFormatter } from "./formatters/deno.formatter.js";
29
28
  import { PrettierFormatter } from "./formatters/prettier.formatter.js";
30
29
  import { ReadmeFormatter } from "./formatters/readme.formatter.js";
31
30
  import { CopyFormatter } from "./formatters/copy.formatter.js";
@@ -71,7 +70,6 @@ const formatterMap: Record<
71
70
  assets: AssetsFormatter,
72
71
  gitignore: GitignoreFormatter,
73
72
  tsconfig: TsconfigFormatter,
74
- deno: DenoFormatter,
75
73
  prettier: PrettierFormatter,
76
74
  readme: ReadmeFormatter,
77
75
  copy: CopyFormatter,
@@ -83,9 +81,22 @@ const formattersNotRequiringProjectType = [
83
81
  "prettier",
84
82
  "cleanup",
85
83
  "packagejson",
86
- "deno",
87
84
  ];
88
85
 
86
+ /**
87
+ * Refuses module names no formatter carries, so a misspelled or removed module
88
+ * never selects or skips nothing in silence.
89
+ */
90
+ const assertKnownFormatModules = (namesArg: string[], sourceArg: string): void => {
91
+ const validNames = Object.keys(formatterMap);
92
+ const unknownNames = namesArg.filter((nameArg) => !validNames.includes(nameArg));
93
+ if (unknownNames.length > 0) {
94
+ throw new Error(
95
+ `Unknown format module ${unknownNames.map((nameArg) => `"${nameArg}"`).join(", ")} in ${sourceArg}. Valid modules: ${validNames.join(", ")}.`,
96
+ );
97
+ }
98
+ };
99
+
89
100
  const getFormatConfig = async () => {
90
101
  const rawFormatConfig = await getCliConfigValue<Record<string, any>>(
91
102
  "format",
@@ -148,13 +159,14 @@ const createActiveFormatters = async (options: {
148
159
  ([, FormatterClass]) => new FormatterClass(context, project),
149
160
  );
150
161
 
151
- const onlyModules = options.only?.length
152
- ? options.only
153
- : formatConfig.modules.only;
154
- const skipModules = [
155
- ...formatConfig.modules.skip,
156
- ...(options.skip || []),
157
- ];
162
+ const configOnly = normalizeModuleList(formatConfig.modules.only);
163
+ const configSkip = normalizeModuleList(formatConfig.modules.skip);
164
+ assertKnownFormatModules(options.only || [], "--only");
165
+ assertKnownFormatModules(options.skip || [], "--skip");
166
+ assertKnownFormatModules(configOnly, "@git.zone/cli.format.modules.only");
167
+ assertKnownFormatModules(configSkip, "@git.zone/cli.format.modules.skip");
168
+ const onlyModules = options.only?.length ? options.only : configOnly;
169
+ const skipModules = [...configSkip, ...(options.skip || [])];
158
170
 
159
171
  const activeFormatters = formatters.filter((formatter) => {
160
172
  if (onlyModules.length > 0) {
@@ -555,6 +567,20 @@ export let run = async (
555
567
  return;
556
568
  }
557
569
 
570
+ // A plan with errors is not applied in part: fix the errors, then write.
571
+ const writeStatus = getPlanStatus(plan);
572
+ if (writeStatus.hasErrors) {
573
+ for (const warning of plan.warnings.filter((warningArg) => warningArg.level === "error")) {
574
+ logger.log("error", `[${warning.module}] ${warning.message}`);
575
+ }
576
+ logger.log(
577
+ "error",
578
+ `Format write refused: the plan has ${writeStatus.errorCount} error warning(s). Nothing was written.`,
579
+ );
580
+ process.exitCode = 1;
581
+ return;
582
+ }
583
+
558
584
  // Interactive confirmation
559
585
  if (interactive && !autoApprove) {
560
586
  const proceed = await ask({
@@ -46,7 +46,6 @@ export function getModuleIcon(module: string): string {
46
46
  packagejson: '📦',
47
47
  license: '📝',
48
48
  tsconfig: '🔧',
49
- deno: '🦕',
50
49
  cleanup: '🚮',
51
50
  gitignore: '🔒',
52
51
  prettier: '✨',
@@ -54,6 +54,54 @@ export const releaseArtifactFileName = "package.tgz" as const;
54
54
  export const releaseJournalFileName = "journal.json" as const;
55
55
  export const releaseIntentKind = "gitzone-release-intent" as const;
56
56
 
57
+ /** npm tarballs and frozen Gitea assets: the bytes retention may remove. */
58
+ export const isReleasePayloadFileName = (nameArg: string): boolean =>
59
+ nameArg === releaseArtifactFileName ||
60
+ /^package\.[0-9a-f]{64}\.tgz$/.test(nameArg) ||
61
+ /^asset\.[0-9a-f]{64}\.bin$/.test(nameArg);
62
+
63
+ export type TReleaseRecordPruneAction = "kept" | "pruned" | "blocked";
64
+ export type TReleaseRecordPruneReason =
65
+ | "newest-completed"
66
+ | "current-release"
67
+ | "incomplete"
68
+ | "older-completed"
69
+ | "payload-absent"
70
+ | "intent-present"
71
+ | "record-in-use"
72
+ | "invalid-journal";
73
+
74
+ export interface IReleaseRecordPruneEntry {
75
+ version: string;
76
+ state: "completed" | "incomplete" | "invalid";
77
+ createdAt: string | null;
78
+ completedAt: string | null;
79
+ /** Every regular file of the record directory. */
80
+ bytes: number;
81
+ /** The npm tarballs and Gitea assets among them. */
82
+ payloadBytes: number;
83
+ payloadFiles: number;
84
+ action: TReleaseRecordPruneAction;
85
+ reason: TReleaseRecordPruneReason;
86
+ detail?: string;
87
+ }
88
+
89
+ export interface IReleaseRecordPruneReport {
90
+ dryRun: boolean;
91
+ keep: number;
92
+ root: string;
93
+ records: IReleaseRecordPruneEntry[];
94
+ totals: {
95
+ records: number;
96
+ kept: number;
97
+ pruned: number;
98
+ blocked: number;
99
+ bytes: number;
100
+ wouldFreeBytes: number;
101
+ freedBytes: number;
102
+ };
103
+ }
104
+
57
105
  /**
58
106
  * `accepted` records a destination that took the upload without rejecting it
59
107
  * while its read-back is still missing. It is neither a success nor a failure:
@@ -2141,11 +2189,7 @@ export class ReleaseJournalStore {
2141
2189
  versionArg: string,
2142
2190
  fileArg: string = releaseArtifactFileName,
2143
2191
  ): string {
2144
- if (
2145
- fileArg !== releaseArtifactFileName &&
2146
- !/^package\.[0-9a-f]{64}\.tgz$/.test(fileArg) &&
2147
- !/^asset\.[0-9a-f]{64}\.bin$/.test(fileArg)
2148
- ) {
2192
+ if (!isReleasePayloadFileName(fileArg)) {
2149
2193
  throw new Error("Invalid release artifact filename.");
2150
2194
  }
2151
2195
  return plugins.path.join(this.getReleaseDirectory(versionArg), fileArg);
@@ -2314,66 +2358,293 @@ export class ReleaseJournalStore {
2314
2358
 
2315
2359
  /**
2316
2360
  * Only a completed run trims completed records. The current record, intents,
2317
- * and records pinned by another publisher/resume remain available. Invalid
2318
- * journals stop retention before deletion rather than guessing their state.
2361
+ * and records pinned by another publisher/resume keep their payloads.
2362
+ * Invalid journals stop retention before deletion rather than guessing
2363
+ * their state.
2319
2364
  */
2320
2365
  public async pruneCompleted(
2321
2366
  keepArg: number,
2322
2367
  currentVersionArg: string,
2323
2368
  ): Promise<string[]> {
2324
2369
  const keep = resolveReleaseRecordRetention(keepArg);
2325
- const currentVersion = normalizeReleaseVersion(currentVersionArg);
2370
+ if ((await this.read(currentVersionArg)).completedAt === null) return [];
2371
+ const report = await this.pruneRecords({
2372
+ keep,
2373
+ apply: true,
2374
+ currentVersion: currentVersionArg,
2375
+ });
2376
+ return report.records
2377
+ .filter((entry) => entry.action === "pruned" && entry.payloadFiles > 0)
2378
+ .map((entry) => entry.version);
2379
+ }
2380
+
2381
+ /**
2382
+ * Retention for every caller: the newest `keep` completed records and every
2383
+ * incomplete record keep their payloads; older completed records lose their
2384
+ * npm tarballs and Gitea assets. Journals and all other files stay. A dry run
2385
+ * only reports; `apply` deletes under the same locks a release takes.
2386
+ */
2387
+ public async pruneRecords(optionsArg: {
2388
+ keep: number;
2389
+ apply: boolean;
2390
+ currentVersion?: string;
2391
+ }): Promise<IReleaseRecordPruneReport> {
2392
+ const keep = resolveReleaseRecordRetention(optionsArg.keep);
2393
+ const currentVersion =
2394
+ optionsArg.currentVersion === undefined
2395
+ ? undefined
2396
+ : normalizeReleaseVersion(optionsArg.currentVersion);
2397
+ if (!optionsArg.apply)
2398
+ return this.summarizePrune(
2399
+ keep,
2400
+ true,
2401
+ await this.planPrune(keep, currentVersion),
2402
+ );
2326
2403
  const retentionLock = new InterProcessLock({
2327
2404
  lockPath: plugins.path.join(this.rootPath, "retention.lock"),
2328
2405
  description: "Release record retention",
2329
2406
  });
2330
2407
  return retentionLock.runExclusive(async () => {
2331
- if ((await this.read(currentVersion)).completedAt === null) return [];
2332
- const completed = (await this.list())
2333
- .filter((journal) => journal.completedAt !== null)
2334
- .sort(
2335
- (left, right) =>
2336
- right.createdAt.localeCompare(left.createdAt) ||
2337
- compareSupportedReleaseVersions(
2338
- right.release.version,
2339
- left.release.version,
2340
- ),
2408
+ const records = await this.planPrune(keep, currentVersion);
2409
+ const invalid = records.filter((entry) => entry.state === "invalid");
2410
+ if (invalid.length > 0)
2411
+ throw new Error(
2412
+ `Release record retention stopped before deletion: ${invalid.map((entry) => `v${entry.version} (${entry.detail})`).join("; ")}.`,
2341
2413
  );
2342
- const pruned: string[] = [];
2343
- for (const journal of completed.slice(keep)) {
2344
- const version = journal.release.version;
2345
- if (version === currentVersion) continue;
2346
- const recordLock = this.getRecordLock(version);
2347
- if (await recordLock.readHolder()) continue;
2348
- await recordLock.runExclusive(async () => {
2349
- const directory = this.getReleaseDirectory(version);
2350
- const journalLock = new InterProcessLock({
2351
- lockPath: `${directory}.lock`,
2352
- description: `Release journal v${version}`,
2353
- });
2354
- await journalLock.runExclusive(async () => {
2355
- const current = await this.read(version);
2356
- if (current.completedAt === null) return;
2357
- // Even a malformed intent protects the record; do not interpret it.
2358
- try {
2359
- await plugins.fs.lstat(this.getIntentPath(version));
2360
- return;
2361
- } catch (error) {
2362
- if ((error as NodeJS.ErrnoException).code !== "ENOENT")
2363
- throw error;
2364
- }
2365
- const stat = await plugins.fs.lstat(directory);
2366
- if (!stat.isDirectory() || stat.isSymbolicLink())
2367
- throw new Error(
2368
- `Release record v${version} is not a regular directory.`,
2369
- );
2370
- await plugins.fs.rm(directory, { recursive: true, force: false });
2371
- await syncDirectory(this.rootPath);
2372
- pruned.push(version);
2373
- });
2374
- });
2414
+ for (const entry of records) {
2415
+ if (entry.action !== "pruned" || entry.payloadFiles === 0) continue;
2416
+ const blocked = await this.prunePayload(entry.version);
2417
+ if (blocked) {
2418
+ entry.action = blocked === "incomplete" ? "kept" : "blocked";
2419
+ entry.reason = blocked;
2420
+ }
2375
2421
  }
2376
- return pruned;
2422
+ return this.summarizePrune(keep, false, records);
2423
+ });
2424
+ }
2425
+
2426
+ /**
2427
+ * Paths that show a release of this repository at work: journal, record,
2428
+ * creation and recovery-preparation locks, the detached-run lock, and
2429
+ * temporary preparation directories. Stale entries need the same manual
2430
+ * owner check as every release lock.
2431
+ */
2432
+ public async findActiveReleaseState(): Promise<string[]> {
2433
+ let names: string[];
2434
+ try {
2435
+ names = await plugins.fs.readdir(this.rootPath);
2436
+ } catch (error) {
2437
+ if ((error as NodeJS.ErrnoException).code === "ENOENT") return [];
2438
+ throw new Error("Release journal directory could not be listed.", {
2439
+ cause: error,
2440
+ });
2441
+ }
2442
+ return names
2443
+ .filter((name) =>
2444
+ /^(?:v.+\.(?:record\.|create\.|prepare\.)?lock|detached\.lock|\.v.+\.tmp-.+)$/.test(
2445
+ name,
2446
+ ),
2447
+ )
2448
+ .sort()
2449
+ .map((name) => plugins.path.join(this.rootPath, name));
2450
+ }
2451
+
2452
+ /** True when a journal's npm tarballs or Gitea assets are not stored. */
2453
+ public async isPayloadMissing(journalArg: TReleaseJournal): Promise<boolean> {
2454
+ const files = [
2455
+ ...getReleaseArtifacts(journalArg).map((artifact) => artifact.file),
2456
+ ...(journalArg.schemaVersion === 4
2457
+ ? journalArg.giteaAssets.assets.map((entry) => entry.asset.fileName)
2458
+ : []),
2459
+ ];
2460
+ for (const file of files) {
2461
+ try {
2462
+ await plugins.fs.lstat(
2463
+ this.getArtifactPath(journalArg.release.version, file),
2464
+ );
2465
+ } catch (error) {
2466
+ if ((error as NodeJS.ErrnoException).code === "ENOENT") return true;
2467
+ throw error;
2468
+ }
2469
+ }
2470
+ return false;
2471
+ }
2472
+
2473
+ private async planPrune(
2474
+ keepArg: number,
2475
+ currentVersionArg: string | undefined,
2476
+ ): Promise<IReleaseRecordPruneEntry[]> {
2477
+ let directoryEntries: Array<{ name: string; isDirectory: () => boolean }>;
2478
+ try {
2479
+ directoryEntries = await plugins.fs.readdir(this.rootPath, {
2480
+ withFileTypes: true,
2481
+ });
2482
+ } catch (error) {
2483
+ if ((error as NodeJS.ErrnoException).code === "ENOENT") return [];
2484
+ throw new Error("Release journal directory could not be listed.", {
2485
+ cause: error,
2486
+ });
2487
+ }
2488
+ const records: Array<{
2489
+ entry: IReleaseRecordPruneEntry;
2490
+ journal: TReleaseJournal | null;
2491
+ }> = [];
2492
+ for (const directoryEntry of directoryEntries) {
2493
+ if (
2494
+ !directoryEntry.isDirectory() ||
2495
+ !directoryEntry.name.startsWith("v") ||
2496
+ !isSupportedReleaseVersion(directoryEntry.name.slice(1))
2497
+ )
2498
+ continue;
2499
+ const version = directoryEntry.name.slice(1);
2500
+ const usage = await this.measureRecord(version);
2501
+ let journal: TReleaseJournal | null = null;
2502
+ let detail: string | undefined;
2503
+ try {
2504
+ journal = await this.read(version);
2505
+ } catch (error) {
2506
+ detail = error instanceof Error ? error.message : String(error);
2507
+ }
2508
+ records.push({
2509
+ journal,
2510
+ entry: {
2511
+ version,
2512
+ state: !journal
2513
+ ? "invalid"
2514
+ : journal.completedAt === null
2515
+ ? "incomplete"
2516
+ : "completed",
2517
+ createdAt: journal?.createdAt ?? null,
2518
+ completedAt: journal?.completedAt ?? null,
2519
+ ...usage,
2520
+ ...(journal
2521
+ ? journal.completedAt === null
2522
+ ? { action: "kept", reason: "incomplete" }
2523
+ : { action: "pruned", reason: "older-completed" }
2524
+ : { action: "blocked", reason: "invalid-journal", detail }),
2525
+ },
2526
+ });
2527
+ }
2528
+ records.sort(
2529
+ (left, right) =>
2530
+ (right.entry.createdAt ?? "").localeCompare(
2531
+ left.entry.createdAt ?? "",
2532
+ ) ||
2533
+ compareSupportedReleaseVersions(
2534
+ right.entry.version,
2535
+ left.entry.version,
2536
+ ),
2537
+ );
2538
+ const completed = records
2539
+ .filter((record) => record.entry.state === "completed")
2540
+ .map((record) => record.entry);
2541
+ for (const [index, entry] of completed.entries()) {
2542
+ if (entry.version === currentVersionArg) {
2543
+ entry.action = "kept";
2544
+ entry.reason = "current-release";
2545
+ } else if (index < keepArg) {
2546
+ entry.action = "kept";
2547
+ entry.reason = "newest-completed";
2548
+ } else if (await this.hasIntent(entry.version)) {
2549
+ entry.action = "blocked";
2550
+ entry.reason = "intent-present";
2551
+ } else if (await this.getRecordLock(entry.version).readHolder()) {
2552
+ entry.action = "blocked";
2553
+ entry.reason = "record-in-use";
2554
+ } else if (entry.payloadFiles === 0) {
2555
+ entry.reason = "payload-absent";
2556
+ }
2557
+ }
2558
+ return records.map((record) => record.entry);
2559
+ }
2560
+
2561
+ private summarizePrune(
2562
+ keepArg: number,
2563
+ dryRunArg: boolean,
2564
+ recordsArg: IReleaseRecordPruneEntry[],
2565
+ ): IReleaseRecordPruneReport {
2566
+ const count = (actionArg: TReleaseRecordPruneAction) =>
2567
+ recordsArg.filter((entry) => entry.action === actionArg).length;
2568
+ const wouldFreeBytes = recordsArg
2569
+ .filter((entry) => entry.action === "pruned")
2570
+ .reduce((sum, entry) => sum + entry.payloadBytes, 0);
2571
+ return {
2572
+ dryRun: dryRunArg,
2573
+ keep: keepArg,
2574
+ root: this.rootPath,
2575
+ records: recordsArg,
2576
+ totals: {
2577
+ records: recordsArg.length,
2578
+ kept: count("kept"),
2579
+ pruned: count("pruned"),
2580
+ blocked: count("blocked"),
2581
+ bytes: recordsArg.reduce((sum, entry) => sum + entry.bytes, 0),
2582
+ wouldFreeBytes,
2583
+ freedBytes: dryRunArg ? 0 : wouldFreeBytes,
2584
+ },
2585
+ };
2586
+ }
2587
+
2588
+ private async measureRecord(
2589
+ versionArg: string,
2590
+ ): Promise<{ bytes: number; payloadBytes: number; payloadFiles: number }> {
2591
+ const directory = this.getReleaseDirectory(versionArg);
2592
+ const usage = { bytes: 0, payloadBytes: 0, payloadFiles: 0 };
2593
+ for (const name of await plugins.fs.readdir(directory)) {
2594
+ const stat = await plugins.fs.lstat(plugins.path.join(directory, name));
2595
+ if (!stat.isFile()) continue;
2596
+ usage.bytes += stat.size;
2597
+ if (!isReleasePayloadFileName(name)) continue;
2598
+ usage.payloadBytes += stat.size;
2599
+ usage.payloadFiles++;
2600
+ }
2601
+ return usage;
2602
+ }
2603
+
2604
+ /** Even a malformed intent protects the record; it is not interpreted. */
2605
+ private async hasIntent(versionArg: string): Promise<boolean> {
2606
+ try {
2607
+ await plugins.fs.lstat(this.getIntentPath(versionArg));
2608
+ return true;
2609
+ } catch (error) {
2610
+ if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
2611
+ return false;
2612
+ }
2613
+ }
2614
+
2615
+ /** Deletes one record's payload, or names what still protects it. */
2616
+ private async prunePayload(
2617
+ versionArg: string,
2618
+ ): Promise<TReleaseRecordPruneReason | null> {
2619
+ const recordLock = this.getRecordLock(versionArg);
2620
+ if (await recordLock.readHolder()) return "record-in-use";
2621
+ return recordLock.runExclusive(async () => {
2622
+ const directory = this.getReleaseDirectory(versionArg);
2623
+ const journalLock = new InterProcessLock({
2624
+ lockPath: `${directory}.lock`,
2625
+ description: `Release journal v${versionArg}`,
2626
+ });
2627
+ return journalLock.runExclusive(async () => {
2628
+ if ((await this.read(versionArg)).completedAt === null)
2629
+ return "incomplete";
2630
+ if (await this.hasIntent(versionArg)) return "intent-present";
2631
+ const stat = await plugins.fs.lstat(directory);
2632
+ if (!stat.isDirectory() || stat.isSymbolicLink())
2633
+ throw new Error(
2634
+ `Release record v${versionArg} is not a regular directory.`,
2635
+ );
2636
+ for (const entry of await plugins.fs.readdir(directory, {
2637
+ withFileTypes: true,
2638
+ })) {
2639
+ if (!entry.isFile() || !isReleasePayloadFileName(entry.name))
2640
+ continue;
2641
+ await plugins.fs.rm(plugins.path.join(directory, entry.name), {
2642
+ force: false,
2643
+ });
2644
+ }
2645
+ await syncDirectory(directory);
2646
+ return null;
2647
+ });
2377
2648
  });
2378
2649
  }
2379
2650
 
@@ -17,6 +17,7 @@ import {
17
17
  giteaReleasePagePath,
18
18
  giteaTagProcessingPollIntervalMs,
19
19
  giteaTagProcessingTimeoutMs,
20
+ GiteaReleasePageCheckError,
20
21
  } from "../../assets/templates/asset_tspack_release_gitea/scripts/gitzone-gitea-tag.mjs";
21
22
 
22
23
  const maximumManifestBytes = 4 * 1024 * 1024;
@@ -1111,10 +1112,13 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
1111
1112
  * when it processes a pushed tag, and answers 404 for a draft and for a tag
1112
1113
  * it has not processed yet. The API never shows a tag-only row.
1113
1114
  */
1114
- private async publicReleasePageStatus(): Promise<number> {
1115
+ private async publicReleasePageStatus(remainingMs: number): Promise<number> {
1115
1116
  const watchdog = new GiteaTransferWatchdog(
1116
1117
  "GET",
1117
- this.limits,
1118
+ {
1119
+ ...this.limits,
1120
+ responseTimeoutMs: Math.min(this.limits.responseTimeoutMs, remainingMs),
1121
+ },
1118
1122
  maximumMetadataBytes,
1119
1123
  );
1120
1124
  let response: Response | undefined;
@@ -1131,12 +1135,14 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
1131
1135
  watchdog.progress("received", 0);
1132
1136
  return response.status;
1133
1137
  } catch (error) {
1134
- if (watchdog.failure) throw watchdog.failure;
1135
- throw new GiteaAssetInconclusiveError(
1136
- `Gitea release page check is inconclusive ${describeGiteaRequestFailure(
1137
- error,
1138
- { status: response?.status, progress: "headers only" },
1139
- )}; no release was created.`,
1138
+ throw new GiteaReleasePageCheckError(
1139
+ error,
1140
+ watchdog.failure
1141
+ ? `(${watchdog.failure.name}: ${watchdog.failure.message})`
1142
+ : describeGiteaRequestFailure(error, {
1143
+ status: response?.status,
1144
+ progress: "headers only",
1145
+ }),
1140
1146
  );
1141
1147
  } finally {
1142
1148
  watchdog.close();
@@ -1153,7 +1159,7 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
1153
1159
  onWaiting?: (elapsedMs: number) => void,
1154
1160
  ): Promise<void> {
1155
1161
  const result = await awaitGiteaTagProcessed({
1156
- pageStatus: () => this.publicReleasePageStatus(),
1162
+ pageStatus: (remainingMs) => this.publicReleasePageStatus(remainingMs),
1157
1163
  timeoutMs: this.tagProcessingTimeoutMs,
1158
1164
  pollIntervalMs: this.tagProcessingPollIntervalMs,
1159
1165
  onWaiting,
@@ -1164,7 +1170,10 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
1164
1170
  );
1165
1171
  if (result.outcome === "timeout")
1166
1172
  throw new GiteaTagProcessingTimeoutError(
1167
- `Gitea has not processed the pushed tag ${this.tag} within ${formatSeconds(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.`,
1173
+ `Gitea has not processed the pushed tag ${this.tag} within ${formatSeconds(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
+ (result.lastError
1175
+ ? ` Last page check error: ${result.lastError}`
1176
+ : ""),
1168
1177
  );
1169
1178
  }
1170
1179