@git.zone/cli 8.4.0 → 8.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/helpers.workflow.d.ts +16 -0
- package/dist_ts/helpers.workflow.js +9 -2
- package/dist_ts/mod_config/index.js +4 -3
- package/dist_ts/mod_release/classes.releasejournal.js +14 -5
- package/dist_ts/mod_release/helpers.giteaassets.d.ts +101 -3
- package/dist_ts/mod_release/helpers.giteaassets.js +362 -59
- package/dist_ts/mod_release/helpers.releasephase.d.ts +9 -0
- package/dist_ts/mod_release/helpers.releasephase.js +25 -0
- package/dist_ts/mod_release/helpers.releasepreparation.js +6 -3
- package/dist_ts/mod_release/helpers.releasepublication.d.ts +10 -1
- package/dist_ts/mod_release/helpers.releasepublication.js +184 -35
- package/dist_ts/mod_release/index.js +20 -5
- package/dist_ts/mod_release/interfaces.giteaassets.d.ts +39 -2
- package/package.json +4 -4
- package/readme.md +141 -10
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/helpers.workflow.ts +34 -0
- package/ts/mod_config/index.ts +3 -1
- package/ts/mod_release/classes.releasejournal.ts +16 -4
- package/ts/mod_release/helpers.giteaassets.ts +479 -66
- package/ts/mod_release/helpers.releasephase.ts +26 -0
- package/ts/mod_release/helpers.releasepreparation.ts +12 -3
- package/ts/mod_release/helpers.releasepublication.ts +314 -63
- package/ts/mod_release/index.ts +36 -6
- package/ts/mod_release/interfaces.giteaassets.ts +45 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase lines carry the wall-clock time they were printed at, so the log of a
|
|
3
|
+
* release, foreground or detached, shows where its time went.
|
|
4
|
+
*/
|
|
5
|
+
export const formatReleasePhase = (
|
|
6
|
+
messageArg: string,
|
|
7
|
+
atArg: Date = new Date(),
|
|
8
|
+
): string => `[${atArg.toISOString()}] ${messageArg}`;
|
|
9
|
+
|
|
10
|
+
/** Prints one timestamped phase line, separated from the output before it. */
|
|
11
|
+
export const printReleasePhase = (messageArg: string): void => {
|
|
12
|
+
console.log(`\n${formatReleasePhase(messageArg)}`);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/** A duration for people: `850 ms`, `7.1 s`, `12 min 4 s`, `1 h 13 min`. */
|
|
16
|
+
export const formatReleaseDuration = (millisecondsArg: number): string => {
|
|
17
|
+
const milliseconds = Math.max(0, Math.round(millisecondsArg));
|
|
18
|
+
if (milliseconds < 1000) return `${milliseconds} ms`;
|
|
19
|
+
if (milliseconds < 60_000) return `${Math.round(milliseconds / 100) / 10} s`;
|
|
20
|
+
const totalSeconds = Math.round(milliseconds / 1000);
|
|
21
|
+
const hours = Math.floor(totalSeconds / 3600);
|
|
22
|
+
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
|
23
|
+
const seconds = totalSeconds % 60;
|
|
24
|
+
if (hours > 0) return `${hours} h ${minutes} min`;
|
|
25
|
+
return `${minutes} min ${seconds} s`;
|
|
26
|
+
};
|
|
@@ -22,6 +22,10 @@ import {
|
|
|
22
22
|
} from "./helpers.npmartifact.js";
|
|
23
23
|
import { getReleaseNpmPublicationOrder } from "./helpers.npmpackages.js";
|
|
24
24
|
import { formatCommandFailure } from "./helpers.commandfailure.js";
|
|
25
|
+
import {
|
|
26
|
+
formatReleaseDuration,
|
|
27
|
+
printReleasePhase,
|
|
28
|
+
} from "./helpers.releasephase.js";
|
|
25
29
|
import {
|
|
26
30
|
ReleaseGitRemoteError,
|
|
27
31
|
runGitRemoteInspection,
|
|
@@ -443,8 +447,8 @@ export const withIsolatedReleaseCheckout = async <T>(
|
|
|
443
447
|
};
|
|
444
448
|
let added = false;
|
|
445
449
|
try {
|
|
446
|
-
|
|
447
|
-
|
|
450
|
+
printReleasePhase(
|
|
451
|
+
`Preparing the release checkout of ${options.mainOid} at ${checkout}`,
|
|
448
452
|
);
|
|
449
453
|
await releaseGit(
|
|
450
454
|
options.smartshell,
|
|
@@ -562,7 +566,8 @@ const run = async (
|
|
|
562
566
|
command: string,
|
|
563
567
|
phase: string,
|
|
564
568
|
) => {
|
|
565
|
-
|
|
569
|
+
printReleasePhase(`Running the release ${phase} in the release checkout`);
|
|
570
|
+
const startedAt = Date.now();
|
|
566
571
|
const result = await smartshell.exec(command, { cwd });
|
|
567
572
|
if (result.exitCode !== 0)
|
|
568
573
|
throw new Error(
|
|
@@ -572,4 +577,8 @@ const run = async (
|
|
|
572
577
|
{ command, output: "combined" },
|
|
573
578
|
),
|
|
574
579
|
);
|
|
580
|
+
logger.log(
|
|
581
|
+
"success",
|
|
582
|
+
`Release ${phase} passed in the release checkout in ${formatReleaseDuration(Date.now() - startedAt)}.`,
|
|
583
|
+
);
|
|
575
584
|
};
|
|
@@ -19,9 +19,18 @@ import {
|
|
|
19
19
|
import {
|
|
20
20
|
GiteaAssetsClient,
|
|
21
21
|
GiteaAssetConflictError,
|
|
22
|
+
GiteaReleaseStateChangedError,
|
|
23
|
+
defaultGiteaAssetConcurrency,
|
|
24
|
+
maximumGiteaAssetConcurrency,
|
|
22
25
|
validateGiteaAssets,
|
|
23
26
|
type IGiteaAssetTransferLimits,
|
|
27
|
+
type IGiteaFrozenAsset,
|
|
28
|
+
type IGiteaRelease,
|
|
24
29
|
} from "./helpers.giteaassets.js";
|
|
30
|
+
import {
|
|
31
|
+
formatReleaseDuration,
|
|
32
|
+
printReleasePhase,
|
|
33
|
+
} from "./helpers.releasephase.js";
|
|
25
34
|
import { assertGiteaAssetsGitDestination } from "../helpers.workflow.js";
|
|
26
35
|
import {
|
|
27
36
|
defaultNpmVerificationWindowMinutes,
|
|
@@ -142,6 +151,8 @@ export interface IReleasePublicationOptions {
|
|
|
142
151
|
tsdocker?: ITsdockerReleaseClient;
|
|
143
152
|
/** Transfer bounds for the Gitea client built from the journal's destination. */
|
|
144
153
|
giteaAssetTransfer?: IGiteaAssetTransferLimits;
|
|
154
|
+
/** Attachments of a draft in progress at the same time (1 or 2); default 1. */
|
|
155
|
+
giteaAssetConcurrency?: number;
|
|
145
156
|
/** Bound and retries of the Git target's remote inspection. */
|
|
146
157
|
gitRemotePolicy?: IReleaseGitRemotePolicy;
|
|
147
158
|
giteaAssets?: Pick<
|
|
@@ -152,6 +163,7 @@ export interface IReleasePublicationOptions {
|
|
|
152
163
|
| "inspectAssets"
|
|
153
164
|
| "uploadAsset"
|
|
154
165
|
| "verifyComplete"
|
|
166
|
+
| "publishRelease"
|
|
155
167
|
>;
|
|
156
168
|
ensurePublicationState: (expectedRemoteMainOidArg?: string) => Promise<void>;
|
|
157
169
|
}
|
|
@@ -241,11 +253,19 @@ const updateTarget = async (
|
|
|
241
253
|
);
|
|
242
254
|
}
|
|
243
255
|
updateArg(status);
|
|
244
|
-
|
|
256
|
+
const finalized = finalizeJournalCompletion(currentArg);
|
|
257
|
+
// A Gitea target never completes a journal on its own: completion is
|
|
258
|
+
// recorded only after the complete attachment set verified.
|
|
259
|
+
return isGiteaSelector(selectorArg) && currentArg.completedAt === null
|
|
260
|
+
? { ...finalized, completedAt: null }
|
|
261
|
+
: finalized;
|
|
245
262
|
},
|
|
246
263
|
);
|
|
247
264
|
};
|
|
248
265
|
|
|
266
|
+
const isGiteaSelector = (selectorArg: TReleaseTargetSelector): boolean =>
|
|
267
|
+
selectorArg.kind === "gitea-release" || selectorArg.kind === "gitea-asset";
|
|
268
|
+
|
|
249
269
|
const claimTarget = async (
|
|
250
270
|
storeArg: ReleaseJournalStore,
|
|
251
271
|
journalArg: TReleaseJournal,
|
|
@@ -1763,37 +1783,76 @@ const executeDockerPromotion = async (
|
|
|
1763
1783
|
);
|
|
1764
1784
|
};
|
|
1765
1785
|
|
|
1786
|
+
/**
|
|
1787
|
+
* Serializes journal transactions of work that runs concurrently: every
|
|
1788
|
+
* update starts from the journal the previous one produced, so concurrent
|
|
1789
|
+
* attachment publications never race on the journal revision.
|
|
1790
|
+
*/
|
|
1791
|
+
interface IReleaseJournalWriter {
|
|
1792
|
+
current(): TReleaseJournal;
|
|
1793
|
+
write(
|
|
1794
|
+
updateArg: (journalArg: TReleaseJournal) => Promise<TReleaseJournal>,
|
|
1795
|
+
): Promise<TReleaseJournal>;
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1798
|
+
const createReleaseJournalWriter = (
|
|
1799
|
+
journalArg: TReleaseJournal,
|
|
1800
|
+
): IReleaseJournalWriter => {
|
|
1801
|
+
let current = journalArg;
|
|
1802
|
+
let tail: Promise<unknown> = Promise.resolve();
|
|
1803
|
+
return {
|
|
1804
|
+
current: () => current,
|
|
1805
|
+
write: (updateArg) => {
|
|
1806
|
+
const next = tail.then(async () => {
|
|
1807
|
+
current = await updateArg(current);
|
|
1808
|
+
return current;
|
|
1809
|
+
});
|
|
1810
|
+
tail = next.catch(() => undefined);
|
|
1811
|
+
return next;
|
|
1812
|
+
},
|
|
1813
|
+
};
|
|
1814
|
+
};
|
|
1815
|
+
|
|
1816
|
+
const requireGiteaJournal = (
|
|
1817
|
+
journalArg: TReleaseJournal,
|
|
1818
|
+
): IReleaseJournalV4 => {
|
|
1819
|
+
if (journalArg.schemaVersion !== 4)
|
|
1820
|
+
throw new Error("Release journal has no Gitea assets.");
|
|
1821
|
+
return journalArg;
|
|
1822
|
+
};
|
|
1823
|
+
|
|
1766
1824
|
const executeGiteaTarget = async (
|
|
1767
1825
|
options: IReleasePublicationOptions,
|
|
1768
|
-
|
|
1826
|
+
writer: IReleaseJournalWriter,
|
|
1769
1827
|
selector: TReleaseTargetSelector,
|
|
1770
1828
|
/** `verifyBytes` is false only for a target the journal already recorded as verified. */
|
|
1771
1829
|
inspect: (verifyBytes: boolean) => Promise<boolean>,
|
|
1772
1830
|
publish: () => Promise<void>,
|
|
1773
1831
|
onVerified?: (target: IReleaseTargetStatus) => void,
|
|
1774
|
-
): Promise<
|
|
1775
|
-
|
|
1776
|
-
let status = getTargetStatus(journal, selector);
|
|
1832
|
+
): Promise<void> => {
|
|
1833
|
+
const status = getTargetStatus(writer.current(), selector);
|
|
1777
1834
|
if (status.state === "conflict")
|
|
1778
1835
|
throw new Error("Gitea publication has a recorded destination conflict.");
|
|
1779
1836
|
const mark = async (
|
|
1780
1837
|
state: "verified" | "failed" | "conflict",
|
|
1781
1838
|
error: TReleaseErrorCode | null,
|
|
1782
1839
|
) => {
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
target
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1840
|
+
await writer.write(async (journal) => {
|
|
1841
|
+
const current = getTargetStatus(journal, selector);
|
|
1842
|
+
return updateTarget(
|
|
1843
|
+
options.store,
|
|
1844
|
+
journal,
|
|
1845
|
+
selector,
|
|
1846
|
+
current.state,
|
|
1847
|
+
current.attempt?.id || null,
|
|
1848
|
+
(target) => {
|
|
1849
|
+
target.state = state;
|
|
1850
|
+
target.error = error;
|
|
1851
|
+
target.attempt = null;
|
|
1852
|
+
if (state === "verified") onVerified?.(target);
|
|
1853
|
+
},
|
|
1854
|
+
);
|
|
1855
|
+
});
|
|
1797
1856
|
};
|
|
1798
1857
|
let present: boolean;
|
|
1799
1858
|
try {
|
|
@@ -1807,7 +1866,7 @@ const executeGiteaTarget = async (
|
|
|
1807
1866
|
}
|
|
1808
1867
|
if (present) {
|
|
1809
1868
|
if (status.state !== "verified") await mark("verified", null);
|
|
1810
|
-
return
|
|
1869
|
+
return;
|
|
1811
1870
|
}
|
|
1812
1871
|
if (status.state === "verified") {
|
|
1813
1872
|
await mark("conflict", "destination-conflict");
|
|
@@ -1816,15 +1875,19 @@ const executeGiteaTarget = async (
|
|
|
1816
1875
|
);
|
|
1817
1876
|
}
|
|
1818
1877
|
if (status.state === "publishing") {
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1878
|
+
await writer.write((journal) =>
|
|
1879
|
+
recoverPublishingTarget(
|
|
1880
|
+
options.store,
|
|
1881
|
+
journal,
|
|
1882
|
+
selector,
|
|
1883
|
+
options.recoveryAttemptId,
|
|
1884
|
+
),
|
|
1824
1885
|
);
|
|
1825
1886
|
}
|
|
1826
|
-
await options.ensurePublicationState(
|
|
1827
|
-
|
|
1887
|
+
await options.ensurePublicationState(writer.current().release.mainOid);
|
|
1888
|
+
await writer.write((journal) =>
|
|
1889
|
+
claimTarget(options.store, journal, selector),
|
|
1890
|
+
);
|
|
1828
1891
|
// One mutation per claimed attempt. Reconcile an accepted request even when
|
|
1829
1892
|
// its response was lost; never overwrite an attachment or recreate a tag.
|
|
1830
1893
|
let publicationError: unknown;
|
|
@@ -1846,7 +1909,7 @@ const executeGiteaTarget = async (
|
|
|
1846
1909
|
}
|
|
1847
1910
|
if (present) {
|
|
1848
1911
|
await mark("verified", null);
|
|
1849
|
-
return
|
|
1912
|
+
return;
|
|
1850
1913
|
}
|
|
1851
1914
|
await mark(
|
|
1852
1915
|
publicationError instanceof GiteaAssetConflictError ? "conflict" : "failed",
|
|
@@ -1862,15 +1925,92 @@ const executeGiteaTarget = async (
|
|
|
1862
1925
|
);
|
|
1863
1926
|
};
|
|
1864
1927
|
|
|
1928
|
+
/**
|
|
1929
|
+
* Runs `workArg` for every item with at most `concurrencyArg` at a time,
|
|
1930
|
+
* starting them in the items' order. After the first failure no further item starts; the ones
|
|
1931
|
+
* already running finish, because cutting a running transfer off would leave
|
|
1932
|
+
* its result inconclusive. Every failure is reported.
|
|
1933
|
+
*/
|
|
1934
|
+
export const runBoundedInOrder = async <T>(
|
|
1935
|
+
itemsArg: readonly T[],
|
|
1936
|
+
concurrencyArg: number,
|
|
1937
|
+
workArg: (itemArg: T) => Promise<void>,
|
|
1938
|
+
describeArg: (itemArg: T) => string,
|
|
1939
|
+
): Promise<void> => {
|
|
1940
|
+
const failures: { item: T; error: unknown }[] = [];
|
|
1941
|
+
let nextIndex = 0;
|
|
1942
|
+
const worker = async (): Promise<void> => {
|
|
1943
|
+
while (failures.length === 0 && nextIndex < itemsArg.length) {
|
|
1944
|
+
const item = itemsArg[nextIndex];
|
|
1945
|
+
nextIndex += 1;
|
|
1946
|
+
try {
|
|
1947
|
+
await workArg(item);
|
|
1948
|
+
} catch (error) {
|
|
1949
|
+
failures.push({ item, error });
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
};
|
|
1953
|
+
await Promise.all(
|
|
1954
|
+
Array.from(
|
|
1955
|
+
{ length: Math.max(1, Math.min(concurrencyArg, itemsArg.length)) },
|
|
1956
|
+
() => worker(),
|
|
1957
|
+
),
|
|
1958
|
+
);
|
|
1959
|
+
if (failures.length === 1) throw failures[0].error;
|
|
1960
|
+
if (failures.length > 1)
|
|
1961
|
+
throw new AggregateError(
|
|
1962
|
+
failures.map(({ error }) => error),
|
|
1963
|
+
`${failures.length} publications failed: ${failures
|
|
1964
|
+
.map(
|
|
1965
|
+
({ item, error }) =>
|
|
1966
|
+
`${describeArg(item)}: ${error instanceof Error ? error.message : String(error)}`,
|
|
1967
|
+
)
|
|
1968
|
+
.join("; ")}`,
|
|
1969
|
+
);
|
|
1970
|
+
};
|
|
1971
|
+
|
|
1972
|
+
/** Runs the tasks it is given one at a time, in the order they were given. */
|
|
1973
|
+
const createExclusiveSlot = (): (<T>(taskArg: () => Promise<T>) => Promise<T>) => {
|
|
1974
|
+
let tail: Promise<unknown> = Promise.resolve();
|
|
1975
|
+
return <T>(taskArg: () => Promise<T>): Promise<T> => {
|
|
1976
|
+
const run = tail.then(taskArg);
|
|
1977
|
+
tail = run.catch(() => undefined);
|
|
1978
|
+
return run;
|
|
1979
|
+
};
|
|
1980
|
+
};
|
|
1981
|
+
|
|
1982
|
+
const resolveGiteaAssetConcurrency = (valueArg: number | undefined): number => {
|
|
1983
|
+
const value = valueArg ?? defaultGiteaAssetConcurrency;
|
|
1984
|
+
if (
|
|
1985
|
+
!Number.isSafeInteger(value) ||
|
|
1986
|
+
value < 1 ||
|
|
1987
|
+
value > maximumGiteaAssetConcurrency
|
|
1988
|
+
)
|
|
1989
|
+
throw new Error(
|
|
1990
|
+
`Gitea asset concurrency must be a whole number between 1 and ${maximumGiteaAssetConcurrency}.`,
|
|
1991
|
+
);
|
|
1992
|
+
return value;
|
|
1993
|
+
};
|
|
1994
|
+
|
|
1865
1995
|
const executeGiteaAssets = async (
|
|
1866
1996
|
options: IReleasePublicationOptions,
|
|
1867
1997
|
journalArg: IReleaseJournalV4,
|
|
1868
1998
|
client: NonNullable<IReleasePublicationOptions["giteaAssets"]>,
|
|
1869
1999
|
): Promise<IReleaseJournalV4> => {
|
|
2000
|
+
const concurrency = resolveGiteaAssetConcurrency(
|
|
2001
|
+
options.giteaAssetConcurrency,
|
|
2002
|
+
);
|
|
2003
|
+
const writer = createReleaseJournalWriter(journalArg);
|
|
1870
2004
|
let releaseId = journalArg.giteaAssets.release.id;
|
|
1871
|
-
|
|
2005
|
+
const observed: {
|
|
2006
|
+
/** The release as Gitea last reported it; never the state this run intended. */
|
|
2007
|
+
release: IGiteaRelease | null;
|
|
2008
|
+
createdHere: boolean;
|
|
2009
|
+
} = { release: null, createdHere: false };
|
|
2010
|
+
printReleasePhase("Gitea release");
|
|
2011
|
+
await executeGiteaTarget(
|
|
1872
2012
|
options,
|
|
1873
|
-
|
|
2013
|
+
writer,
|
|
1874
2014
|
{ kind: "gitea-release" },
|
|
1875
2015
|
async () => {
|
|
1876
2016
|
const release = await client.inspectRelease();
|
|
@@ -1878,56 +2018,157 @@ const executeGiteaAssets = async (
|
|
|
1878
2018
|
if (releaseId !== null && release.id !== releaseId)
|
|
1879
2019
|
throw new GiteaAssetConflictError("Gitea release identity changed.");
|
|
1880
2020
|
releaseId = release.id;
|
|
2021
|
+
observed.release = release;
|
|
1881
2022
|
return true;
|
|
1882
2023
|
},
|
|
1883
2024
|
async () => {
|
|
1884
|
-
|
|
2025
|
+
observed.createdHere = true;
|
|
2026
|
+
await client.createRelease((elapsedMs) =>
|
|
2027
|
+
printReleasePhase(
|
|
2028
|
+
`Gitea release: waiting for Gitea to process the pushed tag ${journalArg.release.tag} (${formatReleaseDuration(elapsedMs)})`,
|
|
2029
|
+
),
|
|
2030
|
+
);
|
|
1885
2031
|
},
|
|
1886
2032
|
(target) => {
|
|
1887
|
-
(
|
|
2033
|
+
if ("id" in target) target.id = releaseId;
|
|
1888
2034
|
},
|
|
1889
|
-
)
|
|
1890
|
-
|
|
2035
|
+
);
|
|
2036
|
+
const verifiedReleaseId = releaseId;
|
|
2037
|
+
const release = observed.release;
|
|
2038
|
+
if (verifiedReleaseId === null || release === null)
|
|
1891
2039
|
throw new Error("Gitea release has no verified identity.");
|
|
2040
|
+
// The draft this run created must read back as a draft; Gitea refusing it
|
|
2041
|
+
// must not turn into a public upload.
|
|
2042
|
+
if (observed.createdHere && !release.draft)
|
|
2043
|
+
throw new GiteaReleaseStateChangedError(
|
|
2044
|
+
`Gitea release ${journalArg.release.tag} was created public instead of as a draft; no attachment was uploaded. A resume continues it as a published release, one attachment at a time in manifest order.`,
|
|
2045
|
+
);
|
|
2046
|
+
const releaseIsDraft = release.draft;
|
|
2047
|
+
const journal = requireGiteaJournal(writer.current());
|
|
1892
2048
|
const expected = journal.giteaAssets.assets.map((entry) => entry.asset);
|
|
1893
2049
|
const directory = options.store.getReleaseDirectory(journal.release.version);
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
2050
|
+
// Order and concurrency follow the state Gitea reported. A draft stays
|
|
2051
|
+
// invisible until every attachment verified, so no attachment is public
|
|
2052
|
+
// before the notices and sources beside it, and every upload first checks
|
|
2053
|
+
// that the release is still a draft. Pipelined (concurrency 2), the next
|
|
2054
|
+
// attachment uploads while the previous one is verified, largest first, so
|
|
2055
|
+
// the last verification is a short one; one at a time, attachments go in
|
|
2056
|
+
// manifest order. A published release (one an older gitzone created, or a
|
|
2057
|
+
// draft published before its set was complete) shows every attachment the
|
|
2058
|
+
// moment it lands, so its missing attachments upload one at a time in
|
|
2059
|
+
// manifest order, sources and notices first.
|
|
2060
|
+
const effectiveConcurrency = releaseIsDraft ? concurrency : 1;
|
|
2061
|
+
const order =
|
|
2062
|
+
effectiveConcurrency > 1
|
|
2063
|
+
? expected
|
|
2064
|
+
.map((asset, index) => ({ asset, index }))
|
|
2065
|
+
.sort((a, b) => b.asset.size - a.asset.size || a.index - b.index)
|
|
2066
|
+
.map(({ asset }) => asset)
|
|
2067
|
+
: expected;
|
|
2068
|
+
printReleasePhase(
|
|
2069
|
+
releaseIsDraft
|
|
2070
|
+
? effectiveConcurrency === 1
|
|
2071
|
+
? `Gitea assets: ${expected.length} attachments into the draft, one at a time in manifest order`
|
|
2072
|
+
: `Gitea assets: ${expected.length} attachments into the draft, largest first, each uploading while the previous one is verified`
|
|
2073
|
+
: `Gitea assets: ${expected.length} attachments into the already published release, one at a time in manifest order`,
|
|
2074
|
+
);
|
|
2075
|
+
// Two transfers in the same direction share the link and each takes longer
|
|
2076
|
+
// than alone, long enough for a large upload to outlast the reverse proxy in
|
|
2077
|
+
// front of Gitea (HTTP 504). So uploads never overlap and neither do
|
|
2078
|
+
// verification downloads, whatever the concurrency; only an upload and
|
|
2079
|
+
// another attachment's verification download may run at the same time.
|
|
2080
|
+
const uploadSlot = createExclusiveSlot();
|
|
2081
|
+
const downloadSlot = createExclusiveSlot();
|
|
2082
|
+
await runBoundedInOrder(
|
|
2083
|
+
order,
|
|
2084
|
+
effectiveConcurrency,
|
|
2085
|
+
async (asset: IGiteaFrozenAsset) => {
|
|
2086
|
+
let startedAt: number | undefined;
|
|
2087
|
+
await executeGiteaTarget(
|
|
2088
|
+
options,
|
|
2089
|
+
writer,
|
|
2090
|
+
{ kind: "gitea-asset", name: asset.name },
|
|
2091
|
+
async (verifyBytes) => {
|
|
2092
|
+
const inspection = await downloadSlot(() =>
|
|
2093
|
+
client.inspectAssets(
|
|
2094
|
+
verifiedReleaseId,
|
|
2095
|
+
expected,
|
|
2096
|
+
verifyBytes ? [asset] : [],
|
|
2097
|
+
),
|
|
2098
|
+
);
|
|
2099
|
+
return inspection.present.some((entry) => entry.name === asset.name);
|
|
2100
|
+
},
|
|
2101
|
+
async () => {
|
|
2102
|
+
await validateGiteaAssets(directory, [asset]);
|
|
2103
|
+
await uploadSlot(async () => {
|
|
2104
|
+
startedAt = Date.now();
|
|
2105
|
+
printReleasePhase(
|
|
2106
|
+
`Gitea asset ${asset.name}: uploading ${asset.size} bytes`,
|
|
2107
|
+
);
|
|
2108
|
+
await client.uploadAsset(
|
|
2109
|
+
verifiedReleaseId,
|
|
2110
|
+
asset,
|
|
2111
|
+
directory,
|
|
2112
|
+
releaseIsDraft,
|
|
2113
|
+
);
|
|
2114
|
+
});
|
|
2115
|
+
},
|
|
2116
|
+
);
|
|
2117
|
+
if (startedAt !== undefined)
|
|
2118
|
+
printReleasePhase(
|
|
2119
|
+
`Gitea asset ${asset.name}: uploaded, downloaded and hashed in ${formatReleaseDuration(Date.now() - startedAt)}`,
|
|
1904
2120
|
);
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
// Resume always repeats it, including an otherwise completed journal.
|
|
2121
|
+
},
|
|
2122
|
+
(asset) => `Gitea asset ${asset.name}`,
|
|
2123
|
+
);
|
|
2124
|
+
// One full verification of the set immediately before publishing it and
|
|
2125
|
+
// before npm: authenticated while the release is a draft, anonymous for a
|
|
2126
|
+
// published one. The client downloads again every attachment it did not
|
|
2127
|
+
// itself hash in this run, so a resume, even of a completed journal,
|
|
2128
|
+
// downloads them all.
|
|
2129
|
+
printReleasePhase("Gitea assets: verifying the complete attachment set");
|
|
1915
2130
|
try {
|
|
1916
|
-
await client.verifyComplete(
|
|
2131
|
+
await client.verifyComplete(verifiedReleaseId, expected);
|
|
2132
|
+
// Publish the draft only now. A release published by an older gitzone is
|
|
2133
|
+
// only verified. Setting `draft: false` is idempotent and observable, so
|
|
2134
|
+
// it needs no journal attempt: a resume after a crash finds the release
|
|
2135
|
+
// published, verifies it and continues.
|
|
2136
|
+
printReleasePhase(
|
|
2137
|
+
releaseIsDraft
|
|
2138
|
+
? "Gitea release: publishing the verified draft"
|
|
2139
|
+
: "Gitea release: verifying the already published release",
|
|
2140
|
+
);
|
|
2141
|
+
await client.publishRelease(verifiedReleaseId, expected, releaseIsDraft);
|
|
1917
2142
|
} catch (error) {
|
|
1918
2143
|
if (error instanceof GiteaAssetConflictError) {
|
|
1919
|
-
await
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
2144
|
+
await writer.write((current) =>
|
|
2145
|
+
markUnclaimedTarget(
|
|
2146
|
+
options.store,
|
|
2147
|
+
current,
|
|
2148
|
+
{ kind: "gitea-release" },
|
|
2149
|
+
["verified"],
|
|
2150
|
+
"conflict",
|
|
2151
|
+
"destination-conflict",
|
|
2152
|
+
),
|
|
1926
2153
|
);
|
|
1927
2154
|
}
|
|
1928
2155
|
throw error;
|
|
1929
2156
|
}
|
|
1930
|
-
|
|
2157
|
+
// Only now may a journal whose last target was a Gitea attachment record
|
|
2158
|
+
// its completion.
|
|
2159
|
+
const verified = writer.current();
|
|
2160
|
+
if (
|
|
2161
|
+
verified.completedAt === null &&
|
|
2162
|
+
finalizeJournalCompletion(verified).completedAt !== null
|
|
2163
|
+
)
|
|
2164
|
+
await writer.write((current) =>
|
|
2165
|
+
options.store.transact(
|
|
2166
|
+
current.release.version,
|
|
2167
|
+
current.revision,
|
|
2168
|
+
(latest) => finalizeJournalCompletion(latest),
|
|
2169
|
+
),
|
|
2170
|
+
);
|
|
2171
|
+
return requireGiteaJournal(writer.current());
|
|
1931
2172
|
};
|
|
1932
2173
|
|
|
1933
2174
|
export const executeReleasePublication = async (
|
|
@@ -1969,6 +2210,7 @@ export const executeReleasePublication = async (
|
|
|
1969
2210
|
await giteaClient.preflight();
|
|
1970
2211
|
}
|
|
1971
2212
|
if (journal.schemaVersion === 2) {
|
|
2213
|
+
printReleasePhase("Docker qualification");
|
|
1972
2214
|
journal = await executeDockerQualification(optionsArg, journal);
|
|
1973
2215
|
if (
|
|
1974
2216
|
journal.docker.cleanup.state === "publishing" ||
|
|
@@ -1977,6 +2219,7 @@ export const executeReleasePublication = async (
|
|
|
1977
2219
|
journal = await executeDockerCleanup(optionsArg, journal);
|
|
1978
2220
|
}
|
|
1979
2221
|
}
|
|
2222
|
+
printReleasePhase("Git target");
|
|
1980
2223
|
journal = await executeGitTarget(optionsArg, journal);
|
|
1981
2224
|
if (journal.schemaVersion === 4)
|
|
1982
2225
|
journal = await executeGiteaAssets(optionsArg, journal, giteaClient!);
|
|
@@ -1985,6 +2228,9 @@ export const executeReleasePublication = async (
|
|
|
1985
2228
|
? journal.release.mainOid
|
|
1986
2229
|
: journal.git.expectedRemoteMainOid || undefined;
|
|
1987
2230
|
for (const registry of journal.npm.registries) {
|
|
2231
|
+
printReleasePhase(
|
|
2232
|
+
`npm ${describeNpmTarget(registry.registry, registry.packageName)}`,
|
|
2233
|
+
);
|
|
1988
2234
|
await optionsArg.ensurePublicationState(expectedRemoteMainOid);
|
|
1989
2235
|
journal = await executeNpmRegistry(
|
|
1990
2236
|
optionsArg,
|
|
@@ -1999,6 +2245,9 @@ export const executeReleasePublication = async (
|
|
|
1999
2245
|
if (hasReleasePackages(journal)) {
|
|
2000
2246
|
for (const registry of journal.npm.registries) {
|
|
2001
2247
|
if (registry.state !== "accepted") continue;
|
|
2248
|
+
printReleasePhase(
|
|
2249
|
+
`npm availability of ${describeNpmTarget(registry.registry, registry.packageName)}`,
|
|
2250
|
+
);
|
|
2002
2251
|
await optionsArg.ensurePublicationState(expectedRemoteMainOid);
|
|
2003
2252
|
journal = await executeNpmRegistry(
|
|
2004
2253
|
optionsArg,
|
|
@@ -2028,12 +2277,14 @@ export const executeReleasePublication = async (
|
|
|
2028
2277
|
journal.docker.cleanup.state !== "verified"
|
|
2029
2278
|
) {
|
|
2030
2279
|
for (const promotion of journal.docker.promotions) {
|
|
2280
|
+
printReleasePhase(`Docker promotion ${promotion.promotionId}`);
|
|
2031
2281
|
journal = await executeDockerPromotion(
|
|
2032
2282
|
optionsArg,
|
|
2033
2283
|
journal,
|
|
2034
2284
|
promotion.promotionId,
|
|
2035
2285
|
);
|
|
2036
2286
|
}
|
|
2287
|
+
printReleasePhase("Docker cleanup");
|
|
2037
2288
|
journal = await executeDockerCleanup(optionsArg, journal);
|
|
2038
2289
|
}
|
|
2039
2290
|
return journal;
|