@git.zone/cli 8.10.1 → 8.11.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/asset_tspack_release_gitea/scripts/gitzone-gitea-tag.d.mts +9 -3
- package/assets/templates/asset_tspack_release_gitea/scripts/gitzone-gitea-tag.mjs +50 -6
- package/assets/templates/asset_tspack_release_gitea/scripts/gitzone-release-api.mjs +7 -6
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/helpers.ownerscopes.d.ts +1 -1
- package/dist_ts/helpers.ownerscopes.js +2 -1
- package/dist_ts/helpers.workflow.d.ts +2 -0
- package/dist_ts/helpers.workflow.js +3 -1
- package/dist_ts/mod_release/classes.releasejournal.d.ts +63 -2
- package/dist_ts/mod_release/classes.releasejournal.js +247 -48
- package/dist_ts/mod_release/helpers.giteaassets.js +18 -9
- package/dist_ts/mod_release/index.js +100 -4
- package/package.json +2 -2
- package/readme.md +99 -11
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/helpers.ownerscopes.ts +1 -0
- package/ts/helpers.workflow.ts +6 -0
- package/ts/mod_release/classes.releasejournal.ts +323 -52
- package/ts/mod_release/helpers.giteaassets.ts +19 -10
- package/ts/mod_release/index.ts +132 -2
package/readme.md
CHANGED
|
@@ -707,20 +707,101 @@ Every release that reaches final publication stores `journal.json` under the rep
|
|
|
707
707
|
<git-common-dir>/gitzone/releases/v1/v<version>/journal.json
|
|
708
708
|
```
|
|
709
709
|
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
710
|
+
Frozen Gitea assets are stored beside them as `asset.<sha256-of-asset-name>.bin`.
|
|
711
|
+
Together, the tarballs and assets are a record's payload.
|
|
712
|
+
|
|
713
|
+
After a fresh release, recovery or resume completes, GitZone keeps the payload
|
|
714
|
+
of the newest three completed local version records by journal creation time
|
|
715
|
+
and deletes the payload of older completed records. Journals and every other
|
|
716
|
+
file of a record stay, so `gitzone release inspect` still lists every version.
|
|
713
717
|
Set `@git.zone/cli.release.recordRetention` in `.smartconfig.json` to a positive
|
|
714
718
|
integer to change this limit, for example `"release": { "recordRetention": 5 }`.
|
|
715
719
|
The current run's record is always retained, even when resuming an older
|
|
716
720
|
version. Incomplete records (including accepted uploads awaiting verification),
|
|
717
721
|
release intents, temporary preparation directories and records locked by an
|
|
718
722
|
active publication or resume are retained in addition to the configured count.
|
|
719
|
-
A malformed journal stops cleanup before deletion; stale record locks
|
|
720
|
-
the same manual owner check as other release locks. Retention affects
|
|
721
|
-
records only; it leaves Git tags and published releases unchanged.
|
|
722
|
-
|
|
723
|
-
|
|
723
|
+
A malformed or missing journal stops cleanup before deletion; stale record locks
|
|
724
|
+
require the same manual owner check as other release locks. Retention affects
|
|
725
|
+
local records only; it leaves Git tags and published releases unchanged. A
|
|
726
|
+
pruned completed version has nothing left to resume: `gitzone release resume`
|
|
727
|
+
reports that its artifacts were removed.
|
|
728
|
+
|
|
729
|
+
#### Pruning on demand
|
|
730
|
+
|
|
731
|
+
A repository that is not released again keeps its records until the next
|
|
732
|
+
release completes. `gitzone release prune` applies the same retention at any
|
|
733
|
+
time, through the same implementation:
|
|
734
|
+
|
|
735
|
+
```bash
|
|
736
|
+
gitzone release prune # report only
|
|
737
|
+
gitzone release prune --keep 1 # report against another retention count
|
|
738
|
+
gitzone release prune --apply # delete the reported payloads
|
|
739
|
+
gitzone release prune --json # machine-readable report
|
|
740
|
+
```
|
|
741
|
+
|
|
742
|
+
It reads `release.recordRetention` (default 3) unless `--keep <n>` overrides it,
|
|
743
|
+
and deletes nothing without `--apply`. It refuses to run, with `--apply` or
|
|
744
|
+
without, while the release store shows a release at work: a journal, record,
|
|
745
|
+
creation or recovery-preparation lock (`v<version>.lock`,
|
|
746
|
+
`v<version>.record.lock`, `v<version>.create.lock`,
|
|
747
|
+
`v<version>.prepare.lock`), the detached-run lock (`detached.lock`) or a
|
|
748
|
+
temporary preparation directory (`.v<version>.tmp-*`). The error lists those
|
|
749
|
+
paths; remove a stale one only after checking that no release process is left.
|
|
750
|
+
An attached release has no such state before it starts preparing its
|
|
751
|
+
artifacts; prune never touches a record that release later creates.
|
|
752
|
+
|
|
753
|
+
`--json` prints one object, also on failure (`{ "ok": false, "error": "..." }`
|
|
754
|
+
with exit code 1):
|
|
755
|
+
|
|
756
|
+
```json
|
|
757
|
+
{
|
|
758
|
+
"ok": true,
|
|
759
|
+
"dryRun": true,
|
|
760
|
+
"keep": 3,
|
|
761
|
+
"root": "/repo/.git/gitzone/releases/v1",
|
|
762
|
+
"records": [
|
|
763
|
+
{
|
|
764
|
+
"version": "35.1.9",
|
|
765
|
+
"state": "completed",
|
|
766
|
+
"createdAt": "2026-10-12T17:49:20.443Z",
|
|
767
|
+
"completedAt": "2026-10-12T18:32:01.907Z",
|
|
768
|
+
"bytes": 2125164346,
|
|
769
|
+
"payloadBytes": 2125156896,
|
|
770
|
+
"payloadFiles": 12,
|
|
771
|
+
"action": "kept",
|
|
772
|
+
"reason": "newest-completed"
|
|
773
|
+
}
|
|
774
|
+
],
|
|
775
|
+
"totals": {
|
|
776
|
+
"records": 47,
|
|
777
|
+
"kept": 4,
|
|
778
|
+
"pruned": 43,
|
|
779
|
+
"blocked": 0,
|
|
780
|
+
"bytes": 83701754868,
|
|
781
|
+
"wouldFreeBytes": 73850194634,
|
|
782
|
+
"freedBytes": 0
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
```
|
|
786
|
+
|
|
787
|
+
Records are ordered newest first by journal creation time. `state` is
|
|
788
|
+
`completed`, `incomplete` or `invalid` (the journal is missing or malformed;
|
|
789
|
+
`createdAt` and `completedAt` are then `null`). `bytes` counts every regular
|
|
790
|
+
file of the record directory, `payloadBytes` and `payloadFiles` its tarballs
|
|
791
|
+
and assets. `action` and `reason` are:
|
|
792
|
+
|
|
793
|
+
| action | reason | meaning |
|
|
794
|
+
| --------- | ------------------ | --------------------------------------------------------------- |
|
|
795
|
+
| `kept` | `newest-completed` | within the newest `keep` completed records |
|
|
796
|
+
| `kept` | `incomplete` | not complete; resume needs its payload |
|
|
797
|
+
| `pruned` | `older-completed` | payload removed by `--apply`; a dry run reports it as removable |
|
|
798
|
+
| `pruned` | `payload-absent` | beyond retention with no payload left; nothing to free |
|
|
799
|
+
| `blocked` | `intent-present` | a release intent for this version exists |
|
|
800
|
+
| `blocked` | `record-in-use` | a publication or resume holds the record lock |
|
|
801
|
+
| `blocked` | `invalid-journal` | `detail` names the error; `--apply` stops before any deletion |
|
|
802
|
+
|
|
803
|
+
`totals.wouldFreeBytes` sums the payloads of `pruned` records;
|
|
804
|
+
`totals.freedBytes` is the same number after `--apply` and `0` in a dry run.
|
|
724
805
|
|
|
725
806
|
The canonical journal binds the release commit, annotated tag object, hashed Git destination, npm registries, per-target attempt states, and, when npm is selected, the package identity, tarball size, SHA-1, SHA-256, and SHA-512 integrity. Schema 2 also binds the exact tSDocker request, candidate identity, qualification result, ordered destination promotions, probe or promotion evidence, and terminal cleanup result. Journal updates use revision compare-and-swap under an interprocess lock. Release identity and destinations cannot change after journal creation. Qualification and promotion evidence is append-only, destination conflicts are terminal, and completed Docker state cannot regress. Inspect and resume reject malformed, future, noncanonical, duplicate-key, or merely reformatted journal JSON rather than repairing or normalizing it.
|
|
726
807
|
|
|
@@ -1001,8 +1082,13 @@ The lifecycle of the Gitea release:
|
|
|
1001
1082
|
(`/<owner>/<repo>/releases/tag/<tag>`) shows; once that page answers 200,
|
|
1002
1083
|
creating the release converts that row into the draft in place and Gitea
|
|
1003
1084
|
never touches it again. The wait polls every 5 seconds for at most 15
|
|
1004
|
-
minutes
|
|
1005
|
-
|
|
1085
|
+
minutes. A page request that times out, aborts or encounters a transient
|
|
1086
|
+
network failure counts as not yet processed and is polled again within
|
|
1087
|
+
that same deadline; each request is capped by the remaining wait. Definite
|
|
1088
|
+
HTTP statuses other than 200 or 404 still stop immediately. When the wait
|
|
1089
|
+
runs out, its error includes the last page-check error's name and safe
|
|
1090
|
+
message, nothing was created and `gitzone release resume` waits again.
|
|
1091
|
+
A release that this run created must read back as a draft,
|
|
1006
1092
|
otherwise the release stops before any upload.
|
|
1007
1093
|
2. Upload every attachment into it and download and hash each one. While the
|
|
1008
1094
|
release is a draft, listing and downloads carry the token (sent only to the
|
|
@@ -1153,7 +1239,7 @@ gitzone release resume 6.0.0 -y
|
|
|
1153
1239
|
gitzone release resume 6.0.0 -y --recover-attempt="$ATTEMPT_ID"
|
|
1154
1240
|
```
|
|
1155
1241
|
|
|
1156
|
-
Resume requires the annotated release tag and each journaled destination setting to remain exact; the local `main` commit must be exact for any remaining publication work and must merely contain the release commit for a verification-only resume. The Git remote must still match when Git is journaled; npm registry, access, and already-published settings must still match when npm is journaled. Before any recovery or publication work, a nonterminal schema-2 resume canonical-compares the current Docker request with the journal, verifies every required project-local tSDocker protocol capability, and validates the journaled request; additive future capabilities are accepted. A completed schema-2 journal trusts its terminal cleanup evidence and does not require candidate state or current Docker configuration. Non-journaled target configuration is ignored, so releases created with a target subset remain resumable. Fresh-release overrides such as targets, integration, build, test, and version flags are rejected even in negated forms such as `--no-git`, `--no-publish`, and `--no-build`; JSON output is available only through `inspect --json`.
|
|
1242
|
+
Resume requires the annotated release tag and each journaled destination setting to remain exact; the local `main` commit must be exact for any remaining publication work and must merely contain the release commit for a verification-only resume. The Git remote must still match when Git is journaled; npm registry, access, and already-published settings must still match when npm is journaled. Before any recovery or publication work, a nonterminal schema-2 resume canonical-compares the current Docker request with the journal, verifies every required project-local tSDocker protocol capability, and validates the journaled request; additive future capabilities are accepted. A completed schema-2 journal trusts its terminal cleanup evidence and does not require candidate state or current Docker configuration. Non-journaled target configuration is ignored, so releases created with a target subset remain resumable. Fresh-release overrides such as targets, integration, build, test, and version flags are rejected even in negated forms such as `--no-git`, `--no-publish`, and `--no-build`; JSON output is available only through `inspect --json` and `prune --json`.
|
|
1157
1243
|
|
|
1158
1244
|
Resume probes remotely observable targets before acting. A published Git release is identified by its annotated tag and that tag's commit, so remote `main` carrying later commits is exact state rather than a conflict. Exact state is accepted without republishing; positive byte, metadata, ref, or digest conflicts fail closed, while inconclusive results do not overwrite a previously verified state. An npm target in `accepted` state is only ever verified: its bytes are never sent again, and a resume that still cannot read the version leaves it accepted and succeeds. A Git, npm, Docker qualification, promotion, or cleanup target left in `publishing` state retains authority until the exact recorded 32-character lowercase hexadecimal `attempt.id` is supplied after independently proving its publisher stopped. An interrupted tSDocker `preparing` record has no qualification evidence and cannot be promoted; when tSDocker reports `RECOVERY_REQUIRED`, the exact recovered qualification owner removes only that incomplete deterministic preparation before claiming a fresh qualification attempt. Promotion recovery first reclaims the retired owner's request files and probes the journaled destination; an exact qualified digest is accepted, pending state retires the old attempt and claims a fresh owner before retry, an inconclusive probe retains the old journal owner, and conflicts halt permanently. Final cleanup of a qualified candidate starts only after every promotion is verified and is itself idempotently recoverable. A terminal qualification destination conflict has no promotions, blocks Git/npm, and permits only exact qualified-candidate cleanup.
|
|
1159
1245
|
|
|
@@ -1728,6 +1814,8 @@ attachments belong to the tag, and the job token can write them.
|
|
|
1728
1814
|
3. **Retain** waits until Gitea has processed the pushed tag before it creates a
|
|
1729
1815
|
draft, because Gitea publishes a release it finds for a tag when it processes
|
|
1730
1816
|
the push (the same wait `gitzone release` uses; see [Gitea release attachments before npm](#gitea-release-attachments-before-npm)). The
|
|
1817
|
+
wait also retries page timeouts, aborts and transient network errors within
|
|
1818
|
+
its 15-minute deadline, reporting the last cause if it expires. The
|
|
1731
1819
|
draft's description names the manifest digest. Uploads run one at a time; every
|
|
1732
1820
|
upload reads the release again first, then the attachment is downloaded and
|
|
1733
1821
|
hashed. Attachments that already match are kept.
|
package/ts/00_commitinfo_data.ts
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@git.zone/cli',
|
|
6
|
-
version: '8.
|
|
6
|
+
version: '8.11.0',
|
|
7
7
|
description: 'A comprehensive CLI tool for enhancing and managing local development workflows with gitzone utilities, focusing on project setup, version control, code formatting, and template management.'
|
|
8
8
|
}
|
package/ts/helpers.workflow.ts
CHANGED
|
@@ -886,6 +886,12 @@ export const resolveReleaseRecordRetention = (valueArg: unknown): number => {
|
|
|
886
886
|
return valueArg;
|
|
887
887
|
};
|
|
888
888
|
|
|
889
|
+
/** `release.recordRetention` of the current project, for on-demand pruning. */
|
|
890
|
+
export const readReleaseRecordRetention = async (): Promise<number> =>
|
|
891
|
+
resolveReleaseRecordRetention(
|
|
892
|
+
(await readCliWorkflowConfig()).release?.recordRetention,
|
|
893
|
+
);
|
|
894
|
+
|
|
889
895
|
export const resolveCommitWorkflow = async (
|
|
890
896
|
argvArg: any,
|
|
891
897
|
inputMode: "ai" | "manual" = "ai",
|
|
@@ -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
|
|
2318
|
-
* journals stop retention before deletion rather than guessing
|
|
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
|
-
|
|
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
|
-
|
|
2332
|
-
const
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
(
|
|
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
|
|
2343
|
-
|
|
2344
|
-
const
|
|
2345
|
-
if (
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
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
|
|