@git.zone/cli 7.2.5 → 7.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist_ts/00_commitinfo_data.js +1 -1
  2. package/dist_ts/helpers.workflow.d.ts +30 -1
  3. package/dist_ts/helpers.workflow.js +55 -3
  4. package/dist_ts/mod_config/index.js +23 -2
  5. package/dist_ts/mod_release/classes.releasejournal.d.ts +34 -0
  6. package/dist_ts/mod_release/classes.releasejournal.js +134 -2
  7. package/dist_ts/mod_release/helpers.giteaassets.d.ts +75 -3
  8. package/dist_ts/mod_release/helpers.giteaassets.js +303 -53
  9. package/dist_ts/mod_release/helpers.gitremote.d.ts +52 -0
  10. package/dist_ts/mod_release/helpers.gitremote.js +87 -0
  11. package/dist_ts/mod_release/helpers.releasebranch.d.ts +5 -0
  12. package/dist_ts/mod_release/helpers.releasebranch.js +39 -15
  13. package/dist_ts/mod_release/helpers.releasepreparation.js +18 -8
  14. package/dist_ts/mod_release/helpers.releasepublication.d.ts +6 -1
  15. package/dist_ts/mod_release/helpers.releasepublication.js +31 -21
  16. package/dist_ts/mod_release/index.js +216 -64
  17. package/dist_ts/mod_release/interfaces.giteaassets.d.ts +18 -3
  18. package/package.json +3 -3
  19. package/readme.md +106 -24
  20. package/ts/00_commitinfo_data.ts +1 -1
  21. package/ts/helpers.workflow.ts +123 -1
  22. package/ts/mod_config/index.ts +25 -0
  23. package/ts/mod_release/classes.releasejournal.ts +181 -1
  24. package/ts/mod_release/helpers.giteaassets.ts +438 -75
  25. package/ts/mod_release/helpers.gitremote.ts +147 -0
  26. package/ts/mod_release/helpers.releasebranch.ts +75 -30
  27. package/ts/mod_release/helpers.releasepreparation.ts +25 -7
  28. package/ts/mod_release/helpers.releasepublication.ts +45 -42
  29. package/ts/mod_release/index.ts +333 -85
  30. package/ts/mod_release/interfaces.giteaassets.ts +20 -2
@@ -1,7 +1,11 @@
1
1
  import * as plugins from "./mod.plugins.js";
2
2
  import { formatCommandFailure } from "./helpers.commandfailure.js";
3
3
  import { InterProcessLock } from "../mod_services/classes.interprocesslock.js";
4
- import { resolveGiteaAssetsConfiguration } from "../helpers.workflow.js";
4
+ import {
5
+ resolveGiteaAssetsConfiguration,
6
+ type TReleaseRecordedPlan,
7
+ type TReleaseTarget,
8
+ } from "../helpers.workflow.js";
5
9
  import {
6
10
  assertGiteaFrozenAssets,
7
11
  validateGiteaAssets,
@@ -33,6 +37,7 @@ export const legacyReleaseJournalSchemaVersion = 1 as const;
33
37
  export const releaseJournalSchemaVersion = 2 as const;
34
38
  export const releaseArtifactFileName = "package.tgz" as const;
35
39
  export const releaseJournalFileName = "journal.json" as const;
40
+ export const releaseIntentKind = "gitzone-release-intent" as const;
36
41
 
37
42
  /**
38
43
  * `accepted` records a destination that took the upload without rejecting it
@@ -1724,6 +1729,106 @@ const assertSchema4AppendOnlyTransition = (
1724
1729
  }
1725
1730
  };
1726
1731
 
1732
+ /** The Git destination state a recorded release leases when it publishes. */
1733
+ export interface IReleaseIntentGit {
1734
+ remote: string;
1735
+ destinationHash: string;
1736
+ expectedRemoteMainOid: string;
1737
+ }
1738
+
1739
+ /**
1740
+ * What a release settled before it prepared its journal: its local commit and
1741
+ * tag, the Git destination state it leases, and the command-line choices that
1742
+ * shaped it. It is recorded as soon as the tag exists, so a failure before the
1743
+ * journal is installed resumes from the release commit instead of stranding
1744
+ * it. The installed journal supersedes it.
1745
+ */
1746
+ export interface IReleaseIntent {
1747
+ kind: typeof releaseIntentKind;
1748
+ release: IReleaseIdentity;
1749
+ plan: TReleaseRecordedPlan;
1750
+ git: IReleaseIntentGit | null;
1751
+ createdAt: string;
1752
+ }
1753
+
1754
+ const releaseTargets: readonly TReleaseTarget[] = [
1755
+ "git",
1756
+ "giteaAssets",
1757
+ "npm",
1758
+ "docker",
1759
+ ];
1760
+
1761
+ const assertReleaseIntentPlan = (valueArg: unknown): TReleaseRecordedPlan => {
1762
+ if (!isPlainObject(valueArg)) {
1763
+ throw new Error("Release intent plan must be an object.");
1764
+ }
1765
+ assertExactKeys(valueArg, ["targets", "runBuild"], "Release intent plan");
1766
+ const targets = valueArg.targets;
1767
+ if (
1768
+ !Array.isArray(targets) ||
1769
+ typeof valueArg.runBuild !== "boolean" ||
1770
+ targets.some(
1771
+ (targetArg, indexArg) =>
1772
+ !releaseTargets.includes(targetArg) ||
1773
+ (indexArg > 0 &&
1774
+ releaseTargets.indexOf(targets[indexArg - 1]) >=
1775
+ releaseTargets.indexOf(targetArg)),
1776
+ )
1777
+ ) {
1778
+ throw new Error(
1779
+ "Release intent plan must name unique release targets in canonical order.",
1780
+ );
1781
+ }
1782
+ return valueArg as unknown as TReleaseRecordedPlan;
1783
+ };
1784
+
1785
+ const assertReleaseIntentGit = (valueArg: unknown): IReleaseIntentGit | null => {
1786
+ if (valueArg === null) return null;
1787
+ if (!isPlainObject(valueArg)) {
1788
+ throw new Error("Release intent Git destination must be an object or null.");
1789
+ }
1790
+ assertExactKeys(
1791
+ valueArg,
1792
+ ["remote", "destinationHash", "expectedRemoteMainOid"],
1793
+ "Release intent Git destination",
1794
+ );
1795
+ if (
1796
+ typeof valueArg.remote !== "string" ||
1797
+ normalizeReleaseGitRemoteName(valueArg.remote) !== valueArg.remote ||
1798
+ typeof valueArg.destinationHash !== "string" ||
1799
+ !sha256Regex.test(valueArg.destinationHash) ||
1800
+ typeof valueArg.expectedRemoteMainOid !== "string" ||
1801
+ !gitOidRegex.test(valueArg.expectedRemoteMainOid)
1802
+ ) {
1803
+ throw new Error("Release intent Git destination data is invalid.");
1804
+ }
1805
+ return valueArg as unknown as IReleaseIntentGit;
1806
+ };
1807
+
1808
+ export const assertReleaseIntent = (valueArg: unknown): IReleaseIntent => {
1809
+ if (!isPlainObject(valueArg)) {
1810
+ throw new Error("Release intent root must be a JSON object.");
1811
+ }
1812
+ assertExactKeys(
1813
+ valueArg,
1814
+ ["kind", "release", "plan", "git", "createdAt"],
1815
+ "Release intent",
1816
+ );
1817
+ if (valueArg.kind !== releaseIntentKind) {
1818
+ throw new Error("Release intent kind is invalid.");
1819
+ }
1820
+ assertReleaseIdentity(valueArg.release);
1821
+ const plan = assertReleaseIntentPlan(valueArg.plan);
1822
+ const git = assertReleaseIntentGit(valueArg.git);
1823
+ if (plan.targets.includes("git") !== (git !== null)) {
1824
+ throw new Error(
1825
+ "A release intent records a Git destination exactly when Git is a target.",
1826
+ );
1827
+ }
1828
+ assertIsoTimestamp(valueArg.createdAt, "Release intent createdAt");
1829
+ return valueArg as unknown as IReleaseIntent;
1830
+ };
1831
+
1727
1832
  export const createReleaseAttempt = (): IReleaseAttempt => ({
1728
1833
  id: plugins.crypto.randomBytes(16).toString("hex"),
1729
1834
  pid: process.pid,
@@ -1815,6 +1920,77 @@ export class ReleaseJournalStore {
1815
1920
  );
1816
1921
  }
1817
1922
 
1923
+ /** Beside the release directory, so installing the journal never meets it. */
1924
+ public getIntentPath(versionArg: string): string {
1925
+ return `${this.getReleaseDirectory(versionArg)}.intent.json`;
1926
+ }
1927
+
1928
+ public async hasJournal(versionArg: string): Promise<boolean> {
1929
+ try {
1930
+ await plugins.fs.lstat(this.getReleaseDirectory(versionArg));
1931
+ return true;
1932
+ } catch (error) {
1933
+ if ((error as NodeJS.ErrnoException).code === "ENOENT") return false;
1934
+ throw error;
1935
+ }
1936
+ }
1937
+
1938
+ /**
1939
+ * Records the intent atomically. A fresh release just created its tag, so
1940
+ * an intent left behind by an earlier, unwound attempt at this version no
1941
+ * longer names an existing tag and is replaced.
1942
+ */
1943
+ public async recordIntent(intentArg: IReleaseIntent): Promise<void> {
1944
+ const intent = assertReleaseIntent(intentArg);
1945
+ await plugins.fs.mkdir(this.rootPath, { recursive: true, mode: 0o700 });
1946
+ const intentPath = this.getIntentPath(intent.release.version);
1947
+ const temporaryPath = `${intentPath}.tmp-${process.pid}-${plugins.crypto.randomBytes(12).toString("hex")}`;
1948
+ try {
1949
+ const handle = await plugins.fs.open(temporaryPath, "wx", 0o600);
1950
+ try {
1951
+ await handle.writeFile(`${JSON.stringify(intent, null, 2)}\n`, "utf8");
1952
+ await handle.sync();
1953
+ } finally {
1954
+ await handle.close();
1955
+ }
1956
+ await plugins.fs.rename(temporaryPath, intentPath);
1957
+ await syncDirectory(this.rootPath);
1958
+ } catch (error) {
1959
+ await plugins.fs.rm(temporaryPath, { force: true });
1960
+ throw new Error(
1961
+ `Release intent v${intent.release.version} could not be recorded.`,
1962
+ { cause: error },
1963
+ );
1964
+ }
1965
+ }
1966
+
1967
+ /** The recorded intent of a release without an installed journal, if any. */
1968
+ public async readIntent(versionArg: string): Promise<IReleaseIntent | null> {
1969
+ const version = normalizeReleaseVersion(versionArg);
1970
+ let content: string;
1971
+ try {
1972
+ content = await plugins.fs.readFile(this.getIntentPath(version), "utf8");
1973
+ } catch (error) {
1974
+ if ((error as NodeJS.ErrnoException).code === "ENOENT") return null;
1975
+ throw new Error(`Release intent v${version} could not be read.`, {
1976
+ cause: error,
1977
+ });
1978
+ }
1979
+ let parsed: unknown;
1980
+ try {
1981
+ parsed = JSON.parse(content);
1982
+ } catch (error) {
1983
+ throw new Error(`Release intent v${version} is not valid JSON.`, {
1984
+ cause: error,
1985
+ });
1986
+ }
1987
+ const intent = assertReleaseIntent(parsed);
1988
+ if (intent.release.version !== version) {
1989
+ throw new Error("Release intent path and version do not match.");
1990
+ }
1991
+ return intent;
1992
+ }
1993
+
1818
1994
  public async read(versionArg: string): Promise<TReleaseJournal> {
1819
1995
  const version = normalizeReleaseVersion(versionArg);
1820
1996
  const filePath = plugins.path.join(
@@ -2014,6 +2190,10 @@ export class ReleaseJournalStore {
2014
2190
  }
2015
2191
  await syncDirectory(temporaryDirectory);
2016
2192
  await plugins.fs.rename(temporaryDirectory, releaseDirectory);
2193
+ // The journal now owns the release; its intent is superseded.
2194
+ await plugins.fs.rm(this.getIntentPath(journal.release.version), {
2195
+ force: true,
2196
+ });
2017
2197
  await syncDirectory(this.rootPath);
2018
2198
  return journal;
2019
2199
  });