@intentius/chant 0.124.70 → 0.124.72

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 (169) hide show
  1. package/dist/ci-agent.d.ts +12 -1
  2. package/dist/ci-agent.d.ts.map +1 -1
  3. package/dist/ci-agent.js +13 -8
  4. package/dist/ci-commit.d.ts +326 -0
  5. package/dist/ci-commit.d.ts.map +1 -0
  6. package/dist/ci-commit.js +725 -0
  7. package/dist/ci-estate/delivery.d.ts +75 -2
  8. package/dist/ci-estate/delivery.d.ts.map +1 -1
  9. package/dist/ci-estate/delivery.js +129 -0
  10. package/dist/ci-estate.d.ts +3 -1
  11. package/dist/ci-estate.d.ts.map +1 -1
  12. package/dist/ci-estate.js +4 -1
  13. package/dist/ci-product-words.d.ts +6 -1
  14. package/dist/ci-product-words.d.ts.map +1 -1
  15. package/dist/ci-product-words.js +3 -1
  16. package/dist/ci-product.d.ts +1 -1
  17. package/dist/ci-product.d.ts.map +1 -1
  18. package/dist/ci-product.js +1 -1
  19. package/dist/cli/handlers/approve.d.ts.map +1 -1
  20. package/dist/cli/handlers/approve.js +7 -2
  21. package/dist/cli/handlers/commit.d.ts +26 -0
  22. package/dist/cli/handlers/commit.d.ts.map +1 -0
  23. package/dist/cli/handlers/commit.js +145 -0
  24. package/dist/cli/handlers/notify-relay.d.ts.map +1 -1
  25. package/dist/cli/handlers/notify-relay.js +22 -2
  26. package/dist/cli/handlers/pr.d.ts +6 -0
  27. package/dist/cli/handlers/pr.d.ts.map +1 -1
  28. package/dist/cli/handlers/pr.js +16 -7
  29. package/dist/cli/handlers/release.d.ts +9 -0
  30. package/dist/cli/handlers/release.d.ts.map +1 -1
  31. package/dist/cli/handlers/release.js +114 -5
  32. package/dist/cli/main.d.ts.map +1 -1
  33. package/dist/cli/main.js +17 -0
  34. package/dist/components/product-pipeline.d.ts +33 -0
  35. package/dist/components/product-pipeline.d.ts.map +1 -1
  36. package/dist/components/product-pipeline.js +34 -1
  37. package/dist/components/release-compile.d.ts +2 -0
  38. package/dist/components/release-compile.d.ts.map +1 -1
  39. package/dist/components/release-compile.js +8 -4
  40. package/dist/config.d.ts +60 -0
  41. package/dist/config.d.ts.map +1 -1
  42. package/dist/config.js +16 -0
  43. package/dist/lexicon.d.ts +54 -0
  44. package/dist/lexicon.d.ts.map +1 -1
  45. package/dist/lexicon.js +28 -0
  46. package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +4 -0
  47. package/dist/lifecycle/__fixtures__/publish-fakes.d.ts.map +1 -1
  48. package/dist/lifecycle/__fixtures__/publish-fakes.js +6 -2
  49. package/dist/lifecycle/gated-request.d.ts +3 -1
  50. package/dist/lifecycle/gated-request.d.ts.map +1 -1
  51. package/dist/lifecycle/gated-request.js +5 -2
  52. package/dist/lifecycle/git.d.ts.map +1 -1
  53. package/dist/lifecycle/git.js +57 -0
  54. package/dist/lifecycle/publish-declaration.d.ts +16 -0
  55. package/dist/lifecycle/publish-declaration.d.ts.map +1 -1
  56. package/dist/lifecycle/publish-declaration.js +35 -3
  57. package/dist/lifecycle/publish-forge.d.ts +12 -0
  58. package/dist/lifecycle/publish-forge.d.ts.map +1 -1
  59. package/dist/lifecycle/publish-forge.js +102 -19
  60. package/dist/lifecycle/publish-npm.d.ts +15 -0
  61. package/dist/lifecycle/publish-npm.d.ts.map +1 -1
  62. package/dist/lifecycle/publish-npm.js +28 -1
  63. package/dist/lifecycle/publish-oci.d.ts +2 -0
  64. package/dist/lifecycle/publish-oci.d.ts.map +1 -1
  65. package/dist/lifecycle/publish-oci.js +10 -0
  66. package/dist/lifecycle/release-cut.d.ts +7 -1
  67. package/dist/lifecycle/release-cut.d.ts.map +1 -1
  68. package/dist/lifecycle/release-cut.js +8 -1
  69. package/dist/lifecycle/release-images.d.ts +87 -0
  70. package/dist/lifecycle/release-images.d.ts.map +1 -0
  71. package/dist/lifecycle/release-images.js +138 -0
  72. package/dist/lifecycle/release-publish.d.ts +2 -0
  73. package/dist/lifecycle/release-publish.d.ts.map +1 -1
  74. package/dist/notify-relay.d.ts +41 -1
  75. package/dist/notify-relay.d.ts.map +1 -1
  76. package/dist/notify-relay.js +40 -0
  77. package/dist/notify.d.ts +16 -3
  78. package/dist/notify.d.ts.map +1 -1
  79. package/dist/notify.js +16 -10
  80. package/dist/op/activities/review-agent.d.ts.map +1 -1
  81. package/dist/op/activities/review-agent.js +4 -2
  82. package/dist/op/gate.d.ts +5 -1
  83. package/dist/op/gate.d.ts.map +1 -1
  84. package/dist/op/gate.js +7 -2
  85. package/dist/op/op-waves-notify.d.ts +1 -1
  86. package/dist/op/op-waves-notify.d.ts.map +1 -1
  87. package/dist/op/op-waves-notify.js +2 -1
  88. package/dist/op/op-waves-run.d.ts.map +1 -1
  89. package/dist/op/op-waves-run.js +12 -8
  90. package/dist/op/op-waves.d.ts +9 -0
  91. package/dist/op/op-waves.d.ts.map +1 -1
  92. package/dist/op/op-waves.js +11 -0
  93. package/dist/pr-forge-base.d.ts +18 -0
  94. package/dist/pr-forge-base.d.ts.map +1 -0
  95. package/dist/pr-forge-base.js +29 -0
  96. package/dist/release-floors.d.ts +1 -1
  97. package/dist/release-floors.js +1 -1
  98. package/dist/wave-runtime.mjs +315 -315
  99. package/dist/workspace/ci-green.d.ts.map +1 -1
  100. package/dist/workspace/ci-green.js +1 -2
  101. package/dist/workspace/release-workflow.d.ts +47 -0
  102. package/dist/workspace/release-workflow.d.ts.map +1 -1
  103. package/dist/workspace/release-workflow.js +258 -14
  104. package/package.json +1 -1
  105. package/src/ci-agent.ts +13 -8
  106. package/src/ci-commit.test.ts +415 -0
  107. package/src/ci-commit.ts +901 -0
  108. package/src/ci-estate/__fixtures__/terragucci-dora.json +1305 -0
  109. package/src/ci-estate/delivery.ts +186 -2
  110. package/src/ci-estate/records-delivery.test.ts +55 -0
  111. package/src/ci-estate.ts +10 -0
  112. package/src/ci-product-words.ts +6 -2
  113. package/src/ci-product.ts +1 -0
  114. package/src/cli/handlers/approve.ts +6 -2
  115. package/src/cli/handlers/commit.ts +155 -0
  116. package/src/cli/handlers/notify-relay.ts +21 -2
  117. package/src/cli/handlers/operator.test.ts +2 -0
  118. package/src/cli/handlers/pr-wave-approve-lines.test.ts +32 -0
  119. package/src/cli/handlers/pr.ts +17 -7
  120. package/src/cli/handlers/release.ts +110 -5
  121. package/src/cli/main.ts +17 -0
  122. package/src/components/product-pipeline.test.ts +28 -1
  123. package/src/components/product-pipeline.ts +54 -1
  124. package/src/components/release-compile.ts +9 -3
  125. package/src/config.ts +31 -0
  126. package/src/lexicon.ts +72 -0
  127. package/src/lifecycle/__fixtures__/publish-fakes.ts +11 -5
  128. package/src/lifecycle/gated-request-spend.test.ts +115 -0
  129. package/src/lifecycle/gated-request.ts +5 -2
  130. package/src/lifecycle/git.ts +53 -0
  131. package/src/lifecycle/ledger-two-clones.test.ts +132 -0
  132. package/src/lifecycle/publish-declaration.ts +35 -3
  133. package/src/lifecycle/publish-forge-notes.test.ts +193 -0
  134. package/src/lifecycle/publish-forge.ts +100 -22
  135. package/src/lifecycle/publish-npm.ts +31 -2
  136. package/src/lifecycle/publish-oci.ts +10 -0
  137. package/src/lifecycle/publish-targets.test.ts +2 -1
  138. package/src/lifecycle/release-cut.ts +17 -1
  139. package/src/lifecycle/release-images.test.ts +242 -0
  140. package/src/lifecycle/release-images.ts +174 -0
  141. package/src/lifecycle/release-publish.ts +2 -0
  142. package/src/notify-relay.test.ts +55 -1
  143. package/src/notify-relay.ts +49 -1
  144. package/src/notify.ts +25 -12
  145. package/src/op/activities/review-agent.test.ts +20 -1
  146. package/src/op/activities/review-agent.ts +5 -2
  147. package/src/op/gate.ts +7 -2
  148. package/src/op/op-waves-approve-target.test.ts +108 -0
  149. package/src/op/op-waves-notify.ts +2 -2
  150. package/src/op/op-waves-run.ts +12 -7
  151. package/src/op/op-waves.ts +12 -0
  152. package/src/pr-forge-base.test.ts +37 -0
  153. package/src/pr-forge-base.ts +36 -0
  154. package/src/release-floors.ts +1 -1
  155. package/src/workspace/__fixtures__/release-workflow/forgejo-plain-member.yml +26 -0
  156. package/src/workspace/__fixtures__/release-workflow/forgejo-plain.yml +23 -0
  157. package/src/workspace/__fixtures__/release-workflow/forgejo-secure-member.yml +27 -0
  158. package/src/workspace/__fixtures__/release-workflow/forgejo-secure.yml +24 -0
  159. package/src/workspace/__fixtures__/release-workflow/github-plain-member.yml +26 -0
  160. package/src/workspace/__fixtures__/release-workflow/github-plain.yml +23 -0
  161. package/src/workspace/__fixtures__/release-workflow/github-secure-member.yml +27 -0
  162. package/src/workspace/__fixtures__/release-workflow/github-secure.yml +24 -0
  163. package/src/workspace/__fixtures__/release-workflow/gitlab-plain-member.yml +13 -0
  164. package/src/workspace/__fixtures__/release-workflow/gitlab-plain.yml +12 -0
  165. package/src/workspace/__fixtures__/release-workflow/gitlab-secure-member.yml +14 -0
  166. package/src/workspace/__fixtures__/release-workflow/gitlab-secure.yml +13 -0
  167. package/src/workspace/ci-green.ts +1 -2
  168. package/src/workspace/release-workflow.test.ts +199 -0
  169. package/src/workspace/release-workflow.ts +356 -14
@@ -0,0 +1,13 @@
1
+ chant-release-publish:
2
+ rules:
3
+ - if: $CI_COMMIT_TAG =~ /^release\//
4
+ id_tokens:
5
+ SIGSTORE_ID_TOKEN:
6
+ aud: sigstore
7
+ script:
8
+ - npm ci
9
+ - npm run build
10
+ - git fetch origin 'refs/tags/ci/*:refs/tags/ci/*'
11
+ - git fetch origin chant/lifecycle:chant/lifecycle
12
+ - npx chant release verify "${CI_COMMIT_TAG#release/}"
13
+ - npx chant release publish "${CI_COMMIT_TAG#release/}" --require-provenance --yes
@@ -59,7 +59,6 @@ import { greenBranches, laneOf, laneTagPrefixes, readDeclaration, readerVersion,
59
59
  import { makeNotifyEvent, sendNotify, type NotifyFields } from "../notify";
60
60
  import { lifecycleRemoteOverride } from "../lifecycle/ledger-remote";
61
61
  import { isTransientForgeError, type CheckRun, type CiForge, type OpRunRef, type WorkflowRun } from "./ci-green-forge";
62
- import { NEXT_RELEASE } from "../release-floors";
63
62
  import type { OpRunRecord } from "../op/runtime";
64
63
  import { readRunLedger } from "../lifecycle/run-ledger";
65
64
  import { fetchLifecycleStatus, listFilesInDir, listLedgerTrees, pushLifecycleStatus, writeLedgerFiles } from "../lifecycle/git";
@@ -92,7 +91,7 @@ export const CI_STALE_WALK = 200;
92
91
  /** The first chant that writes a merge queue's trigger and verdict job, and reads `chant ci verdict` (#4644). */
93
92
  export const CI_MERGE_QUEUE_FLOOR = "0.124.61";
94
93
  /** The first chant that reads `ci.green.mergeQueue: { retries }` and whose `ci verdict` re-runs a failed job and looks again after a forge 5xx (#4729). */
95
- export const CI_VERDICT_RETRIES_FLOOR = NEXT_RELEASE;
94
+ export const CI_VERDICT_RETRIES_FLOOR = "0.124.70";
96
95
 
97
96
  export const CI_LAST_GREEN_CONTRACT_VERSION = 1;
98
97
  export const CI_LAST_GREEN_SCHEMA_ID = "https://intentius.io/chant/schemas/workspace/ci-last-green/v1/ci-last-green.schema.json";
@@ -0,0 +1,199 @@
1
+ /** #4656: `chant release workflow` renders the release pipeline from the `release` block. */
2
+ import { describe, expect, test } from "vitest";
3
+ import { readFileSync } from "node:fs";
4
+ import { join } from "node:path";
5
+ import { parseYAML } from "../yaml";
6
+ import { renderReleaseWorkflow, RELEASE_DIGESTS_FILE, type ReleaseWorkflowInput } from "./release-workflow";
7
+ import type { SecurityGroup } from "./security";
8
+
9
+ const FIXTURES = join(__dirname, "__fixtures__", "release-workflow");
10
+ const FORGES = ["github", "forgejo", "gitlab"] as const;
11
+ const SECURE = new Set<SecurityGroup>(["supply-chain", "verified-releases"]);
12
+
13
+ describe("a config with only publish (#4656)", () => {
14
+ test("renders, byte for byte, the file chant 0.124.70 wrote, on every forge, with and without the security groups and a workspace root", () => {
15
+ for (const forge of FORGES) {
16
+ for (const [name, groups] of [["plain", new Set<SecurityGroup>()], ["secure", SECURE]] as const) {
17
+ for (const root of [".", "packages/app"]) {
18
+ const file = `${forge}-${name}${root === "." ? "" : "-member"}.yml`;
19
+ expect(renderReleaseWorkflow({ forge, groups, workspaceRoot: root }), file).toBe(readFileSync(join(FIXTURES, file), "utf-8"));
20
+ // An empty block, or a tag trigger, is the same file.
21
+ expect(renderReleaseWorkflow({ forge, groups, workspaceRoot: root, pipeline: { trigger: "tag" } }), file).toBe(readFileSync(join(FIXTURES, file), "utf-8"));
22
+ }
23
+ }
24
+ }
25
+ });
26
+ });
27
+
28
+ type GhJob = { needs?: string | string[]; outputs?: Record<string, string>; env?: Record<string, string>; steps: Array<{ id?: string; uses?: string; run?: string; with?: Record<string, unknown> }> };
29
+ type GhDoc = { on: Record<string, unknown>; env?: Record<string, string>; permissions?: Record<string, string>; jobs: Record<string, GhJob> };
30
+ const runs = (job: GhJob): string[] => job.steps.filter((s) => s.run).map((s) => s.run!.trim());
31
+
32
+ const dispatch = (forge: (typeof FORGES)[number], over: Partial<ReleaseWorkflowInput> = {}): string =>
33
+ renderReleaseWorkflow({ forge, groups: new Set(), pipeline: { trigger: "dispatch", build: "npm run build", after: ["npm run announce"] }, ...over });
34
+
35
+ describe("a dispatched release (#4656)", () => {
36
+ for (const forge of ["github", "forgejo"] as const) {
37
+ test(`${forge}: gate, cut, publish and post-release, started by hand with a label, and no tag before the gate`, () => {
38
+ const doc = parseYAML(dispatch(forge)) as GhDoc;
39
+ expect(Object.keys(doc.on)).toEqual(["workflow_dispatch"]);
40
+ expect(doc.env).toEqual({ CHANT_RELEASE_LABEL: "${{ inputs.label }}" });
41
+ expect(Object.keys(doc.jobs)).toEqual(["gate", "cut", "publish", "after-release"]);
42
+ const { gate, cut, publish } = doc.jobs as Record<string, GhJob>;
43
+
44
+ expect(gate!.outputs).toEqual({ commit: "${{ steps.green.outputs.commit }}" });
45
+ const green = gate!.steps.find((s) => s.id === "green")!.run!;
46
+ expect(green).toContain('npx chant ci last-green --from "$GITHUB_SHA" --json');
47
+ expect(green).toContain('echo "commit=$commit" >> "$GITHUB_OUTPUT"');
48
+ expect(green).not.toContain("is not green");
49
+ // Nothing in the gate tags or cuts.
50
+ expect(runs(gate!).join("\n")).not.toMatch(/release cut|git push|git tag/);
51
+
52
+ expect(cut!.needs).toBe("gate");
53
+ expect(cut!.env).toEqual({ CHANT_RELEASE_COMMIT: "${{ needs.gate.outputs.commit }}" });
54
+ expect(cut!.steps[0]!.with).toEqual({ ref: "${{ needs.gate.outputs.commit }}", "fetch-depth": 0 });
55
+ const cutRun = runs(cut!).join("\n");
56
+ expect(cutRun).toContain(`npx chant release cut "$CHANT_RELEASE_LABEL" --at "$CHANT_RELEASE_COMMIT" --yes --build 'npm run build' --json > "$RUNNER_TEMP/chant-cut.json"`);
57
+ expect(cutRun).toContain('git push origin "refs/tags/$tag"');
58
+ // The label reaches the shell as a variable, never spliced into a run line.
59
+ expect(dispatch(forge)).not.toMatch(/run:.*\$\{\{ inputs\.label \}\}/);
60
+
61
+ expect(publish!.needs).toEqual(["gate", "cut"]);
62
+ expect(runs(publish!)).toEqual([
63
+ "npm ci",
64
+ "git fetch origin 'refs/tags/ci/*:refs/tags/ci/*'",
65
+ "git fetch origin chant/lifecycle:chant/lifecycle",
66
+ "npm run build",
67
+ 'npx chant release publish "$CHANT_RELEASE_LABEL" --yes',
68
+ ]);
69
+ expect(runs(doc.jobs["after-release"]!)).toEqual(["npm ci", "npm run announce"]);
70
+ });
71
+ }
72
+
73
+ test("gate head refuses a dispatched commit that is not green; a lane is passed to the gate and the cut", () => {
74
+ const doc = parseYAML(renderReleaseWorkflow({ forge: "github", groups: new Set(), lane: "fast", pipeline: { trigger: "dispatch", gate: "head", build: false } })) as GhDoc;
75
+ const green = doc.jobs.gate!.steps.find((s) => s.id === "green")!.run!;
76
+ expect(green).toContain("--lane fast");
77
+ expect(green).toContain('if [ "$commit" != "$GITHUB_SHA" ]');
78
+ const cutRun = runs(doc.jobs.cut!).join("\n");
79
+ expect(cutRun).toContain("--lane fast");
80
+ expect(cutRun).not.toContain("--build");
81
+ expect(runs(doc.jobs.publish!)).not.toContain("npm run build");
82
+ expect(doc.jobs["after-release"]).toBeUndefined();
83
+ });
84
+
85
+ test("the security groups still add --require-provenance and release verify, and release images runs before the build", () => {
86
+ const doc = parseYAML(dispatch("github", { groups: SECURE, images: true })) as GhDoc;
87
+ expect(runs(doc.jobs.publish!)).toEqual([
88
+ "npm ci",
89
+ "git fetch origin 'refs/tags/ci/*:refs/tags/ci/*'",
90
+ "git fetch origin chant/lifecycle:chant/lifecycle",
91
+ `npx chant release images "$CHANT_RELEASE_LABEL" -o ${RELEASE_DIGESTS_FILE}`,
92
+ `echo "CHANT_RELEASE_DIGESTS=$PWD/${RELEASE_DIGESTS_FILE}" >> "$GITHUB_ENV"`,
93
+ "npm run build",
94
+ 'npx chant release verify "$CHANT_RELEASE_LABEL"',
95
+ 'npx chant release publish "$CHANT_RELEASE_LABEL" --require-provenance --yes',
96
+ ]);
97
+ });
98
+
99
+ test("gitlab: four jobs chained by needs in the default stage, started with CHANT_RELEASE_LABEL, the commit handed on as a dotenv, pushes with CHANT_RELEASE_TOKEN", () => {
100
+ const doc = parseYAML(dispatch("gitlab", { groups: SECURE, images: true })) as Record<string, { rules: Array<{ if: string }>; needs?: string[]; script: string[]; stage?: string; artifacts?: unknown; id_tokens?: unknown }>;
101
+ expect(Object.keys(doc)).toEqual(["chant-release-gate", "chant-release-cut", "chant-release-publish", "chant-release-after"]);
102
+ for (const job of Object.values(doc)) {
103
+ expect(job.rules).toEqual([{ if: "$CHANT_RELEASE_LABEL && $CI_PIPELINE_SOURCE =~ /^(web|api|trigger)$/" }]);
104
+ expect(job.stage).toBeUndefined();
105
+ }
106
+ expect(doc["chant-release-gate"]!.artifacts).toEqual({ reports: { dotenv: "chant-release-gate.env" } });
107
+ expect(doc["chant-release-gate"]!.script.join("\n")).toContain('--from "$CI_COMMIT_SHA"');
108
+ expect(doc["chant-release-cut"]!.needs).toEqual(["chant-release-gate"]);
109
+ expect(doc["chant-release-cut"]!.script[0]).toBe('git checkout --detach "$CHANT_RELEASE_COMMIT"');
110
+ expect(doc["chant-release-cut"]!.script.join("\n")).toContain("CHANT_RELEASE_TOKEN");
111
+ const publish = doc["chant-release-publish"]!;
112
+ expect(publish.id_tokens).toEqual({ SIGSTORE_ID_TOKEN: { aud: "sigstore" } });
113
+ expect(publish.script.slice(-5)).toEqual([
114
+ `npx chant release images "$CHANT_RELEASE_LABEL" -o ${RELEASE_DIGESTS_FILE}`,
115
+ `export CHANT_RELEASE_DIGESTS="$PWD/${RELEASE_DIGESTS_FILE}"`,
116
+ "npm run build",
117
+ 'npx chant release verify "$CHANT_RELEASE_LABEL"',
118
+ 'npx chant release publish "$CHANT_RELEASE_LABEL" --require-provenance --yes',
119
+ ]);
120
+ expect(doc["chant-release-after"]!.script.at(-1)).toBe("npm run announce");
121
+ });
122
+
123
+ test("a build command with a quote is passed to the cut as one shell word", () => {
124
+ const text = renderReleaseWorkflow({ forge: "github", groups: new Set(), pipeline: { trigger: "dispatch", build: "npm run build -- --label 'x'" } });
125
+ expect(text).toContain(`--build 'npm run build -- --label '\\''x'\\''' --json`);
126
+ });
127
+ });
128
+
129
+ describe("the tag trigger with images or after (#4656)", () => {
130
+ test("release images runs after the ledger fetch and before the build, and after-release follows the publish", () => {
131
+ const doc = parseYAML(renderReleaseWorkflow({ forge: "github", groups: new Set(), images: true, pipeline: { after: ["./notify.sh"] } })) as GhDoc;
132
+ expect(Object.keys(doc.on)).toEqual(["push"]);
133
+ expect(runs(doc.jobs.publish!)).toEqual([
134
+ "npm ci",
135
+ "git fetch origin 'refs/tags/ci/*:refs/tags/ci/*'",
136
+ "git fetch origin chant/lifecycle:chant/lifecycle",
137
+ `npx chant release images "\${GITHUB_REF_NAME#release/}" -o ${RELEASE_DIGESTS_FILE}`,
138
+ `echo "CHANT_RELEASE_DIGESTS=$PWD/${RELEASE_DIGESTS_FILE}" >> "$GITHUB_ENV"`,
139
+ "npm run build",
140
+ 'npx chant release publish "${GITHUB_REF_NAME#release/}" --yes',
141
+ ]);
142
+ expect(doc.jobs["after-release"]!.needs).toBe("publish");
143
+ expect(runs(doc.jobs["after-release"]!)).toEqual(['echo "CHANT_RELEASE_LABEL=${GITHUB_REF_NAME#release/}" >> "$GITHUB_ENV"', "npm ci", "./notify.sh"]);
144
+ });
145
+
146
+ test("gitlab: the after job needs the publish", () => {
147
+ const doc = parseYAML(renderReleaseWorkflow({ forge: "gitlab", groups: new Set(), pipeline: { after: ["./notify.sh"] } })) as Record<string, { needs?: string[]; script: string[] }>;
148
+ expect(doc["chant-release-after"]!.needs).toEqual(["chant-release-publish"]);
149
+ expect(doc["chant-release-after"]!.script.at(-1)).toBe("./notify.sh");
150
+ });
151
+ });
152
+
153
+ describe("the release workflow's permissions, env and setup (#4751)", () => {
154
+ const pipeline = {
155
+ trigger: "dispatch" as const,
156
+ permissions: { packages: "write" as const },
157
+ env: { OCI_USERNAME: "${{ github.actor }}", OCI_PASSWORD: "${{ github.token }}" },
158
+ setup: [{ uses: "docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392", with: { platforms: "arm64" } }, { run: "npm install -g npm@11.19.0" }],
159
+ };
160
+
161
+ test("github: the scope joins the workflow's, and the cut and publish jobs get the variables and the steps after the install", () => {
162
+ const doc = parseYAML(renderReleaseWorkflow({ forge: "github", groups: new Set(), images: true, pipeline })) as GhDoc;
163
+ expect(doc.permissions).toEqual({ contents: "write", "id-token": "write", packages: "write" });
164
+ expect(doc.jobs.cut!.env).toEqual({ CHANT_RELEASE_COMMIT: "${{ needs.gate.outputs.commit }}", OCI_USERNAME: "${{ github.actor }}", OCI_PASSWORD: "${{ github.token }}" });
165
+ expect(doc.jobs.publish!.env).toEqual({ OCI_USERNAME: "${{ github.actor }}", OCI_PASSWORD: "${{ github.token }}" });
166
+ expect(doc.jobs.gate!.env).toBeUndefined();
167
+ for (const job of [doc.jobs.cut!, doc.jobs.publish!]) {
168
+ const i = job.steps.findIndex((s) => s.run === "npm ci");
169
+ expect(job.steps[i + 1]).toEqual({ uses: "docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392", with: { platforms: "arm64" } });
170
+ expect(job.steps[i + 2]).toEqual({ run: "npm install -g npm@11.19.0" });
171
+ }
172
+ // An expression stays in env:, off every run: line.
173
+ expect(runs(doc.jobs.publish!).join("\n")).not.toContain("github.token");
174
+ });
175
+
176
+ test("the tag trigger's publish job takes them too", () => {
177
+ const doc = parseYAML(renderReleaseWorkflow({ forge: "github", groups: new Set(), pipeline: { ...pipeline, trigger: "tag" } })) as GhDoc;
178
+ expect(doc.permissions!.packages).toBe("write");
179
+ expect(doc.jobs.publish!.env).toEqual(pipeline.env);
180
+ expect(doc.jobs.publish!.steps.some((s) => s.uses?.startsWith("docker/setup-qemu-action@"))).toBe(true);
181
+ });
182
+
183
+ test("gitlab: variables and run steps; permissions and an action are refused by name", () => {
184
+ const gl = { trigger: "dispatch" as const, env: { OCI_USERNAME: "$CI_REGISTRY_USER" }, setup: [{ run: "docker run --privileged --rm tonistiigi/binfmt --install arm64" }] };
185
+ const doc = parseYAML(renderReleaseWorkflow({ forge: "gitlab", groups: new Set(), pipeline: gl })) as Record<string, { variables: Record<string, string>; script: string[] }>;
186
+ for (const name of ["chant-release-cut", "chant-release-publish"]) {
187
+ expect(doc[name]!.variables).toEqual({ GIT_DEPTH: "0", OCI_USERNAME: "$CI_REGISTRY_USER" });
188
+ expect(doc[name]!.script).toContain("docker run --privileged --rm tonistiigi/binfmt --install arm64");
189
+ }
190
+ expect(doc["chant-release-gate"]!.variables).toEqual({ GIT_DEPTH: "0" });
191
+ expect(() => renderReleaseWorkflow({ forge: "gitlab", groups: new Set(), pipeline: { ...gl, permissions: { packages: "write" } } })).toThrow(/GitLab has no permissions/);
192
+ expect(() => renderReleaseWorkflow({ forge: "gitlab", groups: new Set(), pipeline: { ...pipeline, permissions: undefined } })).toThrow(/give it as \{ run \}/);
193
+ });
194
+
195
+ test("a scope already granted and a bad variable name are refused", () => {
196
+ expect(() => renderReleaseWorkflow({ forge: "github", groups: new Set(), pipeline: { permissions: { contents: "read" } } })).toThrow(/already granted/);
197
+ expect(() => renderReleaseWorkflow({ forge: "github", groups: new Set(), pipeline: { env: { "BAD-NAME": "x" } } })).toThrow(/not a variable name/);
198
+ });
199
+ });