@git.zone/cli 8.5.0 → 8.6.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/.gitea/workflows/release.yml +12 -18
- package/assets/templates/asset_tspack_release_gitea/scripts/gitzone-gitea-tag.d.mts +22 -0
- package/assets/templates/asset_tspack_release_gitea/scripts/gitzone-gitea-tag.mjs +48 -0
- package/assets/templates/asset_tspack_release_gitea/scripts/gitzone-release-api.mjs +244 -74
- package/assets/templates/asset_tspack_release_gitea/scripts/gitzone-sealed-release.mjs +103 -38
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/helpers.workflow.d.ts +7 -6
- package/dist_ts/helpers.workflow.js +2 -2
- package/dist_ts/mod_config/index.js +2 -2
- package/dist_ts/mod_format/formatters/assets.formatter.js +2 -1
- package/dist_ts/mod_release/helpers.giteaassets.d.ts +51 -9
- package/dist_ts/mod_release/helpers.giteaassets.js +120 -12
- package/dist_ts/mod_release/helpers.releasepublication.d.ts +1 -1
- package/dist_ts/mod_release/helpers.releasepublication.js +54 -21
- package/dist_ts/mod_release/interfaces.giteaassets.d.ts +24 -3
- package/package.json +1 -1
- package/readme.md +110 -41
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/helpers.workflow.ts +7 -6
- package/ts/mod_config/index.ts +1 -1
- package/ts/mod_format/formatters/assets.formatter.ts +1 -0
- package/ts/mod_release/helpers.giteaassets.ts +151 -9
- package/ts/mod_release/helpers.releasepublication.ts +85 -29
- package/ts/mod_release/interfaces.giteaassets.ts +26 -1
package/readme.md
CHANGED
|
@@ -765,19 +765,52 @@ its attachment list and its attachment downloads only to accounts with write
|
|
|
765
765
|
access to the repository's releases; everyone else gets 404, also for the
|
|
766
766
|
attachment's UUID URL and for `/releases/download/<tag>/<name>`.
|
|
767
767
|
|
|
768
|
-
Attachments publish
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
768
|
+
Attachments publish one at a time in manifest order by default: each uploads,
|
|
769
|
+
then is downloaded and hashed, then the next starts. Two transfers in the same
|
|
770
|
+
direction share the link, so each takes longer than it would alone; a large
|
|
771
|
+
upload that runs long enough outlasts the reverse proxy in front of Gitea, which
|
|
772
|
+
then answers HTTP 504 although the bytes kept moving (Spark 35.0.1: two
|
|
773
|
+
concurrent 385 MB uploads took over 11 minutes each, against about 3 minutes
|
|
774
|
+
each one after another, and one ended in a 504). Every upload must therefore
|
|
775
|
+
finish, including the time Gitea needs to store it, within that proxy's timeout,
|
|
776
|
+
and gitzone never runs two uploads, or two verification downloads, at the same
|
|
777
|
+
time. `concurrency: 2` pipelines the attachments instead: the next one uploads
|
|
778
|
+
while the previous one is downloaded and hashed, largest first so the last
|
|
779
|
+
verification is a short one. That is the only overlap that does not share a
|
|
780
|
+
direction; on a link where the two directions are not independent, keep the
|
|
781
|
+
default.
|
|
782
|
+
|
|
783
|
+
Once an attachment publication fails, no further attachment starts; the one
|
|
784
|
+
already running finishes, because cutting a running transfer off would leave its
|
|
772
785
|
result inconclusive, and every failure is reported. The journal keeps each
|
|
773
786
|
attachment's own attempt, so `gitzone release resume` continues with exactly the
|
|
774
|
-
unfinished ones. A crash
|
|
775
|
-
|
|
787
|
+
unfinished ones. A crash while pipelining can leave two attachments in
|
|
788
|
+
`publishing`; each needs its own `--recover-attempt`, one resume at a time.
|
|
789
|
+
|
|
790
|
+
An upload that ends in HTTP 504 (or any other unknown outcome) is inspected right
|
|
791
|
+
away: an attachment Gitea stored anyway is downloaded and hashed and then counts
|
|
792
|
+
as published, a missing one is recorded as failed and uploaded again on resume.
|
|
793
|
+
If the proxy let Gitea finish the abandoned request after the resume uploaded the
|
|
794
|
+
attachment again, the release lists the name twice; that is a destination
|
|
795
|
+
conflict that stops the release, never a silent replacement.
|
|
776
796
|
|
|
777
797
|
The lifecycle of the Gitea release:
|
|
778
798
|
|
|
779
|
-
1. After the Git push,
|
|
780
|
-
|
|
799
|
+
1. After the Git push, wait until Gitea has processed the pushed tag, then
|
|
800
|
+
create the release with `draft: true` (or adopt the draft or published
|
|
801
|
+
release that already carries the tag) and read it back. Gitea processes a
|
|
802
|
+
tag push in its push queue after the push returned, sometimes minutes later,
|
|
803
|
+
and publishes (`draft: false`) any release it then finds for the tag, so a
|
|
804
|
+
draft created earlier would turn public on its own with the attachments it
|
|
805
|
+
has by then (Spark 35.0.1 with gitzone 8.5.0: the draft turned public while
|
|
806
|
+
its two largest binaries were uploading). Processing the tag writes a
|
|
807
|
+
tag-only release row, which the API hides and the public release page
|
|
808
|
+
(`/<owner>/<repo>/releases/tag/<tag>`) shows; once that page answers 200,
|
|
809
|
+
creating the release converts that row into the draft in place and Gitea
|
|
810
|
+
never touches it again. The wait polls every 5 seconds for at most 15
|
|
811
|
+
minutes; when it runs out, nothing was created and `gitzone release resume`
|
|
812
|
+
waits again. A release that this run created must read back as a draft,
|
|
813
|
+
otherwise the release stops before any upload.
|
|
781
814
|
2. Upload every attachment into it and download and hash each one. While the
|
|
782
815
|
release is a draft, listing and downloads carry the token (sent only to the
|
|
783
816
|
configured Gitea origin, never along a redirect to another host); a draft's
|
|
@@ -808,7 +841,12 @@ previous semantics: its attachments are listed and downloaded anonymously, and
|
|
|
808
841
|
publishing only verifies it. Because every attachment of such a release is
|
|
809
842
|
public the moment it lands, its missing attachments upload one at a time in
|
|
810
843
|
manifest order, whatever `concurrency` says, so sources and notices still come
|
|
811
|
-
before the binaries that follow them in the manifest.
|
|
844
|
+
before the binaries that follow them in the manifest. The upload order and
|
|
845
|
+
concurrency follow the state Gitea reports, never the state gitzone intended,
|
|
846
|
+
and every upload first reads the release again: a draft that turned public
|
|
847
|
+
meanwhile stops the release before the next byte is sent
|
|
848
|
+
(`GiteaReleaseStateChangedError`), and so does a draft that turned public
|
|
849
|
+
before publication; resume then continues it as a published release.
|
|
812
850
|
|
|
813
851
|
Tag-triggered CI that reads the Gitea release sees the same thing anonymous
|
|
814
852
|
users see. The Git target pushes the tag before the Gitea target creates the
|
|
@@ -837,12 +875,14 @@ binary on a slow server finishes as long as bytes keep moving:
|
|
|
837
875
|
| `responseTimeoutSeconds` | 120 | Wait for response headers of a metadata request or download |
|
|
838
876
|
| `stallTimeoutSeconds` | 60 | Longest gap without a byte sent or received while a transfer runs |
|
|
839
877
|
| `minimumKiBPerSecond` | 256 | Rate floor; a request may take the two bounds above plus its size at this rate |
|
|
840
|
-
| `concurrency` |
|
|
878
|
+
| `concurrency` | 1 | Attachments of a draft in progress at the same time (1 or 2); 2 uploads one while the previous is verified |
|
|
841
879
|
|
|
842
|
-
The rate floor applies to every request on its own.
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
880
|
+
The rate floor applies to every request on its own. Since uploads never
|
|
881
|
+
overlap, and neither do downloads, each direction of the link has to carry
|
|
882
|
+
`minimumKiBPerSecond` once, whatever `concurrency` says. `gitzone config
|
|
883
|
+
doctor` prints that rate. These bounds are gitzone's own; a reverse proxy in
|
|
884
|
+
front of Gitea can end a request sooner (HTTP 504), which is why uploads never
|
|
885
|
+
share the link.
|
|
846
886
|
|
|
847
887
|
Gitea stores an upload before it answers, which takes minutes for a large
|
|
848
888
|
binary. After an upload's last byte the CLI therefore waits for the upload's
|
|
@@ -1346,7 +1386,7 @@ For a component that already builds and packages with `@git.zone/tspack`, select
|
|
|
1346
1386
|
`assets.kind: "tspackRelease"`. GitZone manages the tag-triggered workflow and its
|
|
1347
1387
|
release scripts. Compilation stays in the component's command, and TsPack owns
|
|
1348
1388
|
archive creation and verification. The project must install `@git.zone/tspack`
|
|
1349
|
-
1.
|
|
1389
|
+
1.4.0 or later and ignore both configured output and `dist_gitzone_retained/` in Git.
|
|
1350
1390
|
Pin pnpm 11 or later in `package.json` using `packageManager`. The workflow installs
|
|
1351
1391
|
that version directly with the pinned official `pnpm/setup` action before the
|
|
1352
1392
|
explicit frozen dependency install. This avoids an older container-provided pnpm
|
|
@@ -1375,38 +1415,67 @@ this setup does not require a separate Deno action.
|
|
|
1375
1415
|
Both commands return exactly one JSON object on stdout with `directory` and
|
|
1376
1416
|
`manifestSha256`. Preparation creates a clean tagged release directly beneath
|
|
1377
1417
|
the configured output root and saves every input descriptor needed for reuse.
|
|
1378
|
-
Verification restores that same result without compiling or repacking
|
|
1379
|
-
|
|
1418
|
+
Verification restores that same result without compiling or repacking; the
|
|
1419
|
+
workflow runs it right after preparation and requires the same directory and
|
|
1420
|
+
manifest digest. Commands are explicit executable/argument arrays; GitZone does
|
|
1421
|
+
not interpolate a shell.
|
|
1380
1422
|
A command's stderr goes straight to the job log, so write build progress and
|
|
1381
1423
|
diagnostics there and keep stdout for the JSON result. The command runs without
|
|
1382
1424
|
`GITHUB_TOKEN` and `ACTIONS_RUNTIME_TOKEN`. When it exits non-zero or is killed,
|
|
1383
1425
|
the release step fails with a line that names the command and its exit code or
|
|
1384
1426
|
signal, below the command's own stderr. A command that writes more than 1 MiB to
|
|
1385
1427
|
stdout or runs longer than 30 minutes is stopped and fails the step by name.
|
|
1386
|
-
Run `gitzone format --only assets --write --yes` and commit the generated files
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1428
|
+
Run `gitzone format --only assets --write --yes` and commit the generated files
|
|
1429
|
+
(`.gitea/workflows/release.yml` and three scripts in `scripts/`). The normal
|
|
1430
|
+
authorized `gitzone release -y` pushes the tag that triggers this CI flow.
|
|
1431
|
+
|
|
1432
|
+
The draft Gitea release is the retention. The workflow does not use Actions
|
|
1433
|
+
artifacts: Gitea scopes them to one run attempt, so a rerun could not read them,
|
|
1434
|
+
and Gitea 1.27 finalizes an upload by merging its chunks inside the request, which
|
|
1435
|
+
outlasts the artifact client's 3-minute timeout for a few hundred megabytes and
|
|
1436
|
+
then fails every retry because the merge already consumed the chunks. Release
|
|
1437
|
+
attachments belong to the tag, and the job token can write them.
|
|
1438
|
+
|
|
1439
|
+
1. **Discover** reads the tag's release with the job token and anonymously. With
|
|
1440
|
+
no release, the job builds. A release must name its manifest digest in its
|
|
1441
|
+
description; its `tspack-manifest.json` attachment must hash to that digest,
|
|
1442
|
+
TsPack must accept the manifest and `SHA256SUMS.txt` for the tagged commit, and
|
|
1443
|
+
the attachments must be exactly the sealed set. Discovery then downloads every
|
|
1444
|
+
archive into `dist_gitzone_retained/` and hashes it against the manifest. A
|
|
1445
|
+
complete set is retained and nothing is built. A draft that is not complete is
|
|
1446
|
+
rebuilt. A published release that is not complete stops the job.
|
|
1447
|
+
2. **Prepare** runs the component's prepare command, verifies the result with
|
|
1448
|
+
TsPack, runs the verify command on it, and writes the release receipt.
|
|
1449
|
+
3. **Retain** waits until Gitea has processed the pushed tag before it creates a
|
|
1450
|
+
draft, because Gitea publishes a release it finds for a tag when it processes
|
|
1451
|
+
the push (the same wait `gitzone release` uses; see [Gitea release attachments before npm](#gitea-release-attachments-before-npm)). The
|
|
1452
|
+
draft's description names the manifest digest. Uploads run one at a time; every
|
|
1453
|
+
upload reads the release again first, then the attachment is downloaded and
|
|
1454
|
+
hashed. Attachments that already match are kept.
|
|
1455
|
+
4. **Restore** moves the retained download into the output root and verifies it
|
|
1456
|
+
with TsPack against the manifest digest and the tagged commit. A resumed job
|
|
1457
|
+
does not run the component's verify command: the restored bytes are
|
|
1458
|
+
hash-bound to the digest the description names, which was written only after
|
|
1459
|
+
the verify command passed on the job that built them.
|
|
1460
|
+
5. **Publish** checks that the draft holds exactly the attachments this job
|
|
1461
|
+
hashed (Gitea stores an attachment's bytes under its UUID, and its API can only
|
|
1462
|
+
rename one, so id, name and UUID identify hashed bytes), checks the remote tag
|
|
1463
|
+
again, publishes the draft and confirms the release and its attachment list
|
|
1464
|
+
anonymously.
|
|
1465
|
+
|
|
1466
|
+
A published attachment is never replaced and a release is never deleted. A draft
|
|
1467
|
+
has never been public, so a draft attachment that conflicts with the sealed set
|
|
1468
|
+
(an interrupted earlier attempt whose rebuild produced different bytes, or a file
|
|
1469
|
+
outside the set) is replaced: right before each deletion the release must still
|
|
1470
|
+
read back as a draft with the token and be invisible anonymously, and the job log
|
|
1471
|
+
names the attachment and both digests. A draft that turns public meanwhile stops
|
|
1472
|
+
the job before the next change.
|
|
1473
|
+
|
|
1474
|
+
After an interruption, rerun the job. A rerun after a complete draft or a
|
|
1475
|
+
published release resumes from its bytes without building; a rerun after an
|
|
1476
|
+
incomplete draft rebuilds and completes it. The remote tag must match the sealed
|
|
1477
|
+
source commit. Unexpected API responses, a publicly visible draft, an incomplete
|
|
1478
|
+
published release and changed source identities stop before publication.
|
|
1410
1479
|
|
|
1411
1480
|
## Formatting
|
|
1412
1481
|
|
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.6.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
|
@@ -89,10 +89,11 @@ export interface IReleaseGiteaAssetsTargetConfig {
|
|
|
89
89
|
/** Rate floor that bounds a whole transfer by its size; default 256. */
|
|
90
90
|
minimumKiBPerSecond?: number;
|
|
91
91
|
/**
|
|
92
|
-
* Attachments
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
92
|
+
* Attachments of a draft in progress at the same time, largest first;
|
|
93
|
+
* default 1, at most 2. Uploads never overlap and neither do verification
|
|
94
|
+
* downloads: with 2 the next attachment uploads while the previous one is
|
|
95
|
+
* verified. Uploads into an already published release run one at a time in
|
|
96
|
+
* manifest order.
|
|
96
97
|
*/
|
|
97
98
|
concurrency?: number;
|
|
98
99
|
}
|
|
@@ -199,7 +200,7 @@ export const resolveGiteaAssetTransferLimits = (
|
|
|
199
200
|
});
|
|
200
201
|
|
|
201
202
|
/**
|
|
202
|
-
* How many attachments a
|
|
203
|
+
* How many attachments of a draft are in progress at the same time. Like the
|
|
203
204
|
* transfer bounds this is tuning, not identity: it may change between resumes.
|
|
204
205
|
*/
|
|
205
206
|
export const resolveGiteaAssetConcurrency = (
|
|
@@ -335,7 +336,7 @@ export interface IResolvedReleaseWorkflow {
|
|
|
335
336
|
npmVerificationWindowMinutes: number;
|
|
336
337
|
giteaAssets?: IResolvedReleaseGiteaAssetsConfiguration;
|
|
337
338
|
giteaAssetTransfer?: IGiteaAssetTransferLimits;
|
|
338
|
-
/** Attachments
|
|
339
|
+
/** Attachments of a draft in progress at the same time. */
|
|
339
340
|
giteaAssetConcurrency?: number;
|
|
340
341
|
dockerEnabled: boolean;
|
|
341
342
|
dockerEngine: "tsdocker";
|
package/ts/mod_config/index.ts
CHANGED
|
@@ -1970,7 +1970,7 @@ async function validateReleaseConfig(
|
|
|
1970
1970
|
const concurrency = resolveGiteaAssetConcurrency(targets.giteaAssets);
|
|
1971
1971
|
findings.push({
|
|
1972
1972
|
level: "ok",
|
|
1973
|
-
message: `Gitea asset transfers wait ${transfer.responseTimeoutMs / 1000} s for a response, fail after ${transfer.stallTimeoutMs / 1000} s without progress, and must average at least ${transfer.minimumBytesPerSecond / 1024} KiB/s each; ${concurrency
|
|
1973
|
+
message: `Gitea asset transfers wait ${transfer.responseTimeoutMs / 1000} s for a response, fail after ${transfer.stallTimeoutMs / 1000} s without progress, and must average at least ${transfer.minimumBytesPerSecond / 1024} KiB/s each; ${concurrency === 1 ? "one attachment at a time" : "an upload overlaps the previous attachment's verification download"}, never two uploads or two downloads, so each direction of the link must carry ${transfer.minimumBytesPerSecond / 1024} KiB/s`,
|
|
1974
1974
|
});
|
|
1975
1975
|
if (targets.git?.enabled === false || targets.docker?.enabled === true)
|
|
1976
1976
|
throw new Error(
|
|
@@ -140,6 +140,7 @@ const buildDefaultEntries = (assetsConfig: Record<string, any>, cliName: string)
|
|
|
140
140
|
{ from: '.gitea/workflows/release.yml', to: '.gitea/workflows/release.yml' },
|
|
141
141
|
{ from: 'scripts/gitzone-sealed-release.mjs', to: 'scripts/gitzone-sealed-release.mjs' },
|
|
142
142
|
{ from: 'scripts/gitzone-release-api.mjs', to: 'scripts/gitzone-release-api.mjs' },
|
|
143
|
+
{ from: 'scripts/gitzone-gitea-tag.mjs', to: 'scripts/gitzone-gitea-tag.mjs' },
|
|
143
144
|
],
|
|
144
145
|
}];
|
|
145
146
|
}
|
|
@@ -11,6 +11,13 @@ import type {
|
|
|
11
11
|
IGiteaAssetTransferLimits,
|
|
12
12
|
} from "./interfaces.giteaassets.js";
|
|
13
13
|
export type * from "./interfaces.giteaassets.js";
|
|
14
|
+
// The tag-processing wait is shared with the sealed release workflow, which runs a rendered copy.
|
|
15
|
+
import {
|
|
16
|
+
awaitGiteaTagProcessed,
|
|
17
|
+
giteaReleasePagePath,
|
|
18
|
+
giteaTagProcessingPollIntervalMs,
|
|
19
|
+
giteaTagProcessingTimeoutMs,
|
|
20
|
+
} from "../../assets/templates/asset_tspack_release_gitea/scripts/gitzone-gitea-tag.mjs";
|
|
14
21
|
|
|
15
22
|
const maximumManifestBytes = 4 * 1024 * 1024;
|
|
16
23
|
const maximumMetadataBytes = 8 * 1024 * 1024;
|
|
@@ -45,6 +52,31 @@ export class GiteaAssetInconclusiveError extends Error {
|
|
|
45
52
|
}
|
|
46
53
|
}
|
|
47
54
|
|
|
55
|
+
/**
|
|
56
|
+
* The release left the draft state the attachments were being uploaded for,
|
|
57
|
+
* for example because something other than this release published it. No
|
|
58
|
+
* further attachment starts; `gitzone release resume` reads the release again
|
|
59
|
+
* and continues a published release one attachment at a time in manifest order.
|
|
60
|
+
*/
|
|
61
|
+
export class GiteaReleaseStateChangedError extends Error {
|
|
62
|
+
constructor(message: string) {
|
|
63
|
+
super(message);
|
|
64
|
+
this.name = "GiteaReleaseStateChangedError";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Gitea did not process the pushed release tag within the bound, so the draft
|
|
70
|
+
* was not created: Gitea would publish a draft it found for the tag once it
|
|
71
|
+
* processes the push. Nothing was created; resume waits again.
|
|
72
|
+
*/
|
|
73
|
+
export class GiteaTagProcessingTimeoutError extends Error {
|
|
74
|
+
constructor(message: string) {
|
|
75
|
+
super(message);
|
|
76
|
+
this.name = "GiteaTagProcessingTimeoutError";
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
48
80
|
const safeErrorName = /^[A-Za-z][A-Za-z0-9]{0,63}$/;
|
|
49
81
|
const safeErrorCode = /^[A-Z][A-Z0-9_]{1,63}$/;
|
|
50
82
|
/** Plain words only: no digit, colon, slash or dot inside can carry a URL or token. */
|
|
@@ -85,15 +117,27 @@ export const defaultGiteaAssetTransferLimits: Readonly<IGiteaAssetTransferLimits
|
|
|
85
117
|
minimumBytesPerSecond: 256 * 1024,
|
|
86
118
|
});
|
|
87
119
|
|
|
88
|
-
/** Attachments a release publishes at the same time unless configured otherwise. */
|
|
89
|
-
export const defaultGiteaAssetConcurrency = 2;
|
|
90
120
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
121
|
+
* Attachments a release has in progress at the same time unless configured
|
|
122
|
+
* otherwise: one, so every attachment uploads and verifies alone, as fast as
|
|
123
|
+
* the link allows.
|
|
94
124
|
*/
|
|
95
|
-
export const
|
|
125
|
+
export const defaultGiteaAssetConcurrency = 1;
|
|
126
|
+
/**
|
|
127
|
+
* Upper bound of `release.targets.giteaAssets.concurrency`. Two transfers in
|
|
128
|
+
* the same direction share the link, so each takes longer than it would alone
|
|
129
|
+
* and a large upload can outlast the reverse proxy's timeout in front of
|
|
130
|
+
* Gitea (HTTP 504). Uploads therefore never overlap, nor do verification
|
|
131
|
+
* downloads; with 2 the next attachment uploads while the previous one is
|
|
132
|
+
* downloaded and hashed, which is the only overlap that does not share a
|
|
133
|
+
* direction. A higher value would add nothing.
|
|
134
|
+
*/
|
|
135
|
+
export const maximumGiteaAssetConcurrency = 2;
|
|
96
136
|
|
|
137
|
+
export const defaultGiteaTagProcessingTimeoutMs = giteaTagProcessingTimeoutMs;
|
|
138
|
+
export const defaultGiteaTagProcessingPollIntervalMs =
|
|
139
|
+
giteaTagProcessingPollIntervalMs;
|
|
140
|
+
const maximumTagProcessingTimeoutMs = 6 * 60 * 60_000;
|
|
97
141
|
const maximumTransferTimeoutMs = 60 * 60_000;
|
|
98
142
|
const maximumBytesPerSecond = 1024 * 1024 * 1024;
|
|
99
143
|
/** Node fires longer timers immediately; a ceiling this far out never binds. */
|
|
@@ -738,6 +782,8 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
738
782
|
readonly #token: string;
|
|
739
783
|
private readonly fetchImplementation: typeof fetch;
|
|
740
784
|
private readonly limits: IGiteaAssetTransferLimits;
|
|
785
|
+
private readonly tagProcessingTimeoutMs: number;
|
|
786
|
+
private readonly tagProcessingPollIntervalMs: number;
|
|
741
787
|
private readonly repositoryApiPath: string;
|
|
742
788
|
/**
|
|
743
789
|
* The attachment identity this client downloaded and hashed against each
|
|
@@ -771,6 +817,21 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
771
817
|
options.minimumBytesPerSecond ??
|
|
772
818
|
defaultGiteaAssetTransferLimits.minimumBytesPerSecond,
|
|
773
819
|
});
|
|
820
|
+
this.tagProcessingTimeoutMs =
|
|
821
|
+
options.tagProcessingTimeoutMs ?? defaultGiteaTagProcessingTimeoutMs;
|
|
822
|
+
this.tagProcessingPollIntervalMs =
|
|
823
|
+
options.tagProcessingPollIntervalMs ??
|
|
824
|
+
defaultGiteaTagProcessingPollIntervalMs;
|
|
825
|
+
for (const value of [
|
|
826
|
+
this.tagProcessingTimeoutMs,
|
|
827
|
+
this.tagProcessingPollIntervalMs,
|
|
828
|
+
])
|
|
829
|
+
if (
|
|
830
|
+
!Number.isSafeInteger(value) ||
|
|
831
|
+
value <= 0 ||
|
|
832
|
+
value > maximumTagProcessingTimeoutMs
|
|
833
|
+
)
|
|
834
|
+
throw new Error("Invalid Gitea tag processing bound.");
|
|
774
835
|
this.repositoryApiPath = `/repos/${this.destination.owner}/${this.destination.repository}`;
|
|
775
836
|
}
|
|
776
837
|
|
|
@@ -996,7 +1057,7 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
996
1057
|
private release(value: unknown): IGiteaRelease {
|
|
997
1058
|
const release = record(value);
|
|
998
1059
|
const id = positiveId(release.id);
|
|
999
|
-
const publicUrl = `${this.destination.apiOrigin}
|
|
1060
|
+
const publicUrl = `${this.destination.apiOrigin}${giteaReleasePagePath(this.destination.owner, this.destination.repository, this.tag)}`;
|
|
1000
1061
|
if (
|
|
1001
1062
|
release.tag_name !== this.tag ||
|
|
1002
1063
|
typeof release.draft !== "boolean" ||
|
|
@@ -1044,8 +1105,74 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1044
1105
|
return found;
|
|
1045
1106
|
}
|
|
1046
1107
|
|
|
1047
|
-
|
|
1108
|
+
/**
|
|
1109
|
+
* The anonymous status of the release's public page. Gitea renders it for a
|
|
1110
|
+
* published release and for the tag-only release row its push queue writes
|
|
1111
|
+
* when it processes a pushed tag, and answers 404 for a draft and for a tag
|
|
1112
|
+
* it has not processed yet. The API never shows a tag-only row.
|
|
1113
|
+
*/
|
|
1114
|
+
private async publicReleasePageStatus(): Promise<number> {
|
|
1115
|
+
const watchdog = new GiteaTransferWatchdog(
|
|
1116
|
+
"GET",
|
|
1117
|
+
this.limits,
|
|
1118
|
+
maximumMetadataBytes,
|
|
1119
|
+
);
|
|
1120
|
+
let response: Response | undefined;
|
|
1121
|
+
try {
|
|
1122
|
+
watchdog.awaitResponse();
|
|
1123
|
+
response = await this.fetchImplementation(
|
|
1124
|
+
`${this.destination.apiOrigin}${giteaReleasePagePath(this.destination.owner, this.destination.repository, this.tag)}`,
|
|
1125
|
+
{
|
|
1126
|
+
redirect: "manual",
|
|
1127
|
+
signal: watchdog.signal,
|
|
1128
|
+
headers: { Accept: "text/html" },
|
|
1129
|
+
},
|
|
1130
|
+
);
|
|
1131
|
+
watchdog.progress("received", 0);
|
|
1132
|
+
return response.status;
|
|
1133
|
+
} 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.`,
|
|
1140
|
+
);
|
|
1141
|
+
} finally {
|
|
1142
|
+
watchdog.close();
|
|
1143
|
+
if (response?.body) await response.body.cancel().catch(() => undefined);
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
/**
|
|
1148
|
+
* Waits until Gitea has processed the pushed tag; `awaitGiteaTagProcessed`
|
|
1149
|
+
* (shared with the sealed release workflow) documents why a draft must not
|
|
1150
|
+
* exist before that.
|
|
1151
|
+
*/
|
|
1152
|
+
private async awaitTagProcessed(
|
|
1153
|
+
onWaiting?: (elapsedMs: number) => void,
|
|
1154
|
+
): Promise<void> {
|
|
1155
|
+
const result = await awaitGiteaTagProcessed({
|
|
1156
|
+
pageStatus: () => this.publicReleasePageStatus(),
|
|
1157
|
+
timeoutMs: this.tagProcessingTimeoutMs,
|
|
1158
|
+
pollIntervalMs: this.tagProcessingPollIntervalMs,
|
|
1159
|
+
onWaiting,
|
|
1160
|
+
});
|
|
1161
|
+
if (result.outcome === "unexpected")
|
|
1162
|
+
throw new GiteaAssetInconclusiveError(
|
|
1163
|
+
`Gitea release page check is inconclusive (HTTP ${result.status}); no release was created.`,
|
|
1164
|
+
);
|
|
1165
|
+
if (result.outcome === "timeout")
|
|
1166
|
+
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.`,
|
|
1168
|
+
);
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
public async createRelease(
|
|
1172
|
+
onWaiting?: (elapsedMs: number) => void,
|
|
1173
|
+
): Promise<IGiteaRelease> {
|
|
1048
1174
|
await this.admitTag();
|
|
1175
|
+
await this.awaitTagProcessed(onWaiting);
|
|
1049
1176
|
const result = this.release(
|
|
1050
1177
|
await this.requestJson(
|
|
1051
1178
|
`${this.repositoryApiPath}/releases`,
|
|
@@ -1088,10 +1215,17 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1088
1215
|
public async publishRelease(
|
|
1089
1216
|
releaseId: number,
|
|
1090
1217
|
expected: IGiteaFrozenAsset[],
|
|
1218
|
+
expectedDraft: boolean,
|
|
1091
1219
|
): Promise<void> {
|
|
1092
1220
|
positiveId(releaseId);
|
|
1093
1221
|
const { inspection, attachments, release } =
|
|
1094
1222
|
await this.inspectAssetsWithIds(releaseId, expected, []);
|
|
1223
|
+
if (release.draft !== expectedDraft)
|
|
1224
|
+
throw new GiteaReleaseStateChangedError(
|
|
1225
|
+
expectedDraft
|
|
1226
|
+
? `Gitea release ${this.tag} was published before this run verified its complete attachment set.`
|
|
1227
|
+
: `Gitea release ${this.tag} became a draft during publication.`,
|
|
1228
|
+
);
|
|
1095
1229
|
if (inspection.missing.length !== 0)
|
|
1096
1230
|
throw new Error(
|
|
1097
1231
|
"Gitea attachment set is incomplete; the release stays a draft.",
|
|
@@ -1456,6 +1590,7 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1456
1590
|
releaseId: number,
|
|
1457
1591
|
asset: IGiteaFrozenAsset,
|
|
1458
1592
|
artifactDirectory: string,
|
|
1593
|
+
expectedDraft: boolean,
|
|
1459
1594
|
): Promise<void> {
|
|
1460
1595
|
positiveId(releaseId);
|
|
1461
1596
|
assertGiteaFrozenAssets([asset], this.destination, this.tag);
|
|
@@ -1464,10 +1599,17 @@ export class GiteaAssetsClient implements IGiteaAssetsClient {
|
|
|
1464
1599
|
);
|
|
1465
1600
|
try {
|
|
1466
1601
|
await verifyHandle(handle, asset);
|
|
1467
|
-
|
|
1602
|
+
const release = await this.inspectRelease();
|
|
1603
|
+
if (release?.id !== releaseId)
|
|
1468
1604
|
throw new GiteaAssetConflictError(
|
|
1469
1605
|
"Gitea release identifier changed before upload.",
|
|
1470
1606
|
);
|
|
1607
|
+
if (release.draft !== expectedDraft)
|
|
1608
|
+
throw new GiteaReleaseStateChangedError(
|
|
1609
|
+
expectedDraft
|
|
1610
|
+
? `Gitea release ${this.tag} was published while its attachment set was incomplete; ${asset.name} was not uploaded and no further attachment starts.`
|
|
1611
|
+
: `Gitea release ${this.tag} became a draft during publication; ${asset.name} was not uploaded and no further attachment starts.`,
|
|
1612
|
+
);
|
|
1471
1613
|
// Authenticated: a writer also sees the attachments of a draft.
|
|
1472
1614
|
const listed = await this.requestJson(
|
|
1473
1615
|
`${this.repositoryApiPath}/releases/${releaseId}/assets`,
|