@intentius/chant 0.124.87 → 0.124.88

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 (342) hide show
  1. package/dist/action-pins.d.ts +1 -0
  2. package/dist/action-pins.d.ts.map +1 -1
  3. package/dist/action-pins.js +2 -0
  4. package/dist/actor.d.ts +12 -0
  5. package/dist/actor.d.ts.map +1 -0
  6. package/dist/actor.js +18 -0
  7. package/dist/bundle-check.d.ts +20 -5
  8. package/dist/bundle-check.d.ts.map +1 -1
  9. package/dist/bundle-check.js +20 -5
  10. package/dist/chant-install.d.ts +98 -0
  11. package/dist/chant-install.d.ts.map +1 -1
  12. package/dist/chant-install.js +204 -2
  13. package/dist/ci-commit.d.ts +1 -1
  14. package/dist/ci-commit.d.ts.map +1 -1
  15. package/dist/ci-commit.js +1 -2
  16. package/dist/ci-control.d.ts +1 -1
  17. package/dist/ci-control.d.ts.map +1 -1
  18. package/dist/ci-control.js +1 -1
  19. package/dist/ci-evidence-claims.d.ts +59 -0
  20. package/dist/ci-evidence-claims.d.ts.map +1 -0
  21. package/dist/ci-evidence-claims.js +87 -0
  22. package/dist/ci-evidence-from-job.d.ts +103 -0
  23. package/dist/ci-evidence-from-job.d.ts.map +1 -0
  24. package/dist/ci-evidence-from-job.js +162 -0
  25. package/dist/ci-evidence-jobs.d.ts +39 -4
  26. package/dist/ci-evidence-jobs.d.ts.map +1 -1
  27. package/dist/ci-evidence-jobs.js +38 -4
  28. package/dist/ci-handover.d.ts +12 -0
  29. package/dist/ci-handover.d.ts.map +1 -1
  30. package/dist/ci-handover.js +15 -3
  31. package/dist/ci-identity.d.ts +32 -6
  32. package/dist/ci-identity.d.ts.map +1 -1
  33. package/dist/ci-identity.js +40 -8
  34. package/dist/ci-image.d.ts +47 -9
  35. package/dist/ci-image.d.ts.map +1 -1
  36. package/dist/ci-image.js +45 -18
  37. package/dist/ci-jobs.d.ts +1 -1
  38. package/dist/ci-jobs.d.ts.map +1 -1
  39. package/dist/ci-jobs.js +7 -2
  40. package/dist/ci-login.d.ts +75 -13
  41. package/dist/ci-login.d.ts.map +1 -1
  42. package/dist/ci-login.js +89 -37
  43. package/dist/ci-product-words.d.ts +20 -1
  44. package/dist/ci-product-words.d.ts.map +1 -1
  45. package/dist/ci-product-words.js +27 -1
  46. package/dist/ci-product.d.ts +21 -2
  47. package/dist/ci-product.d.ts.map +1 -1
  48. package/dist/ci-product.js +21 -2
  49. package/dist/cli/handlers/approve-confirm.d.ts +14 -0
  50. package/dist/cli/handlers/approve-confirm.d.ts.map +1 -1
  51. package/dist/cli/handlers/approve-confirm.js +46 -0
  52. package/dist/cli/handlers/build.d.ts +1 -1
  53. package/dist/cli/handlers/build.d.ts.map +1 -1
  54. package/dist/cli/handlers/build.js +22 -1
  55. package/dist/cli/handlers/ci-check.d.ts.map +1 -1
  56. package/dist/cli/handlers/ci-check.js +21 -1
  57. package/dist/cli/handlers/ci-evidence.d.ts.map +1 -1
  58. package/dist/cli/handlers/ci-evidence.js +227 -18
  59. package/dist/cli/handlers/ci-forge-check.d.ts.map +1 -1
  60. package/dist/cli/handlers/ci-forge-check.js +34 -17
  61. package/dist/cli/handlers/generated-check.d.ts +3 -0
  62. package/dist/cli/handlers/generated-check.d.ts.map +1 -0
  63. package/dist/cli/handlers/generated-check.js +41 -0
  64. package/dist/cli/handlers/lifecycle.d.ts.map +1 -1
  65. package/dist/cli/handlers/lifecycle.js +3 -0
  66. package/dist/cli/handlers/local-chant.d.ts +13 -0
  67. package/dist/cli/handlers/local-chant.d.ts.map +1 -1
  68. package/dist/cli/handlers/local-chant.js +42 -1
  69. package/dist/cli/handlers/pr.d.ts.map +1 -1
  70. package/dist/cli/handlers/pr.js +42 -5
  71. package/dist/cli/handlers/run-wave.js +8 -0
  72. package/dist/cli/main.d.ts.map +1 -1
  73. package/dist/cli/main.js +38 -4
  74. package/dist/cli/parse-args.d.ts.map +1 -1
  75. package/dist/cli/parse-args.js +66 -0
  76. package/dist/cli/registry.d.ts +24 -0
  77. package/dist/cli/registry.d.ts.map +1 -1
  78. package/dist/components/check-hooks.d.ts +10 -0
  79. package/dist/components/check-hooks.d.ts.map +1 -1
  80. package/dist/components/check-hooks.js +18 -0
  81. package/dist/components/pr-checks.d.ts +105 -0
  82. package/dist/components/pr-checks.d.ts.map +1 -0
  83. package/dist/components/pr-checks.js +119 -0
  84. package/dist/components/pr-pipeline.d.ts +34 -0
  85. package/dist/components/pr-pipeline.d.ts.map +1 -1
  86. package/dist/components/pr-pipeline.js +14 -1
  87. package/dist/components/product-pipeline.d.ts +16 -1
  88. package/dist/components/product-pipeline.d.ts.map +1 -1
  89. package/dist/components/product-pipeline.js +17 -2
  90. package/dist/components/product-plan.d.ts +257 -4
  91. package/dist/components/product-plan.d.ts.map +1 -1
  92. package/dist/components/product-plan.js +241 -11
  93. package/dist/config.d.ts +10 -6
  94. package/dist/config.d.ts.map +1 -1
  95. package/dist/config.js +11 -6
  96. package/dist/control/consumers.d.ts +6 -0
  97. package/dist/control/consumers.d.ts.map +1 -1
  98. package/dist/control/consumers.js +6 -0
  99. package/dist/dead-guards.d.ts.map +1 -1
  100. package/dist/dead-guards.js +9 -6
  101. package/dist/discovery/files.d.ts +1 -1
  102. package/dist/discovery/files.js +1 -1
  103. package/dist/drift-issue.d.ts +20 -3
  104. package/dist/drift-issue.d.ts.map +1 -1
  105. package/dist/drift-issue.js +16 -0
  106. package/dist/drift-record.d.ts +45 -5
  107. package/dist/drift-record.d.ts.map +1 -1
  108. package/dist/drift-record.js +27 -6
  109. package/dist/floor-table.d.ts +6 -6
  110. package/dist/floor-table.d.ts.map +1 -1
  111. package/dist/floor-table.data.d.ts.map +1 -1
  112. package/dist/floor-table.data.js +58 -21
  113. package/dist/floor-table.js +10 -7
  114. package/dist/forge-check/contract.d.ts +8 -0
  115. package/dist/forge-check/contract.d.ts.map +1 -1
  116. package/dist/forge-check/contract.js +4 -1
  117. package/dist/forge-check/index.d.ts +2 -0
  118. package/dist/forge-check/index.d.ts.map +1 -1
  119. package/dist/forge-check/index.js +2 -0
  120. package/dist/forge-flags.d.ts +10 -0
  121. package/dist/forge-flags.d.ts.map +1 -1
  122. package/dist/forge-flags.js +31 -0
  123. package/dist/forge-remote.d.ts +47 -0
  124. package/dist/forge-remote.d.ts.map +1 -0
  125. package/dist/forge-remote.js +69 -0
  126. package/dist/generated-check.d.ts +74 -0
  127. package/dist/generated-check.d.ts.map +1 -0
  128. package/dist/generated-check.js +216 -0
  129. package/dist/lexicon.d.ts +16 -0
  130. package/dist/lexicon.d.ts.map +1 -1
  131. package/dist/lifecycle/publish-npm.d.ts +15 -0
  132. package/dist/lifecycle/publish-npm.d.ts.map +1 -1
  133. package/dist/lifecycle/publish-npm.js +49 -3
  134. package/dist/lifecycle/release-images.d.ts +22 -1
  135. package/dist/lifecycle/release-images.d.ts.map +1 -1
  136. package/dist/lifecycle/release-images.js +27 -3
  137. package/dist/lifecycle/release-ledger.d.ts +4 -3
  138. package/dist/lifecycle/release-ledger.d.ts.map +1 -1
  139. package/dist/lifecycle/release-ledger.js +3 -2
  140. package/dist/local-chant.d.ts +57 -3
  141. package/dist/local-chant.d.ts.map +1 -1
  142. package/dist/local-chant.js +122 -13
  143. package/dist/op/op-waves-evidence-jobs.d.ts +92 -0
  144. package/dist/op/op-waves-evidence-jobs.d.ts.map +1 -0
  145. package/dist/op/op-waves-evidence-jobs.js +112 -0
  146. package/dist/op/op-waves-evidence.d.ts +12 -1
  147. package/dist/op/op-waves-evidence.d.ts.map +1 -1
  148. package/dist/op/op-waves-evidence.js +23 -2
  149. package/dist/op/op-waves-run.d.ts +12 -1
  150. package/dist/op/op-waves-run.d.ts.map +1 -1
  151. package/dist/op/op-waves-run.js +54 -3
  152. package/dist/op/op-waves.d.ts +8 -0
  153. package/dist/op/op-waves.d.ts.map +1 -1
  154. package/dist/op/op-waves.js +10 -0
  155. package/dist/op/schedule-overdue.d.ts +39 -2
  156. package/dist/op/schedule-overdue.d.ts.map +1 -1
  157. package/dist/op/schedule-overdue.js +89 -7
  158. package/dist/pr-forge-reads.d.ts +21 -1
  159. package/dist/pr-forge-reads.d.ts.map +1 -1
  160. package/dist/pr-forge-reads.js +19 -1
  161. package/dist/pr-forge.d.ts +7 -1
  162. package/dist/pr-forge.d.ts.map +1 -1
  163. package/dist/pr-forge.js +7 -2
  164. package/dist/pr-plan-note.d.ts +24 -0
  165. package/dist/pr-plan-note.d.ts.map +1 -1
  166. package/dist/pr-plan-note.js +11 -1
  167. package/dist/pr-plan-record.d.ts +47 -0
  168. package/dist/pr-plan-record.d.ts.map +1 -0
  169. package/dist/pr-plan-record.js +89 -0
  170. package/dist/pr-post.d.ts +40 -0
  171. package/dist/pr-post.d.ts.map +1 -1
  172. package/dist/pr-post.js +79 -6
  173. package/dist/pr-requires.d.ts +8 -0
  174. package/dist/pr-requires.d.ts.map +1 -1
  175. package/dist/pr-requires.js +3 -1
  176. package/dist/ref-gate-init.d.ts +76 -0
  177. package/dist/ref-gate-init.d.ts.map +1 -0
  178. package/dist/ref-gate-init.js +144 -0
  179. package/dist/ref-gate-rules.d.ts +19 -0
  180. package/dist/ref-gate-rules.d.ts.map +1 -0
  181. package/dist/ref-gate-rules.js +17 -0
  182. package/dist/release-floors.d.ts +64 -16
  183. package/dist/release-floors.d.ts.map +1 -1
  184. package/dist/release-floors.js +65 -17
  185. package/dist/state-migration.d.ts +24 -1
  186. package/dist/state-migration.d.ts.map +1 -1
  187. package/dist/state-migration.js +39 -3
  188. package/dist/state-unlock.d.ts +32 -1
  189. package/dist/state-unlock.d.ts.map +1 -1
  190. package/dist/state-unlock.js +31 -0
  191. package/dist/wave-runtime.mjs +292 -285
  192. package/dist/workspace/ci-green-cli.d.ts.map +1 -1
  193. package/dist/workspace/ci-green-cli.js +13 -7
  194. package/dist/workspace/drift-cli.d.ts +1 -1
  195. package/dist/workspace/drift-cli.d.ts.map +1 -1
  196. package/dist/workspace/drift-cli.js +5 -12
  197. package/dist/workspace/forge-work.d.ts +3 -2
  198. package/dist/workspace/forge-work.d.ts.map +1 -1
  199. package/dist/workspace/forge-work.js +7 -17
  200. package/dist/workspace/lexicon-outputs.js +2 -2
  201. package/dist/workspace/release-workflow.d.ts +26 -3
  202. package/dist/workspace/release-workflow.d.ts.map +1 -1
  203. package/dist/workspace/release-workflow.js +48 -6
  204. package/dist/workspace/trust/check-evidence-report.d.ts +18 -0
  205. package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -1
  206. package/dist/workspace/trust/check-evidence-report.js +13 -0
  207. package/dist/workspace/trust/check-evidence.d.ts +13 -1
  208. package/dist/workspace/trust/check-evidence.d.ts.map +1 -1
  209. package/dist/workspace/trust/check-evidence.js +8 -3
  210. package/dist/workspace/trust/evidence.d.ts +5 -0
  211. package/dist/workspace/trust/evidence.d.ts.map +1 -1
  212. package/dist/workspace/trust/evidence.js +5 -0
  213. package/dist/workspace/trust/open-evidence.d.ts +67 -0
  214. package/dist/workspace/trust/open-evidence.d.ts.map +1 -0
  215. package/dist/workspace/trust/open-evidence.js +92 -0
  216. package/dist/workspace/trust/ref-gate-cli.d.ts.map +1 -1
  217. package/dist/workspace/trust/ref-gate-cli.js +65 -3
  218. package/dist/workspace/trust/ref-gate.d.ts +61 -2
  219. package/dist/workspace/trust/ref-gate.d.ts.map +1 -1
  220. package/dist/workspace/trust/ref-gate.js +72 -7
  221. package/package.json +1 -1
  222. package/src/action-pins.ts +2 -0
  223. package/src/actor.test.ts +12 -0
  224. package/src/actor.ts +19 -0
  225. package/src/bundle-check.test.ts +22 -0
  226. package/src/bundle-check.ts +33 -5
  227. package/src/chant-install.test.ts +109 -1
  228. package/src/chant-install.ts +243 -2
  229. package/src/ci-commit.test.ts +51 -5
  230. package/src/ci-commit.ts +1 -2
  231. package/src/ci-control.ts +1 -0
  232. package/src/ci-evidence-claims.ts +102 -0
  233. package/src/ci-evidence-from-job.test.ts +147 -0
  234. package/src/ci-evidence-from-job.ts +195 -0
  235. package/src/ci-evidence-jobs.ts +41 -4
  236. package/src/ci-handover.ts +16 -3
  237. package/src/ci-identity.test.ts +3 -3
  238. package/src/ci-identity.ts +51 -11
  239. package/src/ci-image.test.ts +60 -10
  240. package/src/ci-image.ts +78 -19
  241. package/src/ci-jobs.ts +7 -2
  242. package/src/ci-login.test.ts +131 -3
  243. package/src/ci-login.token-drop.test.ts +204 -0
  244. package/src/ci-login.ts +137 -39
  245. package/src/ci-product-words.ts +30 -0
  246. package/src/ci-product.ts +26 -1
  247. package/src/cli/commands/__fixtures__/source-dir-root/migrations/0001-init/backfill.ts +3 -0
  248. package/src/cli/handlers/approve-confirm.test.ts +35 -0
  249. package/src/cli/handlers/approve-confirm.ts +44 -0
  250. package/src/cli/handlers/build-source-dir.test.ts +4 -0
  251. package/src/cli/handlers/build.ts +20 -2
  252. package/src/cli/handlers/ci-check.ts +19 -1
  253. package/src/cli/handlers/ci-evidence-open.test.ts +164 -0
  254. package/src/cli/handlers/ci-evidence.ts +210 -16
  255. package/src/cli/handlers/ci-forge-check.ts +22 -9
  256. package/src/cli/handlers/generated-check.ts +39 -0
  257. package/src/cli/handlers/lifecycle.test.ts +20 -0
  258. package/src/cli/handlers/lifecycle.ts +4 -0
  259. package/src/cli/handlers/local-chant.ts +39 -1
  260. package/src/cli/handlers/pr.ts +43 -5
  261. package/src/cli/handlers/run-wave.ts +7 -0
  262. package/src/cli/main.ts +38 -4
  263. package/src/cli/parse-args.ts +46 -0
  264. package/src/cli/registry.ts +24 -0
  265. package/src/components/check-hooks.ts +22 -0
  266. package/src/components/check-report-summary.test.ts +78 -0
  267. package/src/components/pr-checks.ts +159 -0
  268. package/src/components/pr-pipeline.ts +41 -1
  269. package/src/components/product-pipeline.ts +25 -3
  270. package/src/components/product-plan.test.ts +102 -1
  271. package/src/components/product-plan.ts +416 -15
  272. package/src/config.ts +13 -8
  273. package/src/control/consumers.ts +7 -0
  274. package/src/dead-guards.test.ts +27 -5
  275. package/src/dead-guards.ts +9 -6
  276. package/src/discovery/files.ts +1 -1
  277. package/src/drift-issue.test.ts +29 -1
  278. package/src/drift-issue.ts +28 -3
  279. package/src/drift-record.test.ts +25 -0
  280. package/src/drift-record.ts +55 -6
  281. package/src/floor-table.data.ts +58 -21
  282. package/src/floor-table.ts +12 -9
  283. package/src/forge-check/contract.ts +11 -1
  284. package/src/forge-check/forge-check.test.ts +8 -0
  285. package/src/forge-check/index.ts +2 -0
  286. package/src/forge-flags.test.ts +25 -1
  287. package/src/forge-flags.ts +34 -0
  288. package/src/forge-remote.test.ts +37 -0
  289. package/src/forge-remote.ts +79 -0
  290. package/src/generated-check.e2e.test.ts +98 -0
  291. package/src/generated-check.test.ts +104 -0
  292. package/src/generated-check.ts +269 -0
  293. package/src/lexicon.ts +17 -0
  294. package/src/lifecycle/publish-npm.ts +56 -3
  295. package/src/lifecycle/release-catalog.test.ts +2 -2
  296. package/src/lifecycle/release-images-dockerfile.test.ts +20 -0
  297. package/src/lifecycle/release-images.test.ts +44 -0
  298. package/src/lifecycle/release-images.ts +39 -3
  299. package/src/lifecycle/release-ledger.ts +4 -3
  300. package/src/local-chant.e2e.test.ts +81 -6
  301. package/src/local-chant.test.ts +22 -3
  302. package/src/local-chant.ts +130 -13
  303. package/src/op/op-waves-evidence-jobs.ts +134 -0
  304. package/src/op/op-waves-evidence.test.ts +36 -3
  305. package/src/op/op-waves-evidence.ts +23 -3
  306. package/src/op/op-waves-run.ts +57 -2
  307. package/src/op/op-waves.ts +11 -0
  308. package/src/op/schedule-overdue.test.ts +83 -1
  309. package/src/op/schedule-overdue.ts +107 -9
  310. package/src/pr-forge-reads-compare.test.ts +2 -1
  311. package/src/pr-forge-reads.ts +37 -1
  312. package/src/pr-forge.ts +14 -3
  313. package/src/pr-plan-note.ts +32 -3
  314. package/src/pr-plan-record.test.ts +75 -0
  315. package/src/pr-plan-record.ts +101 -0
  316. package/src/pr-post-plan-note.test.ts +60 -0
  317. package/src/pr-post.test.ts +30 -0
  318. package/src/pr-post.ts +110 -6
  319. package/src/pr-requires.test.ts +20 -0
  320. package/src/pr-requires.ts +10 -1
  321. package/src/ref-gate-init.ts +189 -0
  322. package/src/ref-gate-rules.ts +26 -0
  323. package/src/release-floors.ts +86 -17
  324. package/src/state-migration-record.test.ts +90 -0
  325. package/src/state-migration.test.ts +1 -1
  326. package/src/state-migration.ts +52 -3
  327. package/src/state-unlock.test.ts +33 -1
  328. package/src/state-unlock.ts +49 -1
  329. package/src/workspace/ci-green-cli.ts +12 -6
  330. package/src/workspace/drift-cli.ts +6 -18
  331. package/src/workspace/forge-work.ts +7 -14
  332. package/src/workspace/lexicon-outputs.ts +2 -2
  333. package/src/workspace/release-workflow.test.ts +70 -0
  334. package/src/workspace/release-workflow.ts +56 -8
  335. package/src/workspace/trust/check-evidence-report.ts +24 -0
  336. package/src/workspace/trust/check-evidence.ts +17 -5
  337. package/src/workspace/trust/evidence.ts +5 -0
  338. package/src/workspace/trust/open-evidence.ts +129 -0
  339. package/src/workspace/trust/ref-gate-cli.ts +59 -3
  340. package/src/workspace/trust/ref-gate-pieces.test.ts +175 -0
  341. package/src/workspace/trust/ref-gate.e2e.test.ts +17 -0
  342. package/src/workspace/trust/ref-gate.ts +87 -6
@@ -35,8 +35,15 @@ import type { ForgeKind } from "../pr-forge";
35
35
  import type { CiRunner } from "../ci-jobs";
36
36
  import type { CiProductWords } from "../ci-product-words";
37
37
  import type { PrPlanNoteWords } from "../pr-plan-note";
38
- import { assertPipelineEvidence, evidenceIdTokens, evidenceKeyEnv, evidenceKeyless, planEvidenceLines, type PipelineEvidence } from "../ci-evidence-jobs";
38
+ import { assertPipelineEvidence, evidenceIdTokens, evidenceKeyEnv, evidenceKeyless, gitlabOpenEvidenceDir, openEvidenceLines, planEvidenceLines, type PipelineEvidence } from "../ci-evidence-jobs";
39
39
  import { gitlabPlanJobName, PR_LOOP_REPORT_DIR, PR_PLAN_NOTE_JOB, prLoopPassedEnv, prLoopPostJob, prLoopRunner, type PrLoopPipelineOptions } from "./pr-pipeline";
40
+ import { GITHUB_JOB_TOKEN } from "../ci-jobs";
41
+ import { cloudLogin, type CloudLoginSpec } from "../ci-login";
42
+ import type { OpWaveRunStep } from "../lexicon";
43
+ import { controlNoteCheckout, type ControlNoteCheckout, type ControlTarget } from "../control/dispatch";
44
+ import { commentLine, productStatusContext } from "../ci-product-words";
45
+ import { PLAN_WATCHES_ENV, scheduledWatchProblem, type ScheduledWatch } from "../op/schedule-overdue";
46
+ import { PLAN_RUN_OP, PLAN_RUN_RECORD_FILE } from "../pr-plan-record";
40
47
 
41
48
  /** The variable the plan-note job reads the product's note words from (#4799), as JSON. Set from the pipeline, never from the report. */
42
49
  export const PR_PLAN_NOTE_WORDS_ENV = "CHANT_PLAN_NOTE_WORDS";
@@ -56,8 +63,60 @@ export interface ProductPlanTarget {
56
63
  * tokens are dropped.
57
64
  */
58
65
  writeProbe?: string;
66
+ /**
67
+ * This target's cloud login (#4899, #4931), in place of the plan's
68
+ * {@link ProductPlanOptions.login}: chant's login from the OIDC token file
69
+ * (`@intentius/chant/ci-login`, #4788), run before the write probe.
70
+ */
71
+ login?: CloudLoginSpec;
72
+ /** OIDC tokens this target's plan job requests besides its login's, `{ <variable>: <audience> }`, in place of the plan's {@link ProductPlanOptions.idTokens}. */
73
+ idTokens?: Record<string, string>;
74
+ }
75
+
76
+ /**
77
+ * A step a product's plan job runs before its setup lines (#4899): a shell
78
+ * line (`run`), or on GitHub and Forgejo an action (`uses`), such as a
79
+ * cache restore. A `run` step starts without the forge tokens, as every
80
+ * step after the checkout does. GitLab has no actions, so it leaves a
81
+ * `uses` step out; its generator's `cache` is GitLab's cache.
82
+ */
83
+ export interface ProductPlanSetupStep {
84
+ name?: string;
85
+ run?: string;
86
+ uses?: string;
87
+ with?: Record<string, unknown>;
88
+ env?: Record<string, string>;
59
89
  }
60
90
 
91
+ /**
92
+ * The comment re-plan (#4899): `/<product> <plan word>` (or a words' alias
93
+ * for the plan command) plans an open pull request again. With `targets`,
94
+ * `/<product> plan <target>` plans that target alone, and the bare command
95
+ * plans every target. Without targets, the one word after the command
96
+ * reaches the plan verb as {@link PLAN_ARGUMENT_ENV}, such as terragucci's
97
+ * root.
98
+ */
99
+ export interface ProductPlanReplanJob {
100
+ /** `replan` or `replan-<target>` on GitHub and Forgejo, `replan` or `<target>-replan` on GitLab. */
101
+ jobName: string;
102
+ /** `replan-note` or `replan-note-<target>`, `<target>-replan-note` on GitLab. */
103
+ noteJobName: string;
104
+ /** The comments it answers: the plan command, then each alias for it that is on. */
105
+ comments: string[];
106
+ /** Aliases whose words name a variable that turns them on, with that variable. */
107
+ gated: Array<{ comment: string; when: string }>;
108
+ /** The note job's command and variables, which read the pull request and head from the re-plan job. */
109
+ post: { command: string; env: Record<string, string>; setup?: string[] };
110
+ /** The artifact the note job (GitHub, Forgejo) or the re-plan job (GitLab) keeps the directory as. */
111
+ artifact: string;
112
+ }
113
+
114
+ /** The variable a comment re-plan's one argument reaches the plan verb in (#4899). Empty on a pull request's own plan. */
115
+ export const PLAN_ARGUMENT_ENV = "CHANT_PLAN_ARGUMENT";
116
+
117
+ /** The file the note job's own lines write extra notices to, one a line (#4931): `pr-post` adds them under the note's counts. */
118
+ export const PLAN_NOTE_NOTICES_ENV = "CHANT_PLAN_NOTE_NOTICES";
119
+
61
120
  /** The product plan (#4799): {@link ProductPipelineOptions.plan}. */
62
121
  export interface ProductPlanOptions {
63
122
  /**
@@ -84,8 +143,114 @@ export interface ProductPlanOptions {
84
143
  noteWords?: PrPlanNoteWords;
85
144
  /** The workflow's name (GitHub and Forgejo) or the pipeline's (GitLab). Default `chant-pr-<env>`. */
86
145
  workflow?: string;
146
+ /**
147
+ * Variables for the whole plan job (#4899), every step of it: the job's
148
+ * `env` on GitHub and Forgejo, its `variables` on GitLab. A forge token's
149
+ * name is refused.
150
+ */
151
+ env?: Record<string, string>;
152
+ /**
153
+ * The plan job's cloud login (#4899, #4931), for every target without
154
+ * its own: chant's login from the OIDC token file
155
+ * (`@intentius/chant/ci-login`, #4788), after the setup lines and before
156
+ * the write probe. The job asks for the OIDC token: `id-token: write`
157
+ * (Forgejo `enable-openid-connect`), GitLab `id_tokens`.
158
+ */
159
+ login?: CloudLoginSpec;
160
+ /**
161
+ * OIDC tokens the plan job requests for a login the product's command
162
+ * does itself (#4931), `{ <variable>: <audience> }`: GitLab `id_tokens`,
163
+ * and `id-token: write` on GitHub and Forgejo, where the command asks the
164
+ * forge for its token by audience.
165
+ */
166
+ idTokens?: Record<string, string>;
167
+ /**
168
+ * Post the plan status pending ("planning") before the checkout (#4899),
169
+ * on GitHub and Forgejo, from a step that alone holds the job's token.
170
+ * The job asks for `statuses: write`. GitLab's plan job holds no token,
171
+ * so there the pipeline's own status says the plan runs.
172
+ */
173
+ pending?: boolean;
174
+ /**
175
+ * The control repo the plan reads (#4899), as terragucci reads it for
176
+ * estate ownership: chant's read-only fetch of its `chant/lifecycle`
177
+ * (`controlNoteCheckout`), right after the checkout and before any of the
178
+ * change's code runs. It sets `CHANT_CONTROL_DIR`.
179
+ */
180
+ controlRead?: ControlTarget;
181
+ /** Steps after the checkout and the control read, before the setup lines (#4899): a cache restore, an install. */
182
+ setup?: ProductPlanSetupStep[];
183
+ /**
184
+ * A shell line run after the plan verb whatever its exit (#4899), such as
185
+ * sql-yodeler's `yodel report {target} --out {output}/report`, in the plan
186
+ * step, so it is not a step after the change's code. `{target}` and
187
+ * `{output}` are filled as in `command`. The step then exits with the plan
188
+ * verb's status. What it writes under `{output}` is kept with the report.
189
+ */
190
+ report?: string;
191
+ /**
192
+ * One run at a time per pull request (#4899): a workflow-level
193
+ * `concurrency` group `<group>-<pull request>` on GitHub and Forgejo
194
+ * (default group: the workflow's name), cancelling the run before it when
195
+ * `cancelInProgress`. A comment's run, with `replan`, is in a group of its
196
+ * own comment, so a comment never cancels a plan. On GitLab
197
+ * `cancelInProgress` makes the plan jobs `interruptible`, which GitLab's
198
+ * auto-cancel of redundant pipelines stops.
199
+ */
200
+ concurrency?: { group?: string; cancelInProgress?: boolean };
201
+ /**
202
+ * The comment re-plan (#4899, {@link ProductPlanReplanJob}). The words
203
+ * need a plan command. On GitHub the commenter must be an owner, member or
204
+ * collaborator; on Forgejo the job asks the forge whether the commenter
205
+ * can write. On GitLab the note-commands job (`noteCommands`) starts a
206
+ * pipeline of the target branch for the comment, which runs the re-plan
207
+ * jobs whose target the comment names.
208
+ */
209
+ replan?: boolean;
210
+ /**
211
+ * Lines the note job runs (#4931), on GitHub and Forgejo, in the job that
212
+ * holds the token and none of the change's code: `before` after the report
213
+ * is taken back and before `pr-post`, `after` once it posted. A `before`
214
+ * line may write notices, one a line, to the file
215
+ * `$CHANT_PLAN_NOTE_NOTICES` names, and `pr-post` adds them under the
216
+ * note's counts, such as terragucci's notice naming whose review does not
217
+ * count. They reach the job's token as `GITHUB_TOKEN`. GitLab's note job
218
+ * posts every open merge request's note in one run, so it takes none.
219
+ */
220
+ noteSteps?: { before?: string[]; after?: string[] };
221
+ /**
222
+ * The product's own scheduled jobs the note job checks for having stopped
223
+ * (#4888), such as terragucci's drift job: each a `ScheduledWatch` with
224
+ * its cron, the files the product's generator wrote it in, and on GitLab
225
+ * its schedule selector. The note job holds the token the plan job lacks,
226
+ * so `pr-post` asks the forge when each last ran, in its checkout of the
227
+ * target branch's commit, and adds the line for one that is overdue under
228
+ * the note's counts. They reach it as `CHANT_PLAN_WATCHES`, from the
229
+ * pipeline, never from the plan job's report.
230
+ */
231
+ watches?: ScheduledWatch[];
232
+ /**
233
+ * A run record for the plan job (#4899), as `chant ci run plan --in-place`
234
+ * writes one for `pr-plan`'s: Op `pr-plan` in the run ledger,
235
+ * `<env>/runs__pr-plan.jsonl` on `chant/lifecycle`. The plan job holds no
236
+ * token, so its plan step writes the record into the hand-off
237
+ * ({@link PLAN_RUN_RECORD_FILE}) once the plan verb and the report line ran,
238
+ * and the note job, which holds the token, appends it to the ledger and
239
+ * pushes it with the note (`pr-post --record-run <plan job>`). The note job
240
+ * reads the record as data: it keeps the record's id, times and exit code,
241
+ * and names the op, environment, commit, run and status from what it knows
242
+ * itself. The note job then asks `contents: write` on GitHub and Forgejo.
243
+ * Unsigned, as `pr-plan`'s is (#4328). Default off.
244
+ */
245
+ record?: boolean;
87
246
  }
88
247
 
248
+ /** The file a product plan job writes its run record to under the hand-off directory, and the Op it is recorded under: `pr-plan`'s (#4899, ../pr-plan-record.ts). */
249
+ export { PLAN_RUN_OP, PLAN_RUN_RECORD_FILE } from "../pr-plan-record";
250
+
251
+ /** The variable the plan step reads the record's op, environment and labels from (#4899), as JSON. */
252
+ export const PLAN_RUN_RECORD_ENV = "CHANT_PLAN_RECORD";
253
+
89
254
  /** One plan job and its note job, for one target or for the whole pipeline (#4799). */
90
255
  export interface ProductPlanJob {
91
256
  /** The target, when the plan has targets. Also the note's and the status's member. */
@@ -112,12 +277,35 @@ export interface ProductPlanJob {
112
277
  * With the pipeline's `evidence` (#4870): the lines that sign the plan
113
278
  * job's `plan` and `policy` checks from its report, and their variables
114
279
  * (the runner key from its secret). GitHub and Forgejo run them in the
115
- * note job before `pr-post`; GitLab in a job of their own after the plan
116
- * job, `evidenceJobName`. Signing keyless (#4869), the job asks for an
117
- * OIDC token: `idToken` (GitHub's `id-token: write`, Forgejo's
280
+ * note job before `pr-post`; GitLab in a job of their own, `jobName`, in
281
+ * the target branch's plan notes pipeline before the note job (#4914),
282
+ * which keeps `dir` as its artifact and names the environment
283
+ * `GITLAB_EVIDENCE_ENVIRONMENT`; the note job reads `dir`
284
+ * (`--evidence-dir`). Signing keyless (#4869), the job asks for an OIDC
285
+ * token: `idToken` (GitHub's `id-token: write`, Forgejo's
118
286
  * `enable-openid-connect`) or GitLab's `idTokens`.
119
287
  */
120
- evidence?: { lines: string[]; env: Record<string, string>; jobName?: string; idToken?: true; idTokens?: Record<string, { aud: string }> };
288
+ evidence?: { lines: string[]; env: Record<string, string>; jobName?: string; dir?: string; idToken?: true; idTokens?: Record<string, { aud: string }> };
289
+ /** The job's own variables (#4899), every step's. */
290
+ jobEnv?: Record<string, string>;
291
+ /** The cloud login's steps (#4931), after the setup lines and before the write probe. GitLab: their lines in the script. */
292
+ login?: OpWaveRunStep[];
293
+ /** The OIDC tokens the plan job requests (#4931), `{ <variable>: <audience> }`: the login's and the product's own. */
294
+ idTokens?: Record<string, string>;
295
+ /** The pending status posted before the checkout (#4899), on GitHub and Forgejo. */
296
+ pending?: { context: string; description: string };
297
+ /** The control repo read after the checkout (#4899). */
298
+ control?: ControlNoteCheckout;
299
+ /** The steps before the setup lines (#4899). */
300
+ setup?: ProductPlanSetupStep[];
301
+ /** The report line after the plan verb (#4899), `{target}` and `{output}` filled. */
302
+ report?: string;
303
+ /** The comment re-plan's jobs for this target (#4899). */
304
+ replan?: ProductPlanReplanJob;
305
+ /** The note job's own lines (#4931). */
306
+ noteSteps?: { before: string[]; after: string[] };
307
+ /** With `record` (#4899): the plan step writes the run record, `env` its op, environment and labels as {@link PLAN_RUN_RECORD_ENV}; the note job's command records it. */
308
+ record?: { env: Record<string, string> };
121
309
  }
122
310
 
123
311
  const TARGET_NAME = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
@@ -130,7 +318,7 @@ const NOT_WITH_PLAN: ReadonlyArray<[keyof PrLoopPipelineOptions, string]> = [
130
318
  ["locks", "the lock job reads pr-plan's report"],
131
319
  ["previewComment", "the comment preview re-runs pr-plan"],
132
320
  ["staleNotes", "the stale marking names one note per pipeline"],
133
- ["identity", "a target's cloud login is the product's, through its variables"],
321
+ ["identity", "the identity trade runs before pr-plan's checkout; give the product plan's login (or a target's) instead"],
134
322
  ["build", "the plan verb builds what it plans"],
135
323
  ["buildCommand", "the plan verb builds what it plans"],
136
324
  ["refresh", "--refresh is a pr-plan flag"],
@@ -139,7 +327,6 @@ const NOT_WITH_PLAN: ReadonlyArray<[keyof PrLoopPipelineOptions, string]> = [
139
327
  ["events", "--events-json is a pr-plan flag"],
140
328
  ["reportUrl", "--report-url is a pr-plan flag"],
141
329
  ["prEnvironment", "the pull request environment jobs run pr-env"],
142
- ["noteCommands", "the note-commands job starts pr-plan's comment jobs"],
143
330
  ["actionJob", "the action job is in chant build --pr-loop's workflow"],
144
331
  ["control", "the control read is the pr-plan report's cross-stack edges"],
145
332
  ["decide", "the description check reads pr-plan's report"],
@@ -157,6 +344,8 @@ export function productPlanJobs(forge: ForgeKind, env: string, loop: PrLoopPipel
157
344
  const value = loop[key];
158
345
  if (value !== undefined && value !== false) throw new Error(`the product plan (plan) takes no ${key}: ${why}`);
159
346
  }
347
+ // #4899: GitLab's comment commands start the re-plan, so the note-commands job comes with it.
348
+ if (loop.noteCommands && !plan.replan) throw new Error("the product plan (plan) takes no noteCommands without replan: the note-commands job starts its comment re-plan");
160
349
  if (!plan.command.trim()) throw new Error("the product plan's command is empty; give the product's plan verb");
161
350
  const targets = plan.targets;
162
351
  if (targets !== undefined && targets.length === 0) throw new Error("the product plan's targets are empty; leave targets out for one plan job");
@@ -168,12 +357,36 @@ export function productPlanJobs(forge: ForgeKind, env: string, loop: PrLoopPipel
168
357
  }
169
358
  const github = forge !== "gitlab";
170
359
  const shared = prLoopPassedEnv(forge, loop);
360
+ const jobEnv = plan.env ? prLoopPassedEnv(forge, { variables: plan.env }) : {};
361
+ for (const key of Object.keys(jobEnv)) {
362
+ if (key in shared) throw new Error(`the product plan's env ${key} is the pipeline's too; give it once`);
363
+ }
364
+ for (const s of plan.setup ?? []) {
365
+ if ((s.run === undefined) === (s.uses === undefined)) throw new Error(`the product plan's setup step ${JSON.stringify(s.name ?? s.run ?? s.uses ?? "")} gives one of run and uses`);
366
+ if (s.run !== undefined && s.with !== undefined) throw new Error(`the product plan's setup step ${JSON.stringify(s.name ?? s.run)} runs a line, and only a uses step takes with`);
367
+ }
368
+ if (plan.concurrency?.group !== undefined && !/^[A-Za-z0-9][A-Za-z0-9_.-]*$/.test(plan.concurrency.group)) throw new Error(`the product plan's concurrency group ${JSON.stringify(plan.concurrency.group)} is not a name of letters, digits, ., - and _`);
369
+ const replanComments = plan.replan ? replanCommentsOf(words) : undefined;
370
+ if (plan.noteSteps && !github && ((plan.noteSteps.before?.length ?? 0) > 0 || (plan.noteSteps.after?.length ?? 0) > 0)) {
371
+ throw new Error("the product plan's noteSteps run in the note job of one pull request, and GitLab's note job posts every open merge request's note in one run (pr-post --open); leave noteSteps out on GitLab");
372
+ }
171
373
  const planRunner = prLoopRunner(loop, "plan");
172
374
  const noteRunner = prLoopRunner(loop, "default");
173
375
  const base = github
174
376
  ? { BASE_SHA: "${{ github.event.pull_request.base.sha }}", PR_NUMBER: "${{ github.event.pull_request.number }}" }
175
377
  : { BASE_SHA: "$CI_MERGE_REQUEST_DIFF_BASE_SHA", PR_NUMBER: "$CI_MERGE_REQUEST_IID" };
176
- const noteWords: Record<string, string> = plan.noteWords ? { [PR_PLAN_NOTE_WORDS_ENV]: JSON.stringify(plan.noteWords) } : {};
378
+ for (const w of plan.watches ?? []) {
379
+ const problem = scheduledWatchProblem(w);
380
+ if (problem) throw new Error(`the product plan's watches: ${problem}`);
381
+ }
382
+ if (new Set((plan.watches ?? []).map((w) => w.op)).size !== (plan.watches ?? []).length) throw new Error("the product plan's watches name an Op twice");
383
+ // The note job's variables from the pipeline: the note words, and the product's watches (#4888).
384
+ const noteWords: Record<string, string> = {
385
+ ...(plan.noteWords ? { [PR_PLAN_NOTE_WORDS_ENV]: JSON.stringify(plan.noteWords) } : {}),
386
+ ...(plan.watches?.length ? { [PLAN_WATCHES_ENV]: JSON.stringify(plan.watches) } : {}),
387
+ };
388
+ const fill = (line: string, name: string | undefined): string => line.replaceAll("{target}", name ?? env).replaceAll("{output}", PR_LOOP_REPORT_DIR);
389
+ const control = plan.controlRead ? controlNoteCheckout(forge, plan.controlRead, words) : undefined;
177
390
  const one = (target?: ProductPlanTarget): ProductPlanJob => {
178
391
  const name = target?.name;
179
392
  const jobName = github ? (name ? `plan-${name}` : "plan") : gitlabPlanJobName(name);
@@ -181,38 +394,226 @@ export function productPlanJobs(forge: ForgeKind, env: string, loop: PrLoopPipel
181
394
  const own = target ? prLoopPassedEnv(forge, { ...(target.variables ? { variables: target.variables } : {}), ...(target.secrets ? { secrets: target.secrets } : {}) }) : {};
182
395
  for (const key of Object.keys(own)) {
183
396
  if (key in shared) throw new Error(`target ${name}'s ${key} is the pipeline's too; give it on the target or on the pipeline`);
397
+ if (key in jobEnv) throw new Error(`target ${name}'s ${key} is the product plan's env too; give it once`);
184
398
  }
185
- const post = prLoopPostJob(forge, env, name, words);
399
+ const post0 = prLoopPostJob(forge, env, name, words);
400
+ // #4899: the note job records the plan job's run, named by that job.
401
+ const post1 = plan.record ? { ...post0, command: `${post0.command} --record-run ${jobName}` } : post0;
402
+ // #4914: on GitLab the signing job of the same pipeline keeps each merge request's evidence, which the note's checks line reads.
403
+ const post = evidence && !github ? { ...post1, command: `${post1.command} --evidence-dir ${gitlabOpenEvidenceDir(jobName)}` } : post1;
186
404
  // The note job reads its own plan job's result, by that job's name.
187
405
  const postEnv: Record<string, string> = github ? { ...post.env, PLAN_RESULT: `\${{ needs.${jobName}.result }}`, ...noteWords } : { ...post.env, ...noteWords };
406
+ // #4931: the target's login, else the plan's, from the OIDC token file (ci-login, #4788).
407
+ const loginSpec = target?.login ?? plan.login;
408
+ const login = loginSpec ? cloudLogin(forge, loginSpec) : undefined;
409
+ const ownTokens = target?.idTokens ?? plan.idTokens;
410
+ for (const [v, aud] of Object.entries(ownTokens ?? {})) {
411
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(v)) throw new Error(`the product plan's id token ${JSON.stringify(v)} is not a variable name`);
412
+ if (!aud.trim() || /\s/.test(aud)) throw new Error(`the product plan's id token ${v} names no audience`);
413
+ if (login && v in login.idTokens && login.idTokens[v] !== aud) throw new Error(`the product plan's id token ${v} is the login's, with another audience`);
414
+ }
415
+ const idTokens = { ...(login?.idTokens ?? {}), ...(ownTokens ?? {}) };
416
+ const artifact = plan.artifact ? (name ? `${plan.artifact}-${name}` : plan.artifact) : name ? `chant-pr-plan-${name}` : "chant-pr-plan";
417
+ const replan0 = replanComments ? { ...replanJobOf(forge, env, words, name, artifact, noteWords), ...replanComments } : undefined;
418
+ const replan = replan0 && plan.record ? { ...replan0, post: { ...replan0.post, command: `${replan0.post.command} --record-run ${replan0.jobName}` } } : replan0;
419
+ const record = plan.record ? { env: { [PLAN_RUN_RECORD_ENV]: JSON.stringify({ op: PLAN_RUN_OP, env, labels: { Env: env, Pipeline: "pr", Job: "plan", ...(name ? { Target: name } : {}) } }) } } : undefined;
420
+ const noteBefore = plan.noteSteps?.before ?? [];
421
+ const noteAfter = plan.noteSteps?.after ?? [];
188
422
  return {
189
423
  ...(name ? { target: name } : {}),
190
424
  jobName,
191
425
  noteJobName,
192
- command: plan.command.replaceAll("{target}", name ?? env).replaceAll("{output}", PR_LOOP_REPORT_DIR),
426
+ command: fill(plan.command, name),
193
427
  env: { ...base, ...shared, ...own },
194
428
  ...(target?.writeProbe ? { writeProbe: target.writeProbe } : {}),
195
429
  post: { command: post.command, env: postEnv },
196
- artifact: plan.artifact ? (name ? `${plan.artifact}-${name}` : plan.artifact) : name ? `chant-pr-plan-${name}` : "chant-pr-plan",
430
+ artifact,
197
431
  ...(planRunner !== undefined ? { runner: planRunner } : {}),
198
432
  ...(noteRunner !== undefined ? { noteRunner } : {}),
199
- ...(evidence ? { evidence: planEvidenceOf(forge, evidence, words, jobName) } : {}),
433
+ ...(evidence ? { evidence: planEvidenceOf(forge, evidence, words, jobName, plan.forks === "skip" ? { noForks: true } : {}) } : {}),
434
+ ...(Object.keys(jobEnv).length > 0 ? { jobEnv } : {}),
435
+ ...(login && login.steps.length > 0 ? { login: login.steps } : {}),
436
+ ...(Object.keys(idTokens).length > 0 ? { idTokens } : {}),
437
+ ...(plan.pending && github ? { pending: { context: productStatusContext(words, "plan", name), description: "planning" } } : {}),
438
+ ...(control ? { control } : {}),
439
+ ...(plan.setup?.length ? { setup: plan.setup } : {}),
440
+ ...(plan.report ? { report: fill(plan.report, name) } : {}),
441
+ ...(replan ? { replan } : {}),
442
+ ...(noteBefore.length > 0 || noteAfter.length > 0 ? { noteSteps: { before: noteBefore, after: noteAfter } } : {}),
443
+ ...(record ? { record } : {}),
200
444
  };
201
445
  };
202
446
  return targets ? targets.map(one) : [one()];
203
447
  }
204
448
 
449
+ /** The comments the re-plan answers (#4899): the plan command, then the words' aliases for it. Refused when the words name no plan command. */
450
+ function replanCommentsOf(words: CiProductWords): { comments: string[]; gated: Array<{ comment: string; when: string }> } {
451
+ const command = commentLine(words, "plan");
452
+ if (!command) throw new Error(`the product plan's replan answers /${words.product} <plan command>, and the words name no plan command; name one in the words' commands, or drop replan`);
453
+ const aliases = words.aliases.filter((a) => a.command === "plan");
454
+ return { comments: [command, ...aliases.filter((a) => a.when === undefined).map((a) => a.from)], gated: aliases.filter((a) => a.when !== undefined).map((a) => ({ comment: a.from, when: a.when! })) };
455
+ }
456
+
457
+ /** The re-plan's jobs for one target (#4899), its comments filled in by the caller. */
458
+ function replanJobOf(forge: ForgeKind, env: string, words: CiProductWords, name: string | undefined, artifact: string, noteWords: Record<string, string>): Omit<ProductPlanReplanJob, "comments" | "gated"> {
459
+ const github = forge !== "gitlab";
460
+ const jobName = github ? (name ? `${REPLAN_JOB}-${name}` : REPLAN_JOB) : name ? `${name}-${REPLAN_JOB}` : REPLAN_JOB;
461
+ const noteJobName = github ? (name ? `${REPLAN_NOTE_JOB}-${name}` : REPLAN_NOTE_JOB) : name ? `${name}-${REPLAN_NOTE_JOB}` : REPLAN_NOTE_JOB;
462
+ // pr-post reads the pull request and the head from the re-plan job, never the comment. GitLab's is GitHub's line with its own --forge.
463
+ const command = github ? prLoopPostJob(forge, env, name, words).command : prLoopPostJob("github", env, name, words).command.replace(" --forge github ", " --forge gitlab ");
464
+ const post = github
465
+ ? {
466
+ command,
467
+ env: {
468
+ PR_NUMBER: `\${{ needs.${jobName}.outputs.pr }}`,
469
+ HEAD_SHA: `\${{ needs.${jobName}.outputs.head }}`,
470
+ PLAN_RESULT: `\${{ needs.${jobName}.result }}`,
471
+ GITHUB_TOKEN: GITHUB_JOB_TOKEN,
472
+ ...noteWords,
473
+ },
474
+ }
475
+ : {
476
+ // GitLab: the merge request from the pipeline's variable, its head again from the remote, and the re-plan job's result from its artifact.
477
+ command: command.replace(' --result "$PLAN_RESULT"', ""),
478
+ env: { PR_NUMBER: `$${GITLAB_REPLAN_PR_VAR}`, ...noteWords },
479
+ setup: ['HEAD_SHA="$(git ls-remote origin "refs/merge-requests/$PR_NUMBER/head" | cut -f1)" && export HEAD_SHA'],
480
+ };
481
+ return { jobName, noteJobName, post, artifact: `${artifact}-replan` };
482
+ }
483
+
484
+ /** The comment re-plan's job and its note job (#4899). */
485
+ export const REPLAN_JOB = "replan";
486
+ export const REPLAN_NOTE_JOB = "replan-note";
487
+
488
+ /**
489
+ * The GitLab variables the note-commands job starts a re-plan's pipeline
490
+ * with (#4899): the comment preview's (`CHANT_PREVIEW_PR`,
491
+ * `CHANT_PREVIEW_COMMENT`), so `pr-notes --preview-comment` starts it.
492
+ */
493
+ export const GITLAB_REPLAN_PR_VAR = "CHANT_PREVIEW_PR";
494
+ export const GITLAB_REPLAN_COMMENT_VAR = "CHANT_PREVIEW_COMMENT";
495
+
496
+ /** A regular expression's body that matches `text` literally, for a GitLab rule's `/.../`. */
497
+ function literal(text: string): string {
498
+ return text.replace(/[.*+?^${}()|[\]\\\/]/g, "\\$&");
499
+ }
500
+
501
+ /**
502
+ * The GitLab rule condition that the re-plan pipeline's comment asks for
503
+ * `target` (#4899): the command alone, or with the target's name. Without
504
+ * a target, the command with at most one word after it.
505
+ */
506
+ export function gitlabReplanCommentIf(replan: Pick<ProductPlanReplanJob, "comments" | "gated">, target?: string): string {
507
+ const arg = target ? `( +${literal(target)})?` : "( +[A-Za-z0-9_.\\/@+=,:-]+)?";
508
+ const one = (c: string): string => `$${GITLAB_REPLAN_COMMENT_VAR} =~ /^${literal(c)}${arg} *$/`;
509
+ return [...replan.comments.map(one), ...replan.gated.map((g) => `($${g.when} && ${one(g.comment)})`)].join(" || ");
510
+ }
511
+
512
+ /**
513
+ * The re-plan job's first step on GitHub and Forgejo (#4899), with the job's
514
+ * token in its environment alone, before anything is checked out: it reads
515
+ * the comment from the event file (never as an expression in a script),
516
+ * decides whether it asks this job to plan, asks the forge for the pull
517
+ * request (open; from this repository with `forks: "skip"`) and, with
518
+ * `CHANT_REPLAN_PERMISSION` set (Forgejo, whose payload says nothing of the
519
+ * commenter), whether the commenter can write. It writes `go=1`, `pr`,
520
+ * `head`, `base` and `argument` to the step's outputs.
521
+ */
522
+ export const REPLAN_DECIDE_JS = [
523
+ 'const fs=require("fs");',
524
+ 'const say=(m)=>console.log("chant: "+m);',
525
+ 'const out=(k,v)=>fs.appendFileSync(process.env.GITHUB_OUTPUT,k+"="+v+"\\n");',
526
+ "let e;try{e=JSON.parse(fs.readFileSync(process.env.GITHUB_EVENT_PATH,\"utf8\"))}catch{say(\"the event file does not read, so nothing is planned again\");process.exit(0)}",
527
+ 'const body=String((e.comment&&e.comment.body)||"").trim();',
528
+ 'const cmds=JSON.parse(process.env.CHANT_REPLAN_COMMANDS||"[]");',
529
+ 'for(const g of JSON.parse(process.env.CHANT_REPLAN_GATED||"[]")){const v=process.env[g.when]||"";if(v&&v!=="0"&&v!=="false")cmds.push(g.comment)}',
530
+ "let arg;",
531
+ 'for(const c of cmds){if(body===c){arg="";break}if(body.startsWith(c+" ")){const r=body.slice(c.length).trim();if(/^[A-Za-z0-9_.\\/@+=,:-]+$/.test(r)){arg=r;break}}}',
532
+ 'if(arg===undefined){say("the comment asks for no plan");process.exit(0)}',
533
+ 'const target=process.env.CHANT_REPLAN_TARGET||"",targets=JSON.parse(process.env.CHANT_REPLAN_TARGETS||"[]");',
534
+ 'if(targets.length&&arg&&!targets.includes(arg)){say(arg+" is none of "+targets.join(", ")+", so nothing is planned again");process.exit(0)}',
535
+ 'if(targets.length&&arg&&arg!==target){say("the comment plans "+arg+" again, not "+target);process.exit(0)}',
536
+ 'const n=e.issue&&e.issue.number;if(!Number.isInteger(n)||!(e.issue.pull_request||e.is_pull)){say("the comment is not on a pull request");process.exit(0)}',
537
+ 'const api=String(process.env.GITHUB_API_URL||"").replace(/\\/+$/,""),repo=process.env.GITHUB_REPOSITORY;',
538
+ 'const get=async(p)=>{const r=await fetch(api+"/repos/"+repo+p,{headers:{authorization:"token "+process.env.CHANT_REPLAN_TOKEN,accept:"application/json"}});if(!r.ok)throw new Error(p+" answered "+r.status);return r.json()};',
539
+ "(async()=>{",
540
+ 'const pr=await get("/pulls/"+n);',
541
+ 'if(pr.state!=="open"){say("pull request "+n+" is not open, so it is not planned again");return}',
542
+ 'const same=Boolean(pr.head&&pr.head.repo&&pr.head.repo.full_name===repo);',
543
+ 'if(!same&&process.env.CHANT_REPLAN_FORKS==="skip"){say("pull request "+n+" is from a fork, and its code never runs with this repository\\u0027s credentials");return}',
544
+ 'if(process.env.CHANT_REPLAN_PERMISSION){const who=e.comment&&e.comment.user&&e.comment.user.login;const p=who?await get("/collaborators/"+encodeURIComponent(who)+"/permission"):{};',
545
+ 'if(!["owner","admin","maintain","write"].includes(p.permission)){say((who||"the commenter")+" cannot write to "+repo+", so nothing is planned again");return}}',
546
+ 'const sha=/^[0-9a-f]{40}$/;if(!sha.test(String(pr.head&&pr.head.sha))||!sha.test(String(pr.base&&pr.base.sha)))throw new Error("the pull request names no head or base commit");',
547
+ 'out("go","1");out("pr",String(n));out("head",pr.head.sha);out("base",pr.base.sha);out("argument",arg);',
548
+ 'say("planning pull request "+n+" again at "+pr.head.sha.slice(0,12)+(arg?" for "+arg:""))',
549
+ '})().catch((err)=>{console.error("chant: the re-plan could not decide: "+(err&&err.message?err.message:String(err)));process.exit(1)});',
550
+ ].join("");
551
+
552
+ /**
553
+ * The pending step's script on GitHub and Forgejo (#4899): `node -e`, from
554
+ * `/`, posting the plan status pending at `CHANT_PENDING_SHA` with the token
555
+ * in `CHANT_PENDING_TOKEN`. A forge that refuses it is a warning: the note
556
+ * job sets the status the plan ends with.
557
+ */
558
+ export const PENDING_JS = [
559
+ 'const api=String(process.env.GITHUB_API_URL||"").replace(/\\/+$/,""),repo=process.env.GITHUB_REPOSITORY,sha=process.env.CHANT_PENDING_SHA||"";',
560
+ 'if(!/^[0-9a-f]{40}$/.test(sha)){console.log("chant: no commit to say the plan started on");process.exit(0)}',
561
+ 'const run=process.env.GITHUB_SERVER_URL&&process.env.GITHUB_RUN_ID?process.env.GITHUB_SERVER_URL+"/"+repo+"/actions/runs/"+process.env.GITHUB_RUN_ID:undefined;',
562
+ 'fetch(api+"/repos/"+repo+"/statuses/"+sha,{method:"POST",headers:{authorization:"token "+process.env.CHANT_PENDING_TOKEN,accept:"application/json","content-type":"application/json"},body:JSON.stringify({state:"pending",context:process.env.CHANT_PENDING_CONTEXT,description:process.env.CHANT_PENDING_DESCRIPTION,...(run?{target_url:run}:{})})})',
563
+ '.then((r)=>console.log(r.ok?"chant: "+process.env.CHANT_PENDING_CONTEXT+" is pending":"chant: the forge answered "+r.status+" to the pending status"),(err)=>console.log("chant: the pending status was not posted: "+err.message));',
564
+ ].join("");
565
+
566
+ /**
567
+ * The plan step's lines for the plan verb (#4899): the verb, then the
568
+ * report line whatever the verb's exit, then the step exits with the verb's
569
+ * status. Without a report line, the verb alone.
570
+ */
571
+ export function planVerbLines(p: Pick<ProductPlanJob, "command" | "report" | "record">): string[] {
572
+ if (!p.report && !p.record) return [p.command];
573
+ return [
574
+ ...(p.record ? ['chant_plan_started="$(date -u +%Y-%m-%dT%H:%M:%SZ)"'] : []),
575
+ "chant_plan_exit=0",
576
+ `${p.command} || chant_plan_exit=$?`,
577
+ ...(p.report ? [`${p.report} || echo "chant: the report line exited $?" >&2`] : []),
578
+ // #4899: the run record goes into the hand-off, for the note job to keep on chant/lifecycle.
579
+ ...(p.record ? [`CHANT_PLAN_EXIT="$chant_plan_exit" CHANT_PLAN_STARTED="$chant_plan_started" node -e '${PLAN_RECORD_JS}' ${PR_LOOP_REPORT_DIR} || echo "chant: the plan's run record was not written" >&2`] : []),
580
+ '[ "$chant_plan_exit" -eq 0 ] || exit "$chant_plan_exit"',
581
+ ];
582
+ }
583
+
584
+ /**
585
+ * The plan step's record line (#4899): `node -e`, writing the run record of
586
+ * the plan verb into the directory it is given, {@link PLAN_RUN_RECORD_FILE}.
587
+ * It reads the op, environment and labels from {@link PLAN_RUN_RECORD_ENV},
588
+ * the verb's exit from `CHANT_PLAN_EXIT`, its start from
589
+ * `CHANT_PLAN_STARTED`, and the commit from git. The shape is an
590
+ * `OpRunRecordInput` (../op/runtime.ts) with no run origin, which the note
591
+ * job names.
592
+ */
593
+ export const PLAN_RECORD_JS = [
594
+ 'const fs=require("fs"),path=require("path"),cp=require("child_process"),crypto=require("crypto");',
595
+ "const c=JSON.parse(process.env.CHANT_PLAN_RECORD||\"{}\"),dir=process.argv[1];",
596
+ 'const code=Number(process.env.CHANT_PLAN_EXIT||"1"),ended=new Date().toISOString(),started=new Date(Date.parse(process.env.CHANT_PLAN_STARTED||"")||Date.now()).toISOString();',
597
+ 'let sha="";try{sha=cp.execFileSync("git",["rev-parse","HEAD"],{encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trim()}catch{}',
598
+ 'const ok=code===0,status=ok?"ok":"fail",ms=Math.max(0,Date.parse(ended)-Date.parse(started));',
599
+ 'const rec={id:crypto.randomUUID(),op:c.op,env:c.env,started,ended,status,labels:c.labels||{},outcomes:{},phases:[{name:"plan",status,steps:[{fn:"shellCmd",status,durationMs:ms,...(ok?{}:{error:"command exited "+code})}]}],...(sha?{gitSha:sha}:{}),...(ok?{}:{failure:{code:"command-failed",reason:"the plan verb exited "+code,phase:"plan",exitCode:code}})};',
600
+ `fs.mkdirSync(dir,{recursive:true});fs.writeFileSync(path.join(dir,"${PLAN_RUN_RECORD_FILE}"),JSON.stringify(rec)+"\\n");`,
601
+ ].join("");
602
+
205
603
  /** The evidence step of one plan job (#4870), as {@link ProductPlanJob.evidence}. */
206
- export function planEvidenceOf(forge: ForgeKind, evidence: PipelineEvidence, words: CiProductWords, planJob: string): NonNullable<ProductPlanJob["evidence"]> {
604
+ export function planEvidenceOf(forge: ForgeKind, evidence: PipelineEvidence, words: CiProductWords, planJob: string, opts: { noForks?: boolean } = {}): NonNullable<ProductPlanJob["evidence"]> {
207
605
  assertPipelineEvidence(evidence);
208
606
  const key = evidenceKeyEnv(forge, evidence);
209
607
  const bin = words.bin;
210
608
  if (forge === "gitlab") {
211
- // The job runs only once the plan job succeeded, on the merge request's commit.
609
+ // #4914: the job runs in the target branch's plan notes pipeline, before the note job, and signs every open
610
+ // merge request's settled plan job from its artifact; no job of a merge request pipeline holds the key.
611
+ const dir = gitlabOpenEvidenceDir(planJob);
212
612
  return {
213
613
  jobName: `${planJob}-evidence`,
214
- lines: planEvidenceLines({ dir: PR_LOOP_REPORT_DIR, at: '"$CI_COMMIT_SHA"', base: '"$CI_MERGE_REQUEST_DIFF_BASE_SHA"', result: "success", ...(bin ? { bin } : {}) }),
614
+ lines: openEvidenceLines({ job: planJob, dir: PR_LOOP_REPORT_DIR, out: dir, ...(bin ? { bin } : {}), ...(opts.noForks ? { noForks: true } : {}) }),
215
615
  env: key,
616
+ dir,
216
617
  ...(evidenceKeyless(evidence) ? { idTokens: evidenceIdTokens(evidence) } : {}),
217
618
  };
218
619
  }
package/src/config.ts CHANGED
@@ -112,7 +112,8 @@ export const ChantConfigSchema = z.object({
112
112
  images: z
113
113
  .array(
114
114
  z.union([
115
- z.object({ name: z.string().min(1), build: z.string().min(1), archive: z.string().min(1) }).strict(),
115
+ // #4876: `platforms`, what the command builds, for the release workflow's QEMU setup.
116
+ z.object({ name: z.string().min(1), build: z.string().min(1), archive: z.string().min(1), platforms: z.array(z.string().min(1)).min(1).optional() }).strict(),
116
117
  // #4819: chant builds the Dockerfile as the reproducible OCI archive itself.
117
118
  z
118
119
  .object({
@@ -122,6 +123,8 @@ export const ChantConfigSchema = z.object({
122
123
  platforms: z.array(z.string().min(1)).min(1).optional(),
123
124
  archive: z.string().min(1).optional(),
124
125
  prepare: z.string().min(1).optional(),
126
+ // #4908: build arguments beside the two chant passes.
127
+ args: z.record(z.string(), z.string()).optional(),
125
128
  })
126
129
  .strict(),
127
130
  ]),
@@ -422,8 +425,8 @@ export interface ChantConfig {
422
425
  * digest and hands every digest to the build through `CHANT_RELEASE_DIGESTS`,
423
426
  * so a package can pin the images it ships with. An `oci` target pushes
424
427
  * the archive. An entry may name a `dockerfile` (with `context`,
425
- * `platforms`, `archive` and `prepare`) in place of `build`, and chant
426
- * runs the reproducible build itself (#4819). See
428
+ * `platforms`, `archive`, `prepare` and `args`) in place of `build`, and
429
+ * chant runs the reproducible build itself (#4819, #4908). See
427
430
  * ./lifecycle/release-images.ts.
428
431
  */
429
432
  images?: import("./lifecycle/release-images").ReleaseImageDeclaration[];
@@ -758,13 +761,15 @@ export function resolveSourceDir(projectDir: string, config: { sourceDir?: unkno
758
761
  /**
759
762
  * The top-level directories a root build leaves out (#4794): a project with
760
763
  * no `sourceDir`, built from its own root, does not load `scripts/`, where a
761
- * script that runs on load (prints and exits) would take the build's place.
762
- * Matched against the path relative to the project root, so only the
763
- * project's own top-level `scripts/` is skipped. The config's `include`
764
- * brings it back. Test and spec files are left out of every build already
764
+ * script that runs on load (prints and exits) would take the build's place,
765
+ * nor `migrations/` (#4921), whose `.sql` files are `ALTER`s of objects
766
+ * declared elsewhere and whose backfill scripts run on load too. Matched
767
+ * against the path relative to the project root, so only the project's own
768
+ * top-level directories are skipped. The config's `include` brings one back.
769
+ * Test and spec files are left out of every build already
765
770
  * (`isSourceFileName`).
766
771
  */
767
- export const ROOT_SOURCE_EXCLUDES: readonly string[] = ["scripts"];
772
+ export const ROOT_SOURCE_EXCLUDES: readonly string[] = ["scripts", "migrations"];
768
773
 
769
774
  /** A project's discovery globs (#2519) and the directory they are relative to. */
770
775
  export interface DiscoveryGlobs {
@@ -22,6 +22,13 @@
22
22
  import type { CatalogConsumer, CatalogConsumersInput } from "../lifecycle/release-catalog";
23
23
  import type { ControlEntry } from "./records";
24
24
 
25
+ /**
26
+ * The first chant with the consumers join, {@link joinControlConsumers} and
27
+ * {@link readControlConsumers} on `@intentius/chant/ci-control` (#4600).
28
+ * #4916 declared it after the fact, for `chant dev dead-guards`.
29
+ */
30
+ export const CONTROL_CONSUMERS_FLOOR = "0.124.55";
31
+
25
32
  /** The file each project keeps its consumers in. */
26
33
  export const CONSUMERS_FILE = "consumers.json";
27
34
  /** The contract version of {@link ConsumersDocument}. */