@intentius/chant 0.124.76 → 0.124.78

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 (212) hide show
  1. package/dist/__fixtures__/agent-guard/plywood.d.ts +8 -0
  2. package/dist/__fixtures__/agent-guard/plywood.d.ts.map +1 -0
  3. package/dist/__fixtures__/agent-guard/plywood.js +19 -0
  4. package/dist/__fixtures__/agent-guard/terragucci.d.ts +8 -0
  5. package/dist/__fixtures__/agent-guard/terragucci.d.ts.map +1 -0
  6. package/dist/__fixtures__/agent-guard/terragucci.js +30 -0
  7. package/dist/__fixtures__/gated-ledger.d.ts +10 -0
  8. package/dist/__fixtures__/gated-ledger.d.ts.map +1 -0
  9. package/dist/__fixtures__/gated-ledger.js +51 -0
  10. package/dist/__fixtures__/notify-messages/events.d.ts +9 -0
  11. package/dist/__fixtures__/notify-messages/events.d.ts.map +1 -0
  12. package/dist/__fixtures__/notify-messages/events.js +21 -0
  13. package/dist/__fixtures__/product-words.d.ts +14 -0
  14. package/dist/__fixtures__/product-words.d.ts.map +1 -1
  15. package/dist/__fixtures__/product-words.js +11 -0
  16. package/dist/__fixtures__/terragucci-notify.d.ts +66 -0
  17. package/dist/__fixtures__/terragucci-notify.d.ts.map +1 -0
  18. package/dist/__fixtures__/terragucci-notify.js +133 -0
  19. package/dist/action-pins.d.ts +8 -0
  20. package/dist/action-pins.d.ts.map +1 -1
  21. package/dist/action-pins.js +9 -0
  22. package/dist/agent-guard.d.ts +143 -0
  23. package/dist/agent-guard.d.ts.map +1 -0
  24. package/dist/agent-guard.js +455 -0
  25. package/dist/ci-commit.d.ts +120 -5
  26. package/dist/ci-commit.d.ts.map +1 -1
  27. package/dist/ci-commit.js +214 -23
  28. package/dist/ci-own-jobs.d.ts +81 -0
  29. package/dist/ci-own-jobs.d.ts.map +1 -0
  30. package/dist/ci-own-jobs.js +233 -0
  31. package/dist/ci-product-words.d.ts +18 -4
  32. package/dist/ci-product-words.d.ts.map +1 -1
  33. package/dist/ci-product-words.js +26 -6
  34. package/dist/ci-product.d.ts +40 -1
  35. package/dist/ci-product.d.ts.map +1 -1
  36. package/dist/ci-product.js +40 -1
  37. package/dist/cli/handlers/approve.d.ts +5 -1
  38. package/dist/cli/handlers/approve.d.ts.map +1 -1
  39. package/dist/cli/handlers/approve.js +17 -11
  40. package/dist/cli/handlers/build.d.ts +1 -1
  41. package/dist/cli/handlers/build.d.ts.map +1 -1
  42. package/dist/cli/handlers/build.js +88 -2
  43. package/dist/cli/handlers/commit.d.ts.map +1 -1
  44. package/dist/cli/handlers/commit.js +3 -1
  45. package/dist/cli/handlers/notify-relay.d.ts +18 -1
  46. package/dist/cli/handlers/notify-relay.d.ts.map +1 -1
  47. package/dist/cli/handlers/notify-relay.js +90 -14
  48. package/dist/cli/handlers/pr.d.ts.map +1 -1
  49. package/dist/cli/handlers/pr.js +3 -1
  50. package/dist/cli/handlers/release.d.ts +5 -1
  51. package/dist/cli/handlers/release.d.ts.map +1 -1
  52. package/dist/cli/handlers/release.js +21 -9
  53. package/dist/cli/handlers/run-generate.d.ts.map +1 -1
  54. package/dist/cli/handlers/run-generate.js +2 -1
  55. package/dist/cli/main.d.ts.map +1 -1
  56. package/dist/cli/main.js +21 -1
  57. package/dist/cli/parse-args.d.ts.map +1 -1
  58. package/dist/cli/parse-args.js +60 -4
  59. package/dist/cli/registry.d.ts +16 -0
  60. package/dist/cli/registry.d.ts.map +1 -1
  61. package/dist/components/pr-env-components.d.ts +65 -0
  62. package/dist/components/pr-env-components.d.ts.map +1 -0
  63. package/dist/components/pr-env-components.js +162 -0
  64. package/dist/components/pr-policy.d.ts +15 -0
  65. package/dist/components/pr-policy.d.ts.map +1 -1
  66. package/dist/components/pr-policy.js +24 -1
  67. package/dist/components/release-compile.d.ts +15 -3
  68. package/dist/components/release-compile.d.ts.map +1 -1
  69. package/dist/components/release-compile.js +66 -15
  70. package/dist/config.d.ts +14 -8
  71. package/dist/config.d.ts.map +1 -1
  72. package/dist/config.js +16 -1
  73. package/dist/gate-policy.d.ts +14 -1
  74. package/dist/gate-policy.d.ts.map +1 -1
  75. package/dist/gate-policy.js +16 -6
  76. package/dist/lexicon.d.ts +25 -1
  77. package/dist/lexicon.d.ts.map +1 -1
  78. package/dist/lexicon.js +10 -0
  79. package/dist/lifecycle/gated-op.d.ts +95 -0
  80. package/dist/lifecycle/gated-op.d.ts.map +1 -0
  81. package/dist/lifecycle/gated-op.js +96 -0
  82. package/dist/lifecycle/git.d.ts.map +1 -1
  83. package/dist/lifecycle/git.js +83 -2
  84. package/dist/lifecycle/release-images.d.ts +77 -3
  85. package/dist/lifecycle/release-images.d.ts.map +1 -1
  86. package/dist/lifecycle/release-images.js +132 -6
  87. package/dist/notify-product.d.ts +11 -2
  88. package/dist/notify-product.d.ts.map +1 -1
  89. package/dist/notify-product.js +16 -4
  90. package/dist/notify-relay-repo.d.ts +131 -0
  91. package/dist/notify-relay-repo.d.ts.map +1 -0
  92. package/dist/notify-relay-repo.js +202 -0
  93. package/dist/notify-relay.d.ts +25 -1
  94. package/dist/notify-relay.d.ts.map +1 -1
  95. package/dist/notify-relay.js +27 -2
  96. package/dist/notify.d.ts +36 -4
  97. package/dist/notify.d.ts.map +1 -1
  98. package/dist/notify.js +31 -21
  99. package/dist/notify.schema.json +1 -0
  100. package/dist/op/activities/review-product.d.ts +111 -0
  101. package/dist/op/activities/review-product.d.ts.map +1 -0
  102. package/dist/op/activities/review-product.js +116 -0
  103. package/dist/op/op-waves-capability.js +2 -2
  104. package/dist/policy-engine.d.ts +95 -0
  105. package/dist/policy-engine.d.ts.map +1 -0
  106. package/dist/policy-engine.js +157 -0
  107. package/dist/pr-forge-reads.d.ts +124 -0
  108. package/dist/pr-forge-reads.d.ts.map +1 -0
  109. package/dist/pr-forge-reads.js +322 -0
  110. package/dist/pr-forge.d.ts +14 -0
  111. package/dist/pr-forge.d.ts.map +1 -1
  112. package/dist/pr-forge.js +21 -13
  113. package/dist/pr-plan-note.d.ts +293 -0
  114. package/dist/pr-plan-note.d.ts.map +1 -0
  115. package/dist/pr-plan-note.js +362 -0
  116. package/dist/release-floors.d.ts +9 -1
  117. package/dist/release-floors.d.ts.map +1 -1
  118. package/dist/release-floors.js +9 -1
  119. package/dist/state-export.d.ts +126 -0
  120. package/dist/state-export.d.ts.map +1 -0
  121. package/dist/state-export.js +156 -0
  122. package/dist/state-migration.d.ts +148 -0
  123. package/dist/state-migration.d.ts.map +1 -0
  124. package/dist/state-migration.js +146 -0
  125. package/dist/state-unlock.d.ts +167 -0
  126. package/dist/state-unlock.d.ts.map +1 -0
  127. package/dist/state-unlock.js +196 -0
  128. package/dist/wave-runtime.mjs +332 -332
  129. package/dist/workspace/declaration.schema.json +1 -1
  130. package/dist/workspace/release-workflow.d.ts +10 -0
  131. package/dist/workspace/release-workflow.d.ts.map +1 -1
  132. package/dist/workspace/release-workflow.js +10 -4
  133. package/package.json +1 -1
  134. package/src/__fixtures__/agent-guard/plywood.ts +27 -0
  135. package/src/__fixtures__/agent-guard/terragucci.ts +39 -0
  136. package/src/__fixtures__/gated-ledger.ts +58 -0
  137. package/src/__fixtures__/notify-messages/events.ts +23 -0
  138. package/src/__fixtures__/notify-messages/messages.json +50 -0
  139. package/src/__fixtures__/pr-loop/terragucci-plan.note.golden.md +53 -0
  140. package/src/__fixtures__/pr-loop/terragucci-plan.note.json +83 -0
  141. package/src/__fixtures__/product-words.ts +12 -0
  142. package/src/__fixtures__/review-agent/terragucci-review.json +94 -0
  143. package/src/__fixtures__/terragucci-notify.ts +170 -0
  144. package/src/action-pins.test.ts +12 -1
  145. package/src/action-pins.ts +11 -0
  146. package/src/agent-guard.test.ts +319 -0
  147. package/src/agent-guard.ts +547 -0
  148. package/src/ci-commit.test.ts +213 -2
  149. package/src/ci-commit.ts +258 -27
  150. package/src/ci-own-jobs.test.ts +108 -0
  151. package/src/ci-own-jobs.ts +252 -0
  152. package/src/ci-product-words.ts +35 -7
  153. package/src/ci-product.ts +81 -1
  154. package/src/cli/handlers/approve-cwd.test.ts +112 -0
  155. package/src/cli/handlers/approve.ts +22 -11
  156. package/src/cli/handlers/build-own-jobs.test.ts +80 -0
  157. package/src/cli/handlers/build-pr-loop-control.test.ts +87 -0
  158. package/src/cli/handlers/build-run-group.test.ts +59 -0
  159. package/src/cli/handlers/build.ts +83 -3
  160. package/src/cli/handlers/commit.ts +3 -0
  161. package/src/cli/handlers/notify-relay.ts +99 -17
  162. package/src/cli/handlers/pr.ts +3 -1
  163. package/src/cli/handlers/release.ts +20 -10
  164. package/src/cli/handlers/run-generate.ts +2 -1
  165. package/src/cli/main.ts +21 -1
  166. package/src/cli/parse-args.ts +45 -3
  167. package/src/cli/registry.ts +16 -0
  168. package/src/components/pr-env-components.test.ts +137 -0
  169. package/src/components/pr-env-components.ts +213 -0
  170. package/src/components/pr-policy.test.ts +41 -1
  171. package/src/components/pr-policy.ts +25 -1
  172. package/src/components/release-compile.test.ts +47 -0
  173. package/src/components/release-compile.ts +70 -13
  174. package/src/config.ts +23 -3
  175. package/src/gate-policy-bundle.test.ts +14 -0
  176. package/src/gate-policy.test.ts +7 -0
  177. package/src/gate-policy.ts +22 -7
  178. package/src/lexicon.ts +28 -1
  179. package/src/lifecycle/gated-op.ts +158 -0
  180. package/src/lifecycle/git.test.ts +92 -0
  181. package/src/lifecycle/git.ts +71 -2
  182. package/src/lifecycle/release-images-dockerfile.test.ts +221 -0
  183. package/src/lifecycle/release-images.ts +167 -8
  184. package/src/notify-message-words.test.ts +186 -0
  185. package/src/notify-product.ts +17 -4
  186. package/src/notify-relay-repo.test.ts +284 -0
  187. package/src/notify-relay-repo.ts +234 -0
  188. package/src/notify-relay.test.ts +12 -0
  189. package/src/notify-relay.ts +29 -3
  190. package/src/notify.schema.json +1 -0
  191. package/src/notify.ts +59 -19
  192. package/src/op/activities/review-product.test.ts +116 -0
  193. package/src/op/activities/review-product.ts +200 -0
  194. package/src/op/op-waves-capability.ts +2 -2
  195. package/src/op/schedule-overdue.test.ts +26 -0
  196. package/src/policy-engine.test.ts +162 -0
  197. package/src/policy-engine.ts +200 -0
  198. package/src/pr-forge-reads.test.ts +285 -0
  199. package/src/pr-forge-reads.ts +424 -0
  200. package/src/pr-forge.ts +30 -16
  201. package/src/pr-plan-note.test.ts +105 -0
  202. package/src/pr-plan-note.ts +521 -0
  203. package/src/release-floors.ts +13 -1
  204. package/src/state-export.test.ts +124 -0
  205. package/src/state-export.ts +227 -0
  206. package/src/state-migration.test.ts +133 -0
  207. package/src/state-migration.ts +236 -0
  208. package/src/state-unlock.test.ts +165 -0
  209. package/src/state-unlock.ts +293 -0
  210. package/src/workspace/declaration.schema.json +1 -1
  211. package/src/workspace/release-workflow.test.ts +34 -0
  212. package/src/workspace/release-workflow.ts +19 -4
@@ -0,0 +1,165 @@
1
+ /**
2
+ * #4762: the engine-neutral lock release on an in-memory lock and ledger,
3
+ * and the forge clients' live runs through a recording fetch. No forge, no
4
+ * store and no git are reached.
5
+ */
6
+ import { describe, expect, test } from "vitest";
7
+ import { fakeLedger } from "./__fixtures__/gated-ledger";
8
+ import type { ForgeFetch } from "./pr-forge";
9
+ import { CLOCK_SKEW_MS, forgeLiveRuns, parseLockInfo, possibleHolders, releaseStateLock, STATE_UNLOCK_FLOOR, StateUnlockError, type LiveRun, type LockInfo, type StateLockSource } from "./state-unlock";
10
+
11
+ const LOCK: LockInfo = { ID: "a1b2", Operation: "OperationTypeApply", Who: "runner@ci", Created: "2026-11-08T08:00:00Z" };
12
+
13
+ function lock(held: LockInfo | undefined, stuck = false): StateLockSource & { released: string[] } {
14
+ let now = held;
15
+ const released: string[] = [];
16
+ return {
17
+ location: "s3://states/net.tfstate.tflock",
18
+ released,
19
+ read: async () => now,
20
+ release: async (id) => {
21
+ released.push(id);
22
+ if (!stuck && now?.ID === id) now = undefined;
23
+ },
24
+ };
25
+ }
26
+
27
+ const run = (id: string, started: string): LiveRun => ({ id, status: "in_progress", started });
28
+
29
+ const base = (ledger: ReturnType<typeof fakeLedger>, l: StateLockSource, runs: () => Promise<LiveRun[]>, extra: Record<string, unknown> = {}) => ({
30
+ subject: "net",
31
+ by: "ana",
32
+ lock: l,
33
+ liveRuns: runs,
34
+ words: { op: "tf-unlock", approveCommand: (s: string, d: string) => `product approve unlock ${s} --plan ${d}` },
35
+ rules: { mode: "ledger" as const },
36
+ ledger,
37
+ now: "2026-11-08T09:00:00Z",
38
+ ...extra,
39
+ });
40
+
41
+ describe("releaseStateLock", () => {
42
+ test("a free lock asks nothing", async () => {
43
+ const ledger = fakeLedger();
44
+ expect(await releaseStateLock(base(ledger, lock(undefined), async () => []))).toEqual({ status: "free", exit: 0, location: "s3://states/net.tfstate.tflock" });
45
+ expect(ledger.writes).toEqual([]);
46
+ });
47
+
48
+ test("a run that began before the lock keeps it held, and nothing is asked", async () => {
49
+ const ledger = fakeLedger();
50
+ const l = lock(LOCK);
51
+ const r = await releaseStateLock(base(ledger, l, async () => [run("7", "2026-11-08T07:59:00Z"), run("8", "2026-11-08T08:30:00Z")]));
52
+ expect(r).toMatchObject({ status: "alive", exit: 5 });
53
+ expect(r.status === "alive" && r.alive.map((x) => x.id)).toEqual(["7"]);
54
+ expect(ledger.writes).toEqual([]);
55
+ expect(l.released).toEqual([]);
56
+ });
57
+
58
+ test("waits for an approval of that lock, then releases it by its ID and records who released it", async () => {
59
+ const ledger = fakeLedger();
60
+ const l = lock(LOCK);
61
+ const first = await releaseStateLock(base(ledger, l, async () => [run("8", "2026-11-08T08:30:00Z")]));
62
+ expect(first).toMatchObject({ status: "waiting", exit: 3 });
63
+ expect(first.status === "waiting" && first.command).toBe(`product approve unlock net --plan ${first.status === "waiting" ? first.digest : ""}`);
64
+ ledger.approve("bo");
65
+ const second = await releaseStateLock(base(ledger, l, async () => [], { now: "2026-11-08T12:00:00Z" }));
66
+ expect(second).toMatchObject({ status: "released", exit: 0, approvedBy: "bo", digest: first.status === "waiting" ? first.digest : "" });
67
+ expect(l.released).toEqual(["a1b2"]);
68
+ expect(ledger.writes).toEqual(["pending", "applied", "finished:applied"]);
69
+ expect(ledger.details[0]).toMatchObject({ by: "ana", lock_id: "a1b2", locked_by: "runner@ci", approved_by: "bo", live_runs: 0, location: "s3://states/net.tfstate.tflock" });
70
+ });
71
+
72
+ test("a run that came back after the approval holds the release, and the approval stays unspent", async () => {
73
+ const ledger = fakeLedger();
74
+ ledger.approve("bo");
75
+ let calls = 0;
76
+ const runs = async () => (++calls === 1 ? [] : [run("9", "2026-11-08T07:00:00Z")]);
77
+ const l = lock(LOCK);
78
+ const r = await releaseStateLock(base(ledger, l, runs));
79
+ expect(r).toMatchObject({ status: "held", exit: 5 });
80
+ expect(r.status === "held" && r.reason).toMatch(/alive again \(run 9 /);
81
+ expect(ledger.writes).toEqual(["pending"]);
82
+ expect(l.released).toEqual([]);
83
+ });
84
+
85
+ test("a release that leaves the lock held fails the request", async () => {
86
+ const ledger = fakeLedger();
87
+ ledger.approve("bo");
88
+ const r = await releaseStateLock(base(ledger, lock(LOCK, true), async () => []));
89
+ expect(r).toMatchObject({ status: "failed", exit: 1 });
90
+ expect(r.status === "failed" && r.error.message).toMatch(/still holds it/);
91
+ expect(ledger.writes.at(-1)).toBe("finished:failed");
92
+ });
93
+
94
+ test("runs that cannot be read refuse the release", async () => {
95
+ const ledger = fakeLedger();
96
+ await expect(releaseStateLock(base(ledger, lock(LOCK), async () => Promise.reject(new Error("401"))))).rejects.toBeInstanceOf(StateUnlockError);
97
+ expect(ledger.writes).toEqual([]);
98
+ });
99
+
100
+ test("possibleHolders keeps a run within the clocks' skew, and every run for a lock with no time", () => {
101
+ const runs = [run("a", "2026-11-08T08:01:00Z"), run("b", "2026-11-08T08:03:00Z"), { id: "c", status: "queued" }];
102
+ expect(possibleHolders(runs, "2026-11-08T08:00:00Z").map((r) => r.id)).toEqual(["a", "c"]);
103
+ expect(possibleHolders(runs, undefined).map((r) => r.id)).toEqual(["a", "b", "c"]);
104
+ expect(CLOCK_SKEW_MS).toBe(120_000);
105
+ expect(parseLockInfo('{"ID":"x","Who":"me","Extra":1}')).toEqual({ ID: "x", Who: "me" });
106
+ expect(parseLockInfo('{"Who":"me"}')).toBeUndefined();
107
+ });
108
+
109
+ test("its floor is the next release", () => {
110
+ expect(STATE_UNLOCK_FLOOR).toBe("0.124.77");
111
+ });
112
+ });
113
+
114
+ /** A forge answering `routes` by `METHOD path?query`, recording the calls. */
115
+ function forgeFetch(routes: Record<string, unknown>): { fetch: ForgeFetch; urls: string[]; headers: Array<Record<string, string>> } {
116
+ const urls: string[] = [];
117
+ const headers: Array<Record<string, string>> = [];
118
+ const fetch: ForgeFetch = async (url, init) => {
119
+ urls.push(url);
120
+ headers.push(init.headers);
121
+ const u = new URL(url);
122
+ const found = routes[`${init.method} ${u.pathname}${u.search}`];
123
+ return found === undefined ? { ok: true, status: 200, text: async () => "[]" } : { ok: true, status: 200, text: async () => JSON.stringify(found) };
124
+ };
125
+ return { fetch, urls, headers };
126
+ }
127
+
128
+ describe("forgeLiveRuns", () => {
129
+ test("GitHub: queued, waiting and running runs, once each, with when each began", async () => {
130
+ const { fetch, urls, headers } = forgeFetch({
131
+ "GET /repos/acme/infra/actions/runs?status=in_progress&per_page=100": { workflow_runs: [{ id: 1, status: "in_progress", run_started_at: "2026-11-08T08:00:00Z", html_url: "https://github.com/acme/infra/actions/runs/1" }] },
132
+ "GET /repos/acme/infra/actions/runs?status=queued&per_page=100": { workflow_runs: [{ id: 2, status: "queued", created_at: "2026-11-08T08:05:00Z" }, { id: 1, status: "in_progress", run_started_at: "2026-11-08T08:00:00Z" }] },
133
+ });
134
+ const runs = await forgeLiveRuns({ kind: "github", apiBase: "https://api.github.com", repo: "acme/infra", token: "t", fetch });
135
+ expect(runs).toEqual([
136
+ { id: "1", status: "in_progress", started: "2026-11-08T08:00:00Z" },
137
+ { id: "2", status: "queued", started: "2026-11-08T08:05:00Z" },
138
+ ]);
139
+ expect(urls).toHaveLength(5);
140
+ expect(headers[0]!.Authorization).toBe("Bearer t");
141
+ });
142
+
143
+ test("Forgejo: a run whose start is the epoch counts from its creation", async () => {
144
+ const { fetch } = forgeFetch({
145
+ "GET /api/v1/repos/acme/infra/actions/runs?status=waiting&limit=50": { workflow_runs: [{ id: 5, status: "waiting", started: "1970-01-01T00:00:00Z", created: "2026-11-08T08:10:00Z" }] },
146
+ });
147
+ const runs = await forgeLiveRuns({ kind: "forgejo", apiBase: "https://codeberg.org/api/v1", repo: "acme/infra", token: "t", fetch });
148
+ expect(runs).toEqual([{ id: "5", status: "waiting", started: "2026-11-08T08:10:00Z" }]);
149
+ });
150
+
151
+ test("a forge that answers an error throws, so the release is refused", async () => {
152
+ const fetch: ForgeFetch = async () => ({ ok: false, status: 401, text: async () => '{"message":"401 Unauthorized"}' });
153
+ await expect(forgeLiveRuns({ kind: "github", apiBase: "https://api.github.com", repo: "acme/infra", fetch })).rejects.toThrow(/401/);
154
+ });
155
+
156
+ test("GitLab: running, pending, preparing and waiting pipelines", async () => {
157
+ const { fetch, urls, headers } = forgeFetch({
158
+ "GET /api/v4/projects/42/pipelines?status=pending&per_page=100": [{ id: 77, status: "pending", created_at: "2026-11-08T08:00:00Z", web_url: "https://gitlab.example.com/acme/infra/-/pipelines/77" }],
159
+ });
160
+ const runs = await forgeLiveRuns({ kind: "gitlab", apiBase: "https://gitlab.example.com/api/v4", repo: "42", token: "glpat", fetch });
161
+ expect(runs).toEqual([{ id: "77", status: "pending", started: "2026-11-08T08:00:00Z", url: "https://gitlab.example.com/acme/infra/-/pipelines/77" }]);
162
+ expect(urls.map((u) => new URL(u).searchParams.get("status"))).toEqual(["running", "pending", "preparing", "waiting_for_resource"]);
163
+ expect(headers[0]!["PRIVATE-TOKEN"]).toBe("glpat");
164
+ });
165
+ });
@@ -0,0 +1,293 @@
1
+ /**
2
+ * A stale state lock released behind a gated request (#4762): the lock a
3
+ * job killed mid-apply left behind, released once someone else approved
4
+ * that lock by its ID, and only while no run that may hold it is alive.
5
+ *
6
+ * Engine-neutral. The engine's adapter is a {@link StateLockSource}: where
7
+ * the lock is, the lock it holds now, and a release by ID. The terraform
8
+ * lexicon builds one from a root's backend and the binary's `force-unlock`
9
+ * (`@intentius/chant-lexicon-terraform/state-unlock`); a Pulumi stack's lock
10
+ * (`.pulumi/locks/...` and `pulumi cancel`) fits the same calls. The runs
11
+ * come from the forge ({@link forgeLiveRuns}), or the caller's own list.
12
+ *
13
+ * 1. The lock is read, with its ID, who took it and when.
14
+ * 2. A run of the repository that has not finished and began before the
15
+ * lock was taken (give or take {@link CLOCK_SKEW_MS}) may be the one
16
+ * holding it, so while one is alive nothing is asked and nothing is
17
+ * released. A forge that cannot be read refuses too: nothing then says
18
+ * the holder is gone.
19
+ * 3. The request (kind `unlock`, subject the root or stack, fields the
20
+ * lock's location and ID) waits for an approval by someone other than
21
+ * the requester. An approval binds that lock and no other.
22
+ * 4. Approved, the runs are read again just before the spend, the lock is
23
+ * released by its ID, read again to check it is gone, and the finished
24
+ * line records who released which lock under whose approval.
25
+ */
26
+ import { CHANT_EXIT } from "./exit-codes";
27
+ import { gatedOp, type GatedRequestLedger } from "./lifecycle/gated-op";
28
+ import type { GatedRequestRules } from "./lifecycle/gated-request";
29
+ import type { ForgeFetch, ForgeKind } from "./pr-forge";
30
+
31
+ /** The first chant with the engine-neutral lock release and {@link forgeLiveRuns} (#4762). */
32
+ export const STATE_UNLOCK_FLOOR = "0.124.77";
33
+
34
+ /** A run of the repository that has not finished, as {@link forgeLiveRuns} reads it. */
35
+ export interface LiveRun {
36
+ id: string;
37
+ status: string;
38
+ /** When it began, or was created when the forge gives no start. ISO 8601. */
39
+ started?: string;
40
+ url?: string;
41
+ }
42
+
43
+ /** Where {@link forgeLiveRuns} reads a repository's runs. */
44
+ export interface LiveRunsTarget {
45
+ kind: ForgeKind;
46
+ /** The forge's API base: `https://api.github.com`, `https://<host>/api/v1`, `https://<host>/api/v4`. */
47
+ apiBase: string;
48
+ /** `owner/repo` on GitHub and Forgejo; the project's id or path on GitLab. */
49
+ repo: string;
50
+ token?: string;
51
+ /** GitLab: the header the token goes in. Default `PRIVATE-TOKEN`. */
52
+ tokenHeader?: "PRIVATE-TOKEN" | "JOB-TOKEN";
53
+ fetch?: ForgeFetch;
54
+ }
55
+
56
+ const text = (v: unknown): string | undefined => (typeof v === "string" && v !== "" ? v : undefined);
57
+
58
+ /**
59
+ * The repository's runs that have not finished: GitHub's and Forgejo's
60
+ * Actions runs queued, waiting or in progress, GitLab's pipelines running,
61
+ * pending, preparing or waiting for a resource. Kept here rather than on the
62
+ * forge clients, so the bundles that carry those clients do not grow with
63
+ * a read only a lock release makes. Throws on a forge that answers an error.
64
+ */
65
+ export async function forgeLiveRuns(t: LiveRunsTarget): Promise<LiveRun[]> {
66
+ const fetchFn = t.fetch ?? (globalThis.fetch as unknown as ForgeFetch);
67
+ const base = t.apiBase.replace(/\/+$/, "");
68
+ const headers: Record<string, string> =
69
+ t.kind === "github"
70
+ ? { ...(t.token ? { Authorization: `Bearer ${t.token}` } : {}), Accept: "application/vnd.github+json" }
71
+ : t.kind === "forgejo"
72
+ ? { ...(t.token ? { Authorization: `token ${t.token}` } : {}), Accept: "application/json" }
73
+ : { ...(t.token ? { [t.tokenHeader ?? "PRIVATE-TOKEN"]: t.token } : {}), Accept: "application/json" };
74
+ const get = async (path: string): Promise<unknown> => {
75
+ const res = await fetchFn(`${base}${path}`, { method: "GET", headers });
76
+ const body = await res.text();
77
+ if (!res.ok) throw new Error(`GET ${base}${path}: ${res.status} ${body.slice(0, 200)}`);
78
+ return body ? (JSON.parse(body) as unknown) : undefined;
79
+ };
80
+ const isObject = (v: unknown): v is Record<string, unknown> => typeof v === "object" && v !== null && !Array.isArray(v);
81
+ const out = new Map<string, LiveRun>();
82
+ if (t.kind === "gitlab") {
83
+ const project = encodeURIComponent(decodeURIComponent(t.repo));
84
+ for (const status of ["running", "pending", "preparing", "waiting_for_resource"]) {
85
+ const rows = await get(`/projects/${project}/pipelines?status=${status}&per_page=100`);
86
+ for (const p of Array.isArray(rows) ? rows : []) {
87
+ if (!isObject(p) || p.id === undefined) continue;
88
+ const started = text(p.started_at) ?? text(p.created_at);
89
+ const url = text(p.web_url);
90
+ out.set(String(p.id), { id: String(p.id), status: text(p.status) ?? status, ...(started ? { started } : {}), ...(url ? { url } : {}) });
91
+ }
92
+ }
93
+ return [...out.values()];
94
+ }
95
+ const statuses = t.kind === "github" ? ["in_progress", "queued", "waiting", "pending", "requested"] : ["running", "waiting", "blocked"];
96
+ for (const status of statuses) {
97
+ const body = await get(`/repos/${t.repo}/actions/runs?status=${status}&${t.kind === "github" ? "per_page=100" : "limit=50"}`);
98
+ const runs = Array.isArray(body) ? body : isObject(body) && Array.isArray(body.workflow_runs) ? body.workflow_runs : [];
99
+ for (const r of runs) {
100
+ if (!isObject(r) || r.id === undefined) continue;
101
+ const started = t.kind === "github" ? (text(r.run_started_at) ?? text(r.created_at)) : (text(r.started) ?? text(r.created));
102
+ // Forgejo leaves `started` at the epoch until a job starts.
103
+ const begun = started && Date.parse(started) > 0 ? started : (text(r.created) ?? text(r.created_at));
104
+ const url = text(r.html_url);
105
+ out.set(String(r.id), { id: String(r.id), status: text(r.status) ?? status, ...(begun ? { started: begun } : {}), ...(url ? { url } : {}) });
106
+ }
107
+ }
108
+ return [...out.values()];
109
+ }
110
+
111
+ /** How far a run's start may be after the lock's and still count as a run that could hold it: the clocks of the job and the forge differ. */
112
+ export const CLOCK_SKEW_MS = 2 * 60 * 1000;
113
+
114
+ /** A lock's info, as Terraform's binary writes it and other engines can name it. */
115
+ export interface LockInfo {
116
+ ID: string;
117
+ Operation?: string;
118
+ Info?: string;
119
+ Who?: string;
120
+ Version?: string;
121
+ Created?: string;
122
+ Path?: string;
123
+ }
124
+
125
+ /** A lock info's JSON, or undefined when it holds no lock ID. */
126
+ export function parseLockInfo(text: string): LockInfo | undefined {
127
+ try {
128
+ const v = JSON.parse(text) as Record<string, unknown>;
129
+ if (!v || typeof v !== "object" || typeof v.ID !== "string" || v.ID === "") return undefined;
130
+ const out: LockInfo = { ID: v.ID };
131
+ for (const k of ["Operation", "Info", "Who", "Version", "Created", "Path"] as const) if (typeof v[k] === "string") out[k] = v[k] as string;
132
+ return out;
133
+ } catch {
134
+ return undefined;
135
+ }
136
+ }
137
+
138
+ /** An engine's state lock: the adapter a product's engine supplies. */
139
+ export interface StateLockSource {
140
+ /** Where the lock is, as messages and the record name it. Never a credential. */
141
+ readonly location: string;
142
+ /** The lock held now, or undefined when none is. */
143
+ read(): Promise<LockInfo | undefined>;
144
+ /** Release the lock with this ID, and no other. */
145
+ release(id: string): Promise<void>;
146
+ }
147
+
148
+ const time = (iso: string | undefined): number => (iso ? Date.parse(iso) : Number.NaN);
149
+
150
+ /**
151
+ * The live runs that may hold a lock taken at `created`: those that began
152
+ * before it, give or take the clocks' skew. A lock with no time it was taken,
153
+ * or a run with no start, keeps every run in.
154
+ */
155
+ export function possibleHolders(runs: readonly LiveRun[], created: string | undefined, skewMs = CLOCK_SKEW_MS): LiveRun[] {
156
+ const taken = time(created);
157
+ return runs.filter((r) => Number.isNaN(taken) || Number.isNaN(time(r.started)) || time(r.started) <= taken + skewMs);
158
+ }
159
+
160
+ /** A lock as one line: its ID, operation, holder and time. */
161
+ export const describeLock = (l: LockInfo): string => `lock ${l.ID}${l.Operation ? `, ${l.Operation}` : ""}${l.Who ? ` by ${l.Who}` : ""}${l.Created ? ` at ${l.Created}` : ""}`;
162
+
163
+ /** A run as one line. */
164
+ export const describeRun = (r: LiveRun): string => `run ${r.id} (${r.status}${r.started ? `, began ${r.started}` : ""})${r.url ? ` ${r.url}` : ""}`;
165
+
166
+ /** The product's words for a release. */
167
+ export interface StateUnlockWords {
168
+ /** The op the requests wait at, such as `tf-unlock`. */
169
+ op: string;
170
+ /** The request's kind. Default `unlock`. */
171
+ kind?: string;
172
+ /** The command that approves a request, as the product prints it. Default chant's. */
173
+ approveCommand?: (subject: string, digest: string) => string;
174
+ }
175
+
176
+ export interface StateUnlockInput {
177
+ /** Whose lock: a root, a stack. The gate the request waits at. */
178
+ subject: string;
179
+ /** The requester. Their own approval never counts. */
180
+ by: string;
181
+ lock: StateLockSource;
182
+ /**
183
+ * The repository's runs that have not finished, such as
184
+ * {@link forgeLiveRuns}. Read before the request and again just before
185
+ * the spend. A throw refuses the release.
186
+ */
187
+ liveRuns: () => Promise<LiveRun[]>;
188
+ words: StateUnlockWords;
189
+ rules: GatedRequestRules;
190
+ cwd?: string;
191
+ base?: string;
192
+ /** How long a request waits for its approval. Default 48h. */
193
+ expiry?: string;
194
+ now?: string;
195
+ commit?: string;
196
+ skewMs?: number;
197
+ ledger?: GatedRequestLedger;
198
+ }
199
+
200
+ /** How a release ended. `exit` is the code its command exits with. */
201
+ export type StateUnlockOutcome =
202
+ | { status: "free"; exit: 0; location: string }
203
+ | { status: "released"; exit: 0; location: string; lock: LockInfo; digest: string; approvedBy: string; liveRuns: number; recorded: boolean }
204
+ /** A run that may hold the lock is alive: nothing was asked or released. */
205
+ | { status: "alive"; exit: 5; location: string; lock: LockInfo; alive: LiveRun[] }
206
+ | { status: "waiting"; exit: 3; location: string; lock: LockInfo; digest: string; command: string }
207
+ | { status: "refused"; exit: 3; location: string; lock: LockInfo; digest: string; command: string; by: string; reason: string }
208
+ /** Approved, and a run that may hold the lock came back before the spend: the approval stands unspent. */
209
+ | { status: "held"; exit: 5; location: string; lock: LockInfo; digest: string; reason: string }
210
+ | { status: "spent"; exit: 1; location: string; lock: LockInfo; digest: string }
211
+ | { status: "failed"; exit: 1; location: string; lock: LockInfo; digest: string; error: Error; recorded: boolean };
212
+
213
+ /** A refusal before anything is asked: the runs could not be read. */
214
+ export class StateUnlockError extends Error {
215
+ constructor(message: string) {
216
+ super(message);
217
+ this.name = "StateUnlockError";
218
+ }
219
+ }
220
+
221
+ /** Release a state's lock that no live run can hold, once an approval of that lock stands. */
222
+ export async function releaseStateLock(input: StateUnlockInput): Promise<StateUnlockOutcome> {
223
+ const location = input.lock.location;
224
+ const lock = await input.lock.read();
225
+ if (!lock) return { status: "free", exit: CHANT_EXIT.done, location };
226
+ let live = 0;
227
+ const holders = async (): Promise<LiveRun[]> => {
228
+ let runs: LiveRun[];
229
+ try {
230
+ runs = await input.liveRuns();
231
+ } catch (e) {
232
+ throw new StateUnlockError(`the repository's runs could not be read (${(e as Error).message}), so nothing says the run holding ${describeLock(lock)} is gone`);
233
+ }
234
+ live = runs.length;
235
+ return possibleHolders(runs, lock.Created, input.skewMs);
236
+ };
237
+ const alive = await holders();
238
+ if (alive.length > 0) return { status: "alive", exit: CHANT_EXIT.held, location, lock, alive };
239
+
240
+ const result = await gatedOp(
241
+ {
242
+ op: input.words.op,
243
+ request: { kind: input.words.kind ?? "unlock", subject: input.subject, by: input.by, fields: { location, id: lock.ID } },
244
+ rules: input.rules,
245
+ description: `release ${describeLock(lock)} on ${location}`,
246
+ expiry: input.expiry ?? "48h",
247
+ ...(input.base ? { base: input.base } : {}),
248
+ ...(input.cwd ? { cwd: input.cwd } : {}),
249
+ ...(input.now ? { now: input.now } : {}),
250
+ ...(input.commit ? { commit: input.commit } : {}),
251
+ ...(input.ledger ? { ledger: input.ledger } : {}),
252
+ // The approval may be hours old: the runs are read again just before the spend.
253
+ beforeSpend: async () => {
254
+ const still = await holders();
255
+ return still.length > 0 ? `a run that began before the lock is alive again (${still.map(describeRun).join("; ")}), so the lock is not released` : undefined;
256
+ },
257
+ },
258
+ async ({ approvedBy }) => {
259
+ await input.lock.release(lock.ID);
260
+ const after = await input.lock.read();
261
+ if (after?.ID === lock.ID) throw new StateUnlockError(`the release of lock ${lock.ID} ran, and ${location} still holds it`);
262
+ return {
263
+ output: approvedBy,
264
+ detail: {
265
+ by: input.by,
266
+ location,
267
+ lock_id: lock.ID,
268
+ ...(lock.Operation ? { operation: lock.Operation } : {}),
269
+ ...(lock.Who ? { locked_by: lock.Who } : {}),
270
+ ...(lock.Created ? { locked_at: lock.Created } : {}),
271
+ approved_by: approvedBy,
272
+ live_runs: live,
273
+ },
274
+ };
275
+ },
276
+ );
277
+ const command = (fallback: string): string => (input.words.approveCommand ? input.words.approveCommand(input.subject, result.digest) : fallback);
278
+ const at = { location, lock, digest: result.digest };
279
+ switch (result.status) {
280
+ case "done":
281
+ return { status: "released", exit: CHANT_EXIT.done, ...at, approvedBy: result.approvedBy, liveRuns: live, recorded: result.recorded };
282
+ case "waiting":
283
+ return { status: "waiting", exit: CHANT_EXIT.waiting, ...at, command: command(result.command) };
284
+ case "refused":
285
+ return { status: "refused", exit: CHANT_EXIT.waiting, ...at, command: command(result.command), by: result.by, reason: result.reason };
286
+ case "held":
287
+ return { status: "held", exit: CHANT_EXIT.held, ...at, reason: result.reason };
288
+ case "spent":
289
+ return { status: "spent", exit: CHANT_EXIT.failed, ...at };
290
+ case "failed":
291
+ return { status: "failed", exit: CHANT_EXIT.failed, ...at, error: result.error, recorded: result.recorded };
292
+ }
293
+ }
@@ -2035,7 +2035,7 @@
2035
2035
  },
2036
2036
  "ciPolicy": {
2037
2037
  "type": "object",
2038
- "description": "Gate-time policy on the pull-request jobs (#4294): a policy engine run over the change set, with the policy read at base. engine names the result shape the command prints, conftest (the default) or opa. path is the policy directory, relative to the declaration (default policy). namespace is the package to read. command replaces the engine's own argv, with {policy} for the policy directory exported from base and {input} for the input file. deny rules refuse the apply unless an override counts; hold rules make the plan wait for a person's approval; warn rules are advice. There is no unattended outcome. source (#4613) is { repo, ref, path? }: a shared repository whose ref the job fetches, read in place of path, with the commit read recorded on the report and the wave's decision; path inside it defaults to policy, and path beside source is refused. packs (#4613) is a list of { dir, config? }: CrossGuard packs every pulumi-up preview runs, copied from the declaration's directory at base, or from the top of source when it is set. Added in schema 1 by chant 0.124.41, so a declaration that uses it sets minReader to 0.124.41 or newer; source and packs were added in schema 1 by chant 0.124.55, so a declaration that sets either sets minReader to 0.124.55 or newer."
2038
+ "description": "Gate-time policy on the pull-request jobs (#4294): a policy engine run over the change set, with the policy read at base. engine names the result shape the command prints, conftest (the default) or opa. path is the policy directory, relative to the declaration (default policy). namespace is the package to read. command replaces the engine's own argv, with {policy} for the policy directory exported from base and {input} for the input file. deny rules refuse the apply unless an override counts; hold rules make the plan wait for a person's approval; warn rules are advice. There is no unattended outcome. source (#4613) is { repo, ref, path? }: a shared repository whose ref the job fetches, read in place of path, with the commit read recorded on the report and the wave's decision; path inside it defaults to policy, and path beside source is refused. packs (#4613) is a list of { dir, config? }: CrossGuard packs every pulumi-up preview runs, copied from the declaration's directory at base, or from the top of source when it is set. Added in schema 1 by chant 0.124.41, so a declaration that uses it sets minReader to 0.124.41 or newer; source and packs were added in schema 1 by chant 0.124.55, so a declaration that sets either sets minReader to 0.124.55 or newer. install (#4774) is true to fetch conftest or opa at the release chant pins, checked against its recorded sha256, when the engine is not on PATH; it is refused beside command. Read by chant 0.124.77 and newer, so a declaration that sets install sets minReader to 0.124.77 or newer."
2039
2039
  },
2040
2040
  "ciPhaseName": {
2041
2041
  "type": "string",
@@ -201,6 +201,40 @@ describe("the release workflow's permissions, env and setup (#4751)", () => {
201
201
  });
202
202
  });
203
203
 
204
+ describe("the publish job hands GITHUB_TOKEN to a GitHub forge target (#4767)", () => {
205
+ const ghForge = { type: "forge" as const, forge: "github" as const, repo: "acme/api", assets: ["dist/api.tar.gz"] };
206
+
207
+ test("both triggers: the publish job gets the job's token, and no other job does", () => {
208
+ for (const trigger of ["tag", "dispatch"] as const) {
209
+ const doc = parseYAML(renderReleaseWorkflow({ forge: "github", groups: new Set(), publish: [ghForge], pipeline: { trigger } })) as GhDoc;
210
+ expect(doc.jobs.publish!.env, trigger).toEqual({ GITHUB_TOKEN: "${{ github.token }}" });
211
+ if (trigger === "dispatch") {
212
+ expect(doc.jobs.cut!.env).toEqual({ CHANT_RELEASE_COMMIT: "${{ needs.gate.outputs.commit }}" });
213
+ expect(doc.jobs.gate!.env).toBeUndefined();
214
+ }
215
+ }
216
+ });
217
+
218
+ test("it comes before release.workflow.env, which can set GITHUB_TOKEN itself", () => {
219
+ const doc = parseYAML(renderReleaseWorkflow({ forge: "github", groups: new Set(), publish: [ghForge], pipeline: { env: { OCI_USERNAME: "${{ github.actor }}" } } })) as GhDoc;
220
+ expect(Object.entries(doc.jobs.publish!.env!)).toEqual([["GITHUB_TOKEN", "${{ github.token }}"], ["OCI_USERNAME", "${{ github.actor }}"]]);
221
+ const own = parseYAML(renderReleaseWorkflow({ forge: "github", groups: new Set(), publish: [ghForge], pipeline: { env: { GITHUB_TOKEN: "${{ secrets.RELEASE_TOKEN }}" } } })) as GhDoc;
222
+ expect(own.jobs.publish!.env).toEqual({ GITHUB_TOKEN: "${{ secrets.RELEASE_TOKEN }}" });
223
+ });
224
+
225
+ test("a tokenEnv, another forge's target, or no forge target renders the file it did", () => {
226
+ const plain = renderReleaseWorkflow({ forge: "github", groups: new Set() });
227
+ expect(plain).toBe(readFileSync(join(FIXTURES, "github-plain.yml"), "utf-8"));
228
+ for (const publish of [[{ ...ghForge, tokenEnv: "RELEASE_TOKEN" }], [{ ...ghForge, forge: "gitlab" as const }], [{ type: "npm" as const, packages: ["."] }], []]) {
229
+ expect(renderReleaseWorkflow({ forge: "github", groups: new Set(), publish }), JSON.stringify(publish)).toBe(plain);
230
+ }
231
+ // Forgejo's and GitLab's job tokens are not a GitHub token.
232
+ for (const forge of ["forgejo", "gitlab"] as const) {
233
+ expect(renderReleaseWorkflow({ forge, groups: new Set(), publish: [ghForge] })).toBe(readFileSync(join(FIXTURES, `${forge}-plain.yml`), "utf-8"));
234
+ }
235
+ });
236
+ });
237
+
204
238
  describe("a repository's first dispatched release (terragucci 0.4.50's cut)", () => {
205
239
  const cutLedgerLine = (): string => {
206
240
  const doc = parseYAML(renderReleaseWorkflow({ forge: "github", groups: new Set(), pipeline: { trigger: "dispatch" } })) as GhDoc;
@@ -28,6 +28,7 @@
28
28
  * renders the tag-triggered file it always did.
29
29
  */
30
30
  import { ACTION_PINS, tagComments, usesRef } from "../action-pins";
31
+ import { resolveReleaseImages } from "../lifecycle/release-images";
31
32
  import { GENERATED_MARKER } from "../discovery/files";
32
33
  import type { SecurityGroup } from "./security";
33
34
  import type { OpSetupStep } from "../lexicon";
@@ -108,6 +109,12 @@ export interface ReleaseWorkflowInput {
108
109
  imageArchives?: string[];
109
110
  /** `release.lane` (#4692): the gate's green lane. */
110
111
  lane?: string;
112
+ /**
113
+ * `release.publish` (#4767). On GitHub, a `forge: "github"` target with no
114
+ * `tokenEnv` reads `GITHUB_TOKEN`, so the publish job sets it to the job's
115
+ * token unless `release.workflow.env` sets it.
116
+ */
117
+ publish?: ReadonlyArray<{ type: string; forge?: string; tokenEnv?: string }>;
111
118
  }
112
119
 
113
120
  /** The flags `chant release publish` gets under the groups. */
@@ -135,9 +142,14 @@ export function renderReleaseWorkflow(input: ReleaseWorkflowInput): string {
135
142
  const after = p.after ?? [];
136
143
  const images = input.images === true;
137
144
  const extra = jobExtras(p, input.forge);
145
+ // #4767: Forgejo's job token is not a GitHub token, and GitLab has no such expression.
146
+ const forgeToken =
147
+ input.forge === "github" && p.env?.GITHUB_TOKEN === undefined && (input.publish ?? []).some((t) => t.type === "forge" && t.forge === "github" && !t.tokenEnv)
148
+ ? [" GITHUB_TOKEN: ${{ github.token }}"]
149
+ : [];
138
150
  if (p.trigger === "dispatch") {
139
151
  const archives = images ? (input.imageArchives ?? []).map((a) => (root ? `${root}/${a.replace(/^\.\//, "")}` : a.replace(/^\.\//, ""))) : [];
140
- const o = { chant, install, build, root, verify, flags, after, images, archives, forge: input.forge, extra, gate: p.gate ?? "last-green", ...(input.lane ? { lane: input.lane } : {}) };
152
+ const o = { chant, install, build, root, verify, flags, after, images, archives, forge: input.forge, extra, forgeToken, gate: p.gate ?? "last-green", ...(input.lane ? { lane: input.lane } : {}) };
141
153
  return input.forge === "gitlab" ? renderGitlabDispatch(o) : renderGithubDispatch(o);
142
154
  }
143
155
  // #4657: the images are built from the release, so chant/lifecycle is fetched before them and the build after.
@@ -194,7 +206,7 @@ export function renderReleaseWorkflow(input: ReleaseWorkflowInput): string {
194
206
  " publish:",
195
207
  " runs-on: ubuntu-latest",
196
208
  ...(root ? [" defaults:", " run:", ` working-directory: ${root}`] : []),
197
- ...extra.githubEnv([]),
209
+ ...extra.githubEnv(forgeToken),
198
210
  " steps:",
199
211
  ...githubSetup(),
200
212
  ` - run: ${install}`,
@@ -297,6 +309,8 @@ interface DispatchInput {
297
309
  gate: "last-green" | "head";
298
310
  lane?: string;
299
311
  extra: JobExtras;
312
+ /** The publish job's `GITHUB_TOKEN` line for a GitHub forge target (#4767), or nothing. */
313
+ forgeToken: string[];
300
314
  }
301
315
 
302
316
  /** The workflow artifact the cut job hands its image archives on in. */
@@ -413,7 +427,7 @@ function renderGithubDispatch(o: DispatchInput): string {
413
427
  " needs: [gate, cut]",
414
428
  " runs-on: ubuntu-latest",
415
429
  ...defaults,
416
- ...o.extra.githubEnv([]),
430
+ ...o.extra.githubEnv(o.forgeToken),
417
431
  " steps:",
418
432
  ...githubSetup(commit),
419
433
  ` - run: ${o.install}`,
@@ -538,8 +552,9 @@ export async function runReleaseWorkflow(ctx: import("../cli/registry").CommandC
538
552
  groups,
539
553
  workspaceRoot,
540
554
  ...(release?.workflow ? { pipeline: release.workflow } : {}),
541
- ...((release?.images?.length ?? 0) > 0 ? { images: true, imageArchives: release!.images!.map((i) => i.archive) } : {}),
555
+ ...((release?.images?.length ?? 0) > 0 ? { images: true, imageArchives: resolveReleaseImages(release!.images!).map((i) => i.archive) } : {}),
542
556
  ...(release?.lane ? { lane: release.lane } : {}),
557
+ ...(release?.publish ? { publish: release.publish } : {}),
543
558
  ...(args.ciInstall ? { install: args.ciInstall } : {}),
544
559
  ...(args.buildCommand ? { build: args.buildCommand } : {}),
545
560
  ...(args.ciChant ? { chant: args.ciChant } : {}),