@intentius/chant 0.124.100 → 0.124.101

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 (223) hide show
  1. package/dist/action-pins.d.ts +2 -0
  2. package/dist/action-pins.js +3 -0
  3. package/dist/ci-detect.d.ts +13 -0
  4. package/dist/ci-detect.js +12 -0
  5. package/dist/ci-system.d.ts +66 -0
  6. package/dist/ci-system.js +61 -0
  7. package/dist/cli/handlers/build.js +27 -0
  8. package/dist/cli/handlers/release-doctor.d.ts +12 -0
  9. package/dist/cli/handlers/release-doctor.js +118 -0
  10. package/dist/cli/handlers/release-init.d.ts +10 -0
  11. package/dist/cli/handlers/release-init.js +342 -0
  12. package/dist/cli/handlers/release.d.ts +42 -1
  13. package/dist/cli/handlers/release.js +656 -31
  14. package/dist/cli/handlers/run-generate.js +11 -0
  15. package/dist/cli/main.d.ts +2 -0
  16. package/dist/cli/main.js +44 -101
  17. package/dist/cli/parse-args.js +48 -0
  18. package/dist/cli/registry.d.ts +16 -0
  19. package/dist/cli/release-commands/artifacts.d.ts +3 -0
  20. package/dist/cli/release-commands/artifacts.js +14 -0
  21. package/dist/cli/release-commands/candidates.d.ts +3 -0
  22. package/dist/cli/release-commands/candidates.js +16 -0
  23. package/dist/cli/release-commands/changed.d.ts +3 -0
  24. package/dist/cli/release-commands/changed.js +14 -0
  25. package/dist/cli/release-commands/compose.d.ts +3 -0
  26. package/dist/cli/release-commands/compose.js +16 -0
  27. package/dist/cli/release-commands/cut.d.ts +3 -0
  28. package/dist/cli/release-commands/cut.js +49 -0
  29. package/dist/cli/release-commands/doctor.d.ts +3 -0
  30. package/dist/cli/release-commands/doctor.js +14 -0
  31. package/dist/cli/release-commands/export.d.ts +3 -0
  32. package/dist/cli/release-commands/export.js +12 -0
  33. package/dist/cli/release-commands/images.d.ts +3 -0
  34. package/dist/cli/release-commands/images.js +13 -0
  35. package/dist/cli/release-commands/index.d.ts +8 -0
  36. package/dist/cli/release-commands/index.js +52 -0
  37. package/dist/cli/release-commands/init.d.ts +3 -0
  38. package/dist/cli/release-commands/init.js +16 -0
  39. package/dist/cli/release-commands/list.d.ts +3 -0
  40. package/dist/cli/release-commands/list.js +10 -0
  41. package/dist/cli/release-commands/next.d.ts +3 -0
  42. package/dist/cli/release-commands/next.js +13 -0
  43. package/dist/cli/release-commands/publish.d.ts +3 -0
  44. package/dist/cli/release-commands/publish.js +22 -0
  45. package/dist/cli/release-commands/stamp.d.ts +3 -0
  46. package/dist/cli/release-commands/stamp.js +15 -0
  47. package/dist/cli/release-commands/status.d.ts +3 -0
  48. package/dist/cli/release-commands/status.js +17 -0
  49. package/dist/cli/release-commands/tag.d.ts +3 -0
  50. package/dist/cli/release-commands/tag.js +12 -0
  51. package/dist/cli/release-commands/types.d.ts +20 -0
  52. package/dist/cli/release-commands/types.js +1 -0
  53. package/dist/cli/release-commands/verify.d.ts +3 -0
  54. package/dist/cli/release-commands/verify.js +15 -0
  55. package/dist/cli/release-commands/workflow.d.ts +3 -0
  56. package/dist/cli/release-commands/workflow.js +13 -0
  57. package/dist/components/cli-support.d.ts +1 -1
  58. package/dist/components/cli-support.js +1 -1
  59. package/dist/config-environments.d.ts +8 -1
  60. package/dist/config-environments.js +2 -0
  61. package/dist/config.d.ts +294 -9
  62. package/dist/config.js +100 -5
  63. package/dist/floor-table.data.js +15 -1
  64. package/dist/forge-remote.d.ts +13 -0
  65. package/dist/forge-remote.js +15 -0
  66. package/dist/lexicon.d.ts +41 -2
  67. package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +62 -0
  68. package/dist/lifecycle/__fixtures__/publish-fakes.js +270 -3
  69. package/dist/lifecycle/publish-attachments.d.ts +2 -1
  70. package/dist/lifecycle/publish-attachments.js +19 -2
  71. package/dist/lifecycle/publish-cargo.d.ts +99 -0
  72. package/dist/lifecycle/publish-cargo.js +412 -0
  73. package/dist/lifecycle/publish-credentials.d.ts +1 -1
  74. package/dist/lifecycle/publish-credentials.js +8 -0
  75. package/dist/lifecycle/publish-declaration.d.ts +199 -4
  76. package/dist/lifecycle/publish-declaration.js +200 -9
  77. package/dist/lifecycle/publish-forge.d.ts +45 -2
  78. package/dist/lifecycle/publish-forge.js +434 -34
  79. package/dist/lifecycle/publish-git-ssh.d.ts +15 -0
  80. package/dist/lifecycle/publish-git-ssh.js +30 -4
  81. package/dist/lifecycle/publish-github.d.ts +40 -2
  82. package/dist/lifecycle/publish-github.js +100 -3
  83. package/dist/lifecycle/publish-homebrew.d.ts +7 -9
  84. package/dist/lifecycle/publish-homebrew.js +34 -197
  85. package/dist/lifecycle/publish-index.d.ts +141 -0
  86. package/dist/lifecycle/publish-index.js +719 -0
  87. package/dist/lifecycle/publish-marketplace.js +77 -0
  88. package/dist/lifecycle/publish-mcp-registry.d.ts +66 -0
  89. package/dist/lifecycle/publish-mcp-registry.js +306 -0
  90. package/dist/lifecycle/publish-npm.js +165 -2
  91. package/dist/lifecycle/publish-oci.d.ts +34 -1
  92. package/dist/lifecycle/publish-oci.js +246 -7
  93. package/dist/lifecycle/publish-pypi.d.ts +136 -0
  94. package/dist/lifecycle/publish-pypi.js +657 -0
  95. package/dist/lifecycle/publish-record.d.ts +6 -3
  96. package/dist/lifecycle/publish-record.js +6 -3
  97. package/dist/lifecycle/publish-signing.d.ts +147 -0
  98. package/dist/lifecycle/publish-signing.js +257 -0
  99. package/dist/lifecycle/publish-targets.d.ts +27 -1
  100. package/dist/lifecycle/publish-targets.js +80 -0
  101. package/dist/lifecycle/publish-tauri.js +43 -0
  102. package/dist/lifecycle/publish-train-names.d.ts +54 -0
  103. package/dist/lifecycle/publish-train-names.js +118 -0
  104. package/dist/lifecycle/publish-verify.d.ts +121 -0
  105. package/dist/lifecycle/publish-verify.js +130 -0
  106. package/dist/lifecycle/query.js +8 -0
  107. package/dist/lifecycle/release-artifacts.d.ts +212 -0
  108. package/dist/lifecycle/release-artifacts.js +571 -0
  109. package/dist/lifecycle/release-changelog.d.ts +13 -1
  110. package/dist/lifecycle/release-changelog.js +35 -2
  111. package/dist/lifecycle/release-cut.d.ts +58 -3
  112. package/dist/lifecycle/release-cut.js +132 -34
  113. package/dist/lifecycle/release-doctor.d.ts +113 -0
  114. package/dist/lifecycle/release-doctor.js +996 -0
  115. package/dist/lifecycle/release-green.d.ts +86 -0
  116. package/dist/lifecycle/release-green.js +286 -0
  117. package/dist/lifecycle/release-init.d.ts +255 -0
  118. package/dist/lifecycle/release-init.js +859 -0
  119. package/dist/lifecycle/release-intents.d.ts +73 -0
  120. package/dist/lifecycle/release-intents.js +128 -0
  121. package/dist/lifecycle/release-next.d.ts +111 -0
  122. package/dist/lifecycle/release-next.js +252 -0
  123. package/dist/lifecycle/release-prerelease.d.ts +19 -0
  124. package/dist/lifecycle/release-prerelease.js +30 -0
  125. package/dist/lifecycle/release-publish.d.ts +256 -10
  126. package/dist/lifecycle/release-publish.js +246 -34
  127. package/dist/lifecycle/release-status-change.d.ts +226 -0
  128. package/dist/lifecycle/release-status-change.js +478 -0
  129. package/dist/lifecycle/release-status.d.ts +11 -0
  130. package/dist/lifecycle/release-status.js +1 -1
  131. package/dist/lifecycle/release-store.d.ts +73 -2
  132. package/dist/lifecycle/release-store.js +32 -1
  133. package/dist/lifecycle/release-tag.d.ts +142 -0
  134. package/dist/lifecycle/release-tag.js +323 -0
  135. package/dist/lifecycle/release-verify.d.ts +73 -1
  136. package/dist/lifecycle/release-verify.js +117 -2
  137. package/dist/lifecycle/release-version-formats.d.ts +73 -0
  138. package/dist/lifecycle/release-version-formats.js +570 -0
  139. package/dist/lifecycle/release-version.d.ts +58 -10
  140. package/dist/lifecycle/release-version.js +164 -36
  141. package/dist/lifecycle/release-workstation.d.ts +3 -2
  142. package/dist/lifecycle/release-workstation.js +3 -2
  143. package/dist/op/generate-pipeline.js +1 -1
  144. package/dist/pr-forge-base.js +4 -2
  145. package/dist/pr-forge.d.ts +20 -2
  146. package/dist/pr-forge.js +46 -10
  147. package/dist/release-floors.d.ts +8 -1
  148. package/dist/release-floors.js +9 -2
  149. package/dist/tool-pins.d.ts +38 -0
  150. package/dist/tool-pins.js +54 -0
  151. package/dist/wave-runtime.mjs +337 -334
  152. package/dist/workspace/ci-forge.d.ts +17 -0
  153. package/dist/workspace/ci-forge.js +17 -0
  154. package/dist/workspace/ci-init.js +1 -1
  155. package/dist/workspace/composites.schema.json +1 -0
  156. package/dist/workspace/declaration.d.ts +8 -0
  157. package/dist/workspace/declaration.js +12 -0
  158. package/dist/workspace/declaration.schema.json +8 -0
  159. package/dist/workspace/environments.d.ts +2 -0
  160. package/dist/workspace/environments.js +1 -1
  161. package/dist/workspace/identity-gate-rule.d.ts +61 -5
  162. package/dist/workspace/identity-gate-rule.js +81 -12
  163. package/dist/workspace/member-pipeline.d.ts +2 -1
  164. package/dist/workspace/member-pipeline.js +5 -2
  165. package/dist/workspace/reason-codes.d.ts +2 -0
  166. package/dist/workspace/reason-codes.js +3 -1
  167. package/dist/workspace/release-changed.d.ts +75 -4
  168. package/dist/workspace/release-changed.js +205 -34
  169. package/dist/workspace/release-changed.schema.json +20 -2
  170. package/dist/workspace/release-steps/artifacts.d.ts +7 -0
  171. package/dist/workspace/release-steps/artifacts.js +45 -0
  172. package/dist/workspace/release-steps/builds.d.ts +12 -0
  173. package/dist/workspace/release-steps/builds.js +38 -0
  174. package/dist/workspace/release-steps/doctor.d.ts +8 -0
  175. package/dist/workspace/release-steps/doctor.js +14 -0
  176. package/dist/workspace/release-steps/goreleaser.d.ts +16 -0
  177. package/dist/workspace/release-steps/goreleaser.js +36 -0
  178. package/dist/workspace/release-steps/green.d.ts +3 -0
  179. package/dist/workspace/release-steps/green.js +6 -0
  180. package/dist/workspace/release-steps/images.d.ts +22 -0
  181. package/dist/workspace/release-steps/images.js +59 -0
  182. package/dist/workspace/release-steps/index.d.ts +9 -0
  183. package/dist/workspace/release-steps/index.js +46 -0
  184. package/dist/workspace/release-steps/pypi.d.ts +15 -0
  185. package/dist/workspace/release-steps/pypi.js +21 -0
  186. package/dist/workspace/release-steps/qemu.d.ts +21 -0
  187. package/dist/workspace/release-steps/qemu.js +35 -0
  188. package/dist/workspace/release-steps/signing.d.ts +18 -0
  189. package/dist/workspace/release-steps/signing.js +30 -0
  190. package/dist/workspace/release-steps/stamp.d.ts +3 -0
  191. package/dist/workspace/release-steps/stamp.js +4 -0
  192. package/dist/workspace/release-steps/targets.d.ts +31 -0
  193. package/dist/workspace/release-steps/targets.js +40 -0
  194. package/dist/workspace/release-steps/types.d.ts +104 -0
  195. package/dist/workspace/release-steps/types.js +2 -0
  196. package/dist/workspace/release-steps/verify.d.ts +3 -0
  197. package/dist/workspace/release-steps/verify.js +4 -0
  198. package/dist/workspace/release-toolchains.d.ts +59 -0
  199. package/dist/workspace/release-toolchains.js +133 -0
  200. package/dist/workspace/release-train-workflow.d.ts +29 -0
  201. package/dist/workspace/release-train-workflow.js +85 -0
  202. package/dist/workspace/release-train.d.ts +3 -1
  203. package/dist/workspace/release-train.js +20 -3
  204. package/dist/workspace/release-workflow.d.ts +160 -61
  205. package/dist/workspace/release-workflow.js +539 -193
  206. package/dist/workspace/releases.schema.json +70 -1
  207. package/dist/workspace/search-contract.d.ts +1 -1
  208. package/dist/workspace/security.js +9 -2
  209. package/dist/workspace/train-cut.d.ts +182 -0
  210. package/dist/workspace/train-cut.js +482 -0
  211. package/dist/workspace/train-prepare.d.ts +61 -0
  212. package/dist/workspace/train-prepare.js +267 -0
  213. package/dist/workspace/train-publish.d.ts +177 -0
  214. package/dist/workspace/train-publish.js +575 -0
  215. package/dist/workspace/train-range-labels.d.ts +33 -0
  216. package/dist/workspace/train-range-labels.js +109 -0
  217. package/dist/workspace/trust/seal.d.ts +13 -3
  218. package/dist/workspace/trust/seal.js +14 -4
  219. package/dist/workspace/work-cli.d.ts +3 -2
  220. package/dist/workspace/work-cli.js +3 -2
  221. package/dist/workspace/workspace-ledger.d.ts +14 -1
  222. package/dist/workspace/workspace-ledger.js +33 -7
  223. package/package.json +1 -1
@@ -0,0 +1,86 @@
1
+ /**
2
+ * The green gate of a release cut (#5149): what says a commit may be
3
+ * released, set by `release.green` in the member's `chant.config.ts`.
4
+ *
5
+ * - `chant`: the commit carries a `ci/green/<sha>` tag and no
6
+ * `ci/revoked/<sha>` tag, as `chant ci` writes them from `ci.green`
7
+ * (./release-cut.ts). The default when `chant.workspace.json` declares
8
+ * `ci.green` or the repository holds any `ci/green/` tag.
9
+ * - `forge-checks`: the forge's checks on the commit passed. GitHub: every
10
+ * check run and commit status, and each check a branch rule of the
11
+ * branch requires. Forgejo: every commit status, and each context its
12
+ * branch protection requires when the token can read it. GitLab: the
13
+ * newest pipeline of each source on the commit. A check that failed or has
14
+ * not finished refuses the cut, and so does a commit with no check at all.
15
+ * The release workflow's own runs on the commit are left out (GitHub:
16
+ * every run of the workflow file the cut runs in; Forgejo: the cut's run;
17
+ * GitLab: pipelines started the way the cut's was, from the web or the
18
+ * API). The default otherwise.
19
+ * - `none`: no gate. The cut prints a warning and records that it had none.
20
+ * Refused under the `supply-chain` or `verified-releases` security groups
21
+ * and under a `release` gate in `identity.gates`.
22
+ *
23
+ * The cut records the gate it passed on its cut line (`green`): the tag, the
24
+ * forge and the names of the checks, or `none`. `chant release verify` shows
25
+ * it and the publish's provenance statement carries it.
26
+ *
27
+ * The forge is the CI job's when the cut runs in one (`GITHUB_REPOSITORY`,
28
+ * `CI_PROJECT_ID`, ...), and otherwise the one the checkout's `origin`
29
+ * remote names. The token is read in the order every chant forge client
30
+ * reads it (`FORGE_TOKEN_ORDER`): `CHANT_GITHUB_TOKEN`, `GH_TOKEN`,
31
+ * `GITHUB_TOKEN` on GitHub, and the like on Forgejo and GitLab.
32
+ */
33
+ import type { ForgeFetch, ForgeKind, ForgeTarget } from "../pr-forge.js";
34
+ /** `release.green`. */
35
+ export declare const RELEASE_GREEN_SOURCES: readonly ["chant", "forge-checks", "none"];
36
+ export type ReleaseGreenSource = (typeof RELEASE_GREEN_SOURCES)[number];
37
+ /**
38
+ * The gate a cut checks: `release.green`, else `chant` when the workspace
39
+ * declares `ci.green` or the repository holds `ci/green/` tags (a project
40
+ * that writes them some other way, as before #5149), else `forge-checks`.
41
+ */
42
+ export declare function resolveGreenSource(declared: ReleaseGreenSource | undefined, hasCiGreen: boolean, hasGreenTags?: boolean): ReleaseGreenSource;
43
+ /** One check the forge reports on a commit. */
44
+ export interface ForgeCheck {
45
+ name: string;
46
+ state: "success" | "pending" | "failure";
47
+ /** The forge's own word for it, for a message. */
48
+ status: string;
49
+ url?: string;
50
+ }
51
+ /** What the forge says of a commit's checks. */
52
+ export type ForgeChecksVerdict = {
53
+ green: true;
54
+ forge: ForgeKind;
55
+ checks: string[];
56
+ } | {
57
+ green: false;
58
+ forge: ForgeKind;
59
+ why: string;
60
+ checks: ForgeCheck[];
61
+ };
62
+ /** The forge could not be asked: none is known, a token is missing, or the forge answered with an error. */
63
+ export declare class ForgeChecksUnavailableError extends Error {
64
+ readonly fix?: string | undefined;
65
+ constructor(message: string, fix?: string | undefined);
66
+ }
67
+ /** Reads a commit's checks; a test hands in a fake. */
68
+ export type ForgeChecksReader = (commit: string, branch: string | null) => Promise<ForgeChecksVerdict>;
69
+ /** A check's state from the forge's status and, once completed, conclusion. */
70
+ export declare function checkState(status: string, conclusion?: string | null): ForgeCheck["state"];
71
+ /**
72
+ * The verdict on `checks`: green when there is at least one, each passed,
73
+ * and each of `required` is among them.
74
+ */
75
+ export declare function judgeChecks(forge: ForgeKind, checks: ForgeCheck[], required: readonly string[]): ForgeChecksVerdict;
76
+ /**
77
+ * A reader of the commit checks of the forge `target` names, with `env`
78
+ * naming the run the cut runs in, whose own checks are left out.
79
+ */
80
+ export declare function forgeChecksReader(target: ForgeTarget, env?: Record<string, string | undefined>, fetchImpl?: ForgeFetch): ForgeChecksReader;
81
+ /**
82
+ * The forge a cut in `cwd` asks: the CI job's, read from `env`, or the one
83
+ * the checkout's `origin` remote names, with the token from `env`. Throws
84
+ * {@link ForgeChecksUnavailableError} naming what is missing.
85
+ */
86
+ export declare function forgeChecksTarget(cwd: string, env?: Record<string, string | undefined>): Promise<ForgeTarget>;
@@ -0,0 +1,286 @@
1
+ /**
2
+ * The green gate of a release cut (#5149): what says a commit may be
3
+ * released, set by `release.green` in the member's `chant.config.ts`.
4
+ *
5
+ * - `chant`: the commit carries a `ci/green/<sha>` tag and no
6
+ * `ci/revoked/<sha>` tag, as `chant ci` writes them from `ci.green`
7
+ * (./release-cut.ts). The default when `chant.workspace.json` declares
8
+ * `ci.green` or the repository holds any `ci/green/` tag.
9
+ * - `forge-checks`: the forge's checks on the commit passed. GitHub: every
10
+ * check run and commit status, and each check a branch rule of the
11
+ * branch requires. Forgejo: every commit status, and each context its
12
+ * branch protection requires when the token can read it. GitLab: the
13
+ * newest pipeline of each source on the commit. A check that failed or has
14
+ * not finished refuses the cut, and so does a commit with no check at all.
15
+ * The release workflow's own runs on the commit are left out (GitHub:
16
+ * every run of the workflow file the cut runs in; Forgejo: the cut's run;
17
+ * GitLab: pipelines started the way the cut's was, from the web or the
18
+ * API). The default otherwise.
19
+ * - `none`: no gate. The cut prints a warning and records that it had none.
20
+ * Refused under the `supply-chain` or `verified-releases` security groups
21
+ * and under a `release` gate in `identity.gates`.
22
+ *
23
+ * The cut records the gate it passed on its cut line (`green`): the tag, the
24
+ * forge and the names of the checks, or `none`. `chant release verify` shows
25
+ * it and the publish's provenance statement carries it.
26
+ *
27
+ * The forge is the CI job's when the cut runs in one (`GITHUB_REPOSITORY`,
28
+ * `CI_PROJECT_ID`, ...), and otherwise the one the checkout's `origin`
29
+ * remote names. The token is read in the order every chant forge client
30
+ * reads it (`FORGE_TOKEN_ORDER`): `CHANT_GITHUB_TOKEN`, `GH_TOKEN`,
31
+ * `GITHUB_TOKEN` on GitHub, and the like on Forgejo and GitLab.
32
+ */
33
+ /** `release.green`. */
34
+ export const RELEASE_GREEN_SOURCES = ["chant", "forge-checks", "none"];
35
+ /**
36
+ * The gate a cut checks: `release.green`, else `chant` when the workspace
37
+ * declares `ci.green` or the repository holds `ci/green/` tags (a project
38
+ * that writes them some other way, as before #5149), else `forge-checks`.
39
+ */
40
+ export function resolveGreenSource(declared, hasCiGreen, hasGreenTags = false) {
41
+ return declared ?? (hasCiGreen || hasGreenTags ? "chant" : "forge-checks");
42
+ }
43
+ /** The forge could not be asked: none is known, a token is missing, or the forge answered with an error. */
44
+ export class ForgeChecksUnavailableError extends Error {
45
+ constructor(message, fix) {
46
+ super(message);
47
+ this.fix = fix;
48
+ this.name = "ForgeChecksUnavailableError";
49
+ }
50
+ }
51
+ const PENDING = new Set(["queued", "in_progress", "waiting", "requested", "pending", "running", "created", "preparing", "waiting_for_resource", "scheduled", "manual"]);
52
+ const PASSED = new Set(["success", "neutral", "skipped", "warning"]);
53
+ /** A check's state from the forge's status and, once completed, conclusion. */
54
+ export function checkState(status, conclusion) {
55
+ const s = status.toLowerCase();
56
+ if (PENDING.has(s))
57
+ return "pending";
58
+ const word = (s === "completed" ? (conclusion ?? "") : s).toLowerCase();
59
+ return PASSED.has(word) ? "success" : "failure";
60
+ }
61
+ /**
62
+ * The verdict on `checks`: green when there is at least one, each passed,
63
+ * and each of `required` is among them.
64
+ */
65
+ export function judgeChecks(forge, checks, required) {
66
+ const names = new Set(checks.map((c) => c.name));
67
+ const missing = required.filter((r) => !names.has(r));
68
+ const failed = checks.filter((c) => c.state === "failure");
69
+ const pending = checks.filter((c) => c.state === "pending");
70
+ const list = (cs) => cs.map((c) => `${c.name} (${c.status})`).join(", ");
71
+ if (checks.length === 0)
72
+ return { green: false, forge, checks, why: `${forge} reports no check on it` };
73
+ if (failed.length > 0)
74
+ return { green: false, forge, checks, why: `${failed.length === 1 ? "a check" : `${failed.length} checks`} did not pass on ${forge}: ${list(failed)}` };
75
+ if (pending.length > 0)
76
+ return { green: false, forge, checks, why: `${pending.length === 1 ? "a check has" : `${pending.length} checks have`} not finished on ${forge}: ${list(pending)}` };
77
+ if (missing.length > 0)
78
+ return { green: false, forge, checks, why: `the branch requires ${missing.join(", ")}, which ${forge} does not report on it` };
79
+ return { green: true, forge, checks: [...names].sort() };
80
+ }
81
+ const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
82
+ const str = (v) => (typeof v === "string" ? v : undefined);
83
+ /** Whether `url` is a page of one of the CI runs `runIds` (`.../actions/runs/<id>` or `.../actions/runs/<id>/...`). */
84
+ function inRun(url, runIds) {
85
+ if (!url || !runIds)
86
+ return false;
87
+ const m = /\/actions\/runs\/([0-9A-Za-z]+)(?:\/|$)/.exec(url);
88
+ if (!m)
89
+ return false;
90
+ return typeof runIds === "string" ? m[1] === runIds : runIds.has(m[1]);
91
+ }
92
+ /**
93
+ * A reader of the commit checks of the forge `target` names, with `env`
94
+ * naming the run the cut runs in, whose own checks are left out.
95
+ */
96
+ export function forgeChecksReader(target, env = process.env, fetchImpl) {
97
+ const doFetch = fetchImpl ?? globalThis.fetch;
98
+ const api = target.apiBase.replace(/\/+$/, "");
99
+ const headers = target.kind === "gitlab"
100
+ ? { [target.tokenHeader ?? "PRIVATE-TOKEN"]: target.token, Accept: "application/json" }
101
+ : target.kind === "github"
102
+ ? { Authorization: `Bearer ${target.token}`, Accept: "application/vnd.github+json" }
103
+ : { Authorization: `token ${target.token}`, Accept: "application/json" };
104
+ /** GET a JSON document; `optional` answers undefined for a refusal or a missing resource rather than throwing. */
105
+ const get = async (path, optional = false) => {
106
+ const url = `${api}${path}`;
107
+ let res;
108
+ try {
109
+ res = await doFetch(url, { method: "GET", headers });
110
+ }
111
+ catch (err) {
112
+ throw new ForgeChecksUnavailableError(`${target.kind} could not be reached at ${api}: ${err instanceof Error ? err.message : String(err)}`);
113
+ }
114
+ if (!res.ok) {
115
+ if (optional && [401, 403, 404].includes(res.status))
116
+ return undefined;
117
+ throw new ForgeChecksUnavailableError(`${target.kind} answered ${res.status} to GET ${path}`, res.status === 401 || res.status === 403 || res.status === 404
118
+ ? `The token from ${target.tokenSource} must read the repository's checks and statuses (GitHub: checks: read and statuses: read).`
119
+ : undefined);
120
+ }
121
+ try {
122
+ return JSON.parse(await res.text());
123
+ }
124
+ catch {
125
+ throw new ForgeChecksUnavailableError(`${target.kind} answered GET ${path} with something that is not JSON`);
126
+ }
127
+ };
128
+ if (target.kind === "github") {
129
+ const repo = `/repos/${target.repo}`;
130
+ // The release workflow's own runs on the commit, this one and any earlier attempt, are not checks of it.
131
+ const workflowPath = env.GITHUB_WORKFLOW_REF ? /^[^/]+\/[^/]+\/(.+?)@/.exec(env.GITHUB_WORKFLOW_REF)?.[1] : undefined;
132
+ return async (sha, branch) => {
133
+ const runId = new Set(env.GITHUB_RUN_ID ? [env.GITHUB_RUN_ID] : []);
134
+ if (workflowPath) {
135
+ const runs = await get(`${repo}/actions/runs?head_sha=${sha}&per_page=100`, true);
136
+ for (const r of isObject(runs) && Array.isArray(runs.workflow_runs) ? runs.workflow_runs.filter(isObject) : []) {
137
+ if (str(r.path) === workflowPath && r.id !== undefined)
138
+ runId.add(String(r.id));
139
+ }
140
+ }
141
+ const checks = [];
142
+ for (let page = 1; page <= 20; page++) {
143
+ const got = await get(`${repo}/commits/${sha}/check-runs?per_page=100&page=${page}`);
144
+ const runs = isObject(got) && Array.isArray(got.check_runs) ? got.check_runs.filter(isObject) : [];
145
+ for (const r of runs) {
146
+ const name = str(r.name);
147
+ const url = str(r.details_url) ?? str(r.html_url);
148
+ if (!name || inRun(url, runId))
149
+ continue;
150
+ const status = str(r.status) ?? "unknown";
151
+ const conclusion = str(r.conclusion) ?? null;
152
+ checks.push({ name, state: checkState(status, conclusion), status: status === "completed" ? (conclusion ?? status) : status, ...(url ? { url } : {}) });
153
+ }
154
+ if (runs.length < 100)
155
+ break;
156
+ }
157
+ const combined = await get(`${repo}/commits/${sha}/status?per_page=100`);
158
+ for (const s of isObject(combined) && Array.isArray(combined.statuses) ? combined.statuses.filter(isObject) : []) {
159
+ const name = str(s.context);
160
+ const url = str(s.target_url);
161
+ if (!name || inRun(url, runId))
162
+ continue;
163
+ const state = str(s.state) ?? "unknown";
164
+ checks.push({ name, state: state === "error" ? "failure" : checkState(state), status: state, ...(url ? { url } : {}) });
165
+ }
166
+ const required = [];
167
+ if (branch) {
168
+ const rules = await get(`${repo}/rules/branches/${encodeURIComponent(branch)}`, true);
169
+ for (const rule of Array.isArray(rules) ? rules.filter(isObject) : []) {
170
+ if (rule.type !== "required_status_checks" || !isObject(rule.parameters))
171
+ continue;
172
+ const list = rule.parameters.required_status_checks;
173
+ for (const c of Array.isArray(list) ? list.filter(isObject) : []) {
174
+ const ctx = str(c.context);
175
+ if (ctx && !required.includes(ctx))
176
+ required.push(ctx);
177
+ }
178
+ }
179
+ }
180
+ return judgeChecks("github", newestByName(checks), required);
181
+ };
182
+ }
183
+ if (target.kind === "forgejo") {
184
+ const runNumber = env.FORGEJO_RUN_NUMBER ?? env.GITHUB_RUN_NUMBER;
185
+ const repo = `/repos/${target.repo}`;
186
+ return async (sha, branch) => {
187
+ const combined = await get(`${repo}/commits/${sha}/status?limit=100`);
188
+ const checks = [];
189
+ for (const s of isObject(combined) && Array.isArray(combined.statuses) ? combined.statuses.filter(isObject) : []) {
190
+ const name = str(s.context);
191
+ const url = str(s.target_url);
192
+ if (!name || inRun(url, runNumber))
193
+ continue;
194
+ const state = str(s.status) ?? str(s.state) ?? "unknown";
195
+ checks.push({ name, state: state === "error" ? "failure" : checkState(state), status: state, ...(url ? { url } : {}) });
196
+ }
197
+ const required = [];
198
+ if (branch) {
199
+ const protections = await get(`${repo}/branch_protections`, true);
200
+ for (const p of Array.isArray(protections) ? protections.filter(isObject) : []) {
201
+ const names = [str(p.rule_name), str(p.branch_name)];
202
+ if (!names.includes(branch) || p.enable_status_check !== true)
203
+ continue;
204
+ for (const ctx of Array.isArray(p.status_check_contexts) ? p.status_check_contexts : [])
205
+ if (typeof ctx === "string" && !required.includes(ctx))
206
+ required.push(ctx);
207
+ }
208
+ }
209
+ return judgeChecks("forgejo", newestByName(checks), required);
210
+ };
211
+ }
212
+ const pipelineId = env.CI_PIPELINE_ID;
213
+ // A release started from "Run pipeline" or the API is such a pipeline itself, as are earlier attempts of it.
214
+ const ownSource = ["web", "api", "trigger"].includes(env.CI_PIPELINE_SOURCE ?? "") ? env.CI_PIPELINE_SOURCE : undefined;
215
+ const project = `/projects/${encodeURIComponent(target.repo)}`;
216
+ return async (sha) => {
217
+ const got = await get(`${project}/pipelines?sha=${encodeURIComponent(sha)}&per_page=100&order_by=id&sort=desc`);
218
+ const checks = [];
219
+ const seen = new Set();
220
+ for (const p of Array.isArray(got) ? got.filter(isObject) : []) {
221
+ const id = p.id;
222
+ if (id === undefined || String(id) === pipelineId || (ownSource !== undefined && p.source === ownSource))
223
+ continue;
224
+ // The newest pipeline of each source (push, merge_request_event, schedule, ...) speaks for it.
225
+ const name = `pipeline (${str(p.source) ?? "unknown"})`;
226
+ if (seen.has(name))
227
+ continue;
228
+ seen.add(name);
229
+ const status = str(p.status) ?? "unknown";
230
+ const url = str(p.web_url);
231
+ checks.push({ name, state: status === "canceled" ? "failure" : checkState(status), status, ...(url ? { url } : {}) });
232
+ }
233
+ return judgeChecks("gitlab", checks, []);
234
+ };
235
+ }
236
+ /** Each check name once, at the worst state any entry of that name has, so a check run and a status of the same name can't hide a failure. */
237
+ function newestByName(checks) {
238
+ const rank = { failure: 2, pending: 1, success: 0 };
239
+ const out = new Map();
240
+ for (const c of checks) {
241
+ const had = out.get(c.name);
242
+ if (!had || rank[c.state] > rank[had.state])
243
+ out.set(c.name, c);
244
+ }
245
+ return [...out.values()].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
246
+ }
247
+ /**
248
+ * The forge a cut in `cwd` asks: the CI job's, read from `env`, or the one
249
+ * the checkout's `origin` remote names, with the token from `env`. Throws
250
+ * {@link ForgeChecksUnavailableError} naming what is missing.
251
+ */
252
+ export async function forgeChecksTarget(cwd, env = process.env) {
253
+ const { detectForge, forgeTargetFromEnv, ForgeEnvironmentError, FORGE_TOKEN_ORDER } = await import("../pr-forge.js");
254
+ const inCi = detectForge(env);
255
+ if (inCi) {
256
+ try {
257
+ return forgeTargetFromEnv(env, { kind: inCi });
258
+ }
259
+ catch (err) {
260
+ if (err instanceof ForgeEnvironmentError) {
261
+ throw new ForgeChecksUnavailableError(`release.green is forge-checks, and this ${inCi} job can't ask ${inCi} for the commit's checks: it needs ${err.missing.join(", ")}`, inCi === "github" ? "Give the job its token (env GITHUB_TOKEN: ${{ github.token }}) with checks: read and statuses: read." : `Set ${FORGE_TOKEN_ORDER[inCi][0]} to a token that reads the repository's pipelines and statuses.`);
262
+ }
263
+ throw err;
264
+ }
265
+ }
266
+ const { forgeOfCheckout } = await import("../forge-remote.js");
267
+ const remote = forgeOfCheckout(cwd);
268
+ if (!remote) {
269
+ throw new ForgeChecksUnavailableError("release.green is forge-checks, and the origin remote names no forge chant reads checks from (GitHub, GitLab or Forgejo)", 'Cut from a checkout whose origin is on GitHub, GitLab or Forgejo, or set release.green in chant.config.ts to "chant" (ci/green tags) or "none".');
270
+ }
271
+ const names = FORGE_TOKEN_ORDER[remote.kind];
272
+ const tokenSource = names.find((n) => env[n]?.trim());
273
+ if (!tokenSource) {
274
+ throw new ForgeChecksUnavailableError(`release.green is forge-checks, and no token to ask ${remote.kind} (${remote.host}) for the commit's checks is set: ${names.join(", ")}`, remote.kind === "github" ? "Set GH_TOKEN, for one: GH_TOKEN=$(gh auth token) chant release cut ..." : `Set ${names[0]} to a token that reads ${remote.repo}.`);
275
+ }
276
+ const apiBase = remote.kind === "github" ? (remote.host === "github.com" ? "https://api.github.com" : `${remote.url}/api/v3`) : remote.kind === "gitlab" ? `${remote.url}/api/v4` : `${remote.url}/api/v1`;
277
+ return {
278
+ kind: remote.kind,
279
+ apiBase,
280
+ repo: remote.repo,
281
+ host: remote.host,
282
+ token: env[tokenSource].trim(),
283
+ tokenSource,
284
+ ...(remote.kind === "gitlab" ? { tokenHeader: "PRIVATE-TOKEN" } : {}),
285
+ };
286
+ }
@@ -0,0 +1,255 @@
1
+ /**
2
+ * `chant release init` (#5160): the first setup of `chant release` in a
3
+ * project that has never used chant.
4
+ *
5
+ * It reads the project ({@link detectProject}): the package.json and its
6
+ * npm, pnpm or yarn workspaces, go.mod, Cargo.toml, pyproject.toml,
7
+ * Dockerfiles, a goreleaser config, the forge `origin` names, and the tags
8
+ * releases were made under so far. From that it plans a `release` block
9
+ * ({@link planRelease}): the tag template, `legacyTags`, the green gate, the
10
+ * version stamping, the publish targets it can infer, and a dispatched
11
+ * release workflow. Then it writes that block into `chant.config.ts`
12
+ * ({@link insertReleaseBlock}), making a config of the block alone when
13
+ * there is none.
14
+ *
15
+ * Detection reads files and local git only; it never reaches a registry or
16
+ * the forge. Everything it can't set up from the repository, such as an npm
17
+ * trusted publisher, is a step printed for a person ({@link ReleaseInitPlan.registry}).
18
+ */
19
+ export type ReleaseInitCode = "release-init-release-exists" | "release-init-config-unreadable" | "release-init-workflow-exists" | "release-init-not-a-project" | "release-init-member-exists";
20
+ /** A refusal of `chant release init`, with its code. */
21
+ export declare class ReleaseInitError extends Error {
22
+ readonly code: ReleaseInitCode;
23
+ readonly fix?: string | undefined;
24
+ constructor(code: ReleaseInitCode, message: string, fix?: string | undefined);
25
+ }
26
+ /** One package.json found in the project. */
27
+ export interface InitPackage {
28
+ /** Directory from the project root, `.` for the root. */
29
+ dir: string;
30
+ name: string | null;
31
+ private: boolean;
32
+ /** `publishConfig.access`, when set. */
33
+ access: string | null;
34
+ /** A VS Code extension: `engines.vscode` is set. */
35
+ vscode: boolean;
36
+ /** The extension's publisher, for a VS Code extension. */
37
+ publisher: string | null;
38
+ /** Names in `dependencies`, `peerDependencies` and `optionalDependencies`. */
39
+ deps: string[];
40
+ scripts: string[];
41
+ /** `files` in package.json or an `.npmignore`, so npm packs only what they name. */
42
+ packList?: boolean;
43
+ }
44
+ export type NodeManager = "npm" | "pnpm" | "yarn";
45
+ /** What {@link detectProject} found. */
46
+ export interface ProjectFacts {
47
+ /** The project's directory from the repository root, or null at the root. */
48
+ path: string | null;
49
+ /** The forge `origin` names, or null. */
50
+ origin: {
51
+ kind: "github" | "gitlab" | "forgejo";
52
+ host: string;
53
+ repo: string;
54
+ } | null;
55
+ /** The forge whose workflow directory the repository has, else the origin's, else github. */
56
+ workflowForge: "github" | "gitlab" | "forgejo";
57
+ /** Other CI files at the repository root, which give a commit checks: workflow files other than chant's release, or `.gitlab-ci.yml`. */
58
+ ciFiles: string[];
59
+ node: {
60
+ manager: NodeManager;
61
+ lockfile: string | null;
62
+ /** `.yarnrc.yml` is there: yarn 2 or later. */
63
+ yarnBerry: boolean;
64
+ root: InitPackage;
65
+ /** Workspace packages, when the root declares workspaces. */
66
+ workspaces: InitPackage[] | null;
67
+ /** `@intentius/chant` is a dependency of the root package. */
68
+ hasChant: boolean;
69
+ } | null;
70
+ go: {
71
+ module: string | null;
72
+ } | null;
73
+ rust: {
74
+ name: string | null;
75
+ workspace: boolean;
76
+ /** `Cargo.toml` has a `version` string in `[package]` or `[workspace.package]`, which `release.version.files` can stamp. */
77
+ version: boolean;
78
+ /** `[package]` sets `publish = false`. */
79
+ unpublishable: boolean;
80
+ } | null;
81
+ python: {
82
+ name: string | null;
83
+ /** There is a `pyproject.toml`, which `python -m build` reads. */
84
+ pyproject: boolean;
85
+ /** `pyproject.toml` has a static `version` in `[project]` or `[tool.poetry]`, which `release.version.files` can stamp. */
86
+ version: boolean;
87
+ } | null;
88
+ /** Dockerfiles, from the project root. */
89
+ dockerfiles: string[];
90
+ goreleaser: {
91
+ file: string;
92
+ /** The config sets `snapshot.version_template` to the release label. */
93
+ labelTemplate: boolean;
94
+ /** The config has a top-level `snapshot:` key. */
95
+ snapshot: boolean;
96
+ /** The config builds images (`dockers:` or `kos:`). */
97
+ images: boolean;
98
+ } | null;
99
+ /** The tags releases were made under. */
100
+ tags: TagHistory;
101
+ /** `ci.green` is declared or `ci/green/` tags exist. */
102
+ chantCi: boolean;
103
+ /** `.gitignore` ignores `dist/`. */
104
+ distIgnored: boolean;
105
+ }
106
+ /** The release tags a repository holds, grouped by what comes before the version. */
107
+ export interface TagHistory {
108
+ /** The prefix most of the version tags share, such as `v` or `cli-v`; `""` for bare versions; null with no version tags. */
109
+ prefix: string | null;
110
+ /** How many tags have that prefix. */
111
+ count: number;
112
+ /** The newest tag with that prefix, by version. */
113
+ newest: string | null;
114
+ /** Other prefixes seen, with their counts. */
115
+ others: Array<{
116
+ prefix: string;
117
+ count: number;
118
+ }>;
119
+ }
120
+ /**
121
+ * The tag history of a list of tags: version tags grouped by their prefix,
122
+ * the largest group first. `ci/` and `chant/` tags are chant's own and
123
+ * left out.
124
+ */
125
+ export declare function readTagHistory(tags: readonly string[]): TagHistory;
126
+ /** The directories a workspace pattern such as `packages/*` or `apps/**` names, from `root`. */
127
+ export declare function expandWorkspacePattern(root: string, pattern: string): string[];
128
+ /** The workspace patterns of a package.json (`workspaces` as a list or `{ packages }`) or a pnpm-workspace.yaml. */
129
+ export declare function workspacePatterns(root: string): string[] | null;
130
+ /** Whether a goreleaser config sets `snapshot.version_template` to the release label. */
131
+ export declare function goreleaserFacts(text: string): {
132
+ labelTemplate: boolean;
133
+ snapshot: boolean;
134
+ images: boolean;
135
+ };
136
+ /** The lines a goreleaser config needs so its snapshot build carries the release's label. */
137
+ export declare const GORELEASER_SNAPSHOT = "snapshot:\n version_template: \"{{ .Env.CHANT_RELEASE_LABEL }}\"\n";
138
+ /** A `Cargo.toml`'s name, workspace, stampable version and `publish = false`. */
139
+ export declare function cargoFacts(text: string): NonNullable<ProjectFacts["rust"]>;
140
+ /** A `pyproject.toml`'s project name, and whether its version is a static string that `release.version.files` can stamp. */
141
+ export declare function pyprojectFacts(text: string): NonNullable<ProjectFacts["python"]>;
142
+ export declare function detectProject(root: string): ProjectFacts;
143
+ /** A value in the release block, as it is written to chant.config.ts. */
144
+ type Json = string | number | boolean | null | Json[] | {
145
+ [k: string]: Json;
146
+ };
147
+ /** What `chant release init` would write and say. */
148
+ export interface ReleaseInitPlan {
149
+ /** The `release` block. */
150
+ release: Record<string, Json>;
151
+ /** Why each part of the block is what it is, one line each. */
152
+ reasons: string[];
153
+ /** What the release does not publish, and why. */
154
+ notes: string[];
155
+ /** Steps a person takes on the registries and the forge. */
156
+ registry: string[];
157
+ /** The workflow file `chant release workflow` writes, from the repository root. */
158
+ workflowFile: string;
159
+ /** Lines to add to the goreleaser config, when it lacks them. */
160
+ goreleaserPatch: {
161
+ file: string;
162
+ append: string | null;
163
+ manual: string | null;
164
+ } | null;
165
+ /**
166
+ * True when the existing version tags are ones `release.tag` or
167
+ * `release.legacyTags` matches, so `chant release next` reads the newest
168
+ * as the previous release and the first release can take the label `auto`
169
+ * (#5200).
170
+ */
171
+ readsHistory: boolean;
172
+ }
173
+ /** What the plan needs besides the facts. */
174
+ export interface PlanOptions {
175
+ /** The chant version writing the plan, for the workflow's `npx --yes @intentius/chant@<version>`. */
176
+ chantVersion: string;
177
+ }
178
+ /** Packages in dependency order: each after the packages of the list it depends on, ties by directory. */
179
+ export declare function dependencyOrder(pkgs: readonly InitPackage[]): InitPackage[];
180
+ /**
181
+ * The tag template a project's history asks for, and the prefixes to read
182
+ * older releases by. `packages` is how many packages one release publishes:
183
+ * with more than one, a prefix other than `v` names one package's tags, so
184
+ * the release gets `v{version}` and the older tags are only read.
185
+ */
186
+ export declare function tagTemplateOf(facts: Pick<ProjectFacts, "tags" | "go" | "path">, packages?: number): {
187
+ template: string;
188
+ legacy: string[];
189
+ reason: string;
190
+ note: string | null;
191
+ };
192
+ /** Plan the `release` block for a project. */
193
+ export declare function planRelease(facts: ProjectFacts, opts: PlanOptions): ReleaseInitPlan;
194
+ /** One member of a planned train: a publishable package, released at its own version from its own `chant.config.ts`. */
195
+ export interface TrainMemberPlan {
196
+ /** The member's name in `chant.workspace.json`. */
197
+ name: string;
198
+ /** The package's directory from the project root. */
199
+ dir: string;
200
+ /** The npm package name. */
201
+ package: string;
202
+ /** The member's `release` block. */
203
+ release: Record<string, Json>;
204
+ }
205
+ /** What `chant release init` writes for a workspace released as a train (#5154). */
206
+ export interface ReleaseTrainPlan {
207
+ /** The workspace root's `release` block: `train`, the gate and the workflow. */
208
+ release: Record<string, Json>;
209
+ members: TrainMemberPlan[];
210
+ /** The name for a new `chant.workspace.json`. */
211
+ workspaceName: string;
212
+ reasons: string[];
213
+ notes: string[];
214
+ registry: string[];
215
+ workflowFile: string;
216
+ /** The environment the train is recorded for. */
217
+ env: string;
218
+ }
219
+ /** The environment a planned train is recorded for. */
220
+ export declare const TRAIN_ENV = "npm";
221
+ /**
222
+ * Whether the project's npm, pnpm or yarn workspaces can release as a train:
223
+ * one member per publishable package (#5154). `why` says why a project with
224
+ * several packages gets one release instead, and is null for a project with
225
+ * fewer than two.
226
+ */
227
+ export declare function trainFit(facts: ProjectFacts): {
228
+ train: true;
229
+ } | {
230
+ train: false;
231
+ why: string | null;
232
+ };
233
+ /** A workspace member name (lowercase letters, digits and dashes, at most 40) for a package. */
234
+ export declare function memberNameOf(pkg: Pick<InitPackage, "name" | "dir">): string;
235
+ /**
236
+ * Plan a train for a project {@link trainFit} accepts: a member per
237
+ * publishable workspace package, each stamping and publishing its own
238
+ * package, and the root's `release.train` with a dispatched workflow.
239
+ */
240
+ export declare function planTrain(facts: ProjectFacts, opts: PlanOptions): ReleaseTrainPlan;
241
+ /** A value as TypeScript source, objects and arrays on one line when short. */
242
+ export declare function toSource(value: Json, indent: string, step?: string): string;
243
+ /** The `release:` property as source, at `indent`, expanded one level so each field is on its own line. */
244
+ export declare function releaseBlockSource(release: Record<string, Json>, indent: string, step?: string): string;
245
+ /** A config made of the release block alone. */
246
+ export declare function newConfigSource(release: Record<string, Json>): string;
247
+ /**
248
+ * Write `release` into a chant.config.ts's default export: before the
249
+ * object's closing brace, or in place of an existing `release` property
250
+ * when `force`. Throws {@link ReleaseInitError}: `release-init-release-exists`
251
+ * for a `release` property without `force`, `release-init-config-unreadable`
252
+ * when the default export is not an object literal this can find.
253
+ */
254
+ export declare function insertReleaseBlock(src: string, release: Record<string, Json>, force: boolean): string;
255
+ export {};