@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
@@ -7,7 +7,9 @@ import { crc32, deflateRawSync, gzipSync } from "node:zlib";
7
7
  import { describe, expect, test } from "vitest";
8
8
  import {
9
9
  CI_BASE_IMAGES,
10
+ CI_IMAGE_DOCKER_STAGES_FLOOR,
10
11
  CI_IMAGE_FLOOR,
12
+ CI_IMAGE_NON_ROOT_FLOOR,
11
13
  CI_TOOL_DOCKER_ARCH,
12
14
  CI_TOOL_SHA256,
13
15
  CI_TOOLS,
@@ -163,8 +165,10 @@ describe("ciToolRelease", () => {
163
165
  expect(() => ciToolSha256("tofu", "1.13.1", { amd64: "nothex" })).toThrow(/64 lower-case hex/);
164
166
  });
165
167
 
166
- test("CI_IMAGE_FLOOR is the next release", () => {
167
- expect(CI_IMAGE_FLOOR).toBe(NEXT_RELEASE);
168
+ test("CI_IMAGE_FLOOR is the release that shipped it, and #4908's and #4932's floors the next", () => {
169
+ expect(CI_IMAGE_FLOOR).toBe("0.124.86");
170
+ expect(CI_IMAGE_NON_ROOT_FLOOR).toBe(NEXT_RELEASE);
171
+ expect(CI_IMAGE_DOCKER_STAGES_FLOOR).toBe(NEXT_RELEASE);
168
172
  });
169
173
  });
170
174
 
@@ -238,13 +242,13 @@ describe("ciToolFetchScript against local fixtures", () => {
238
242
  test("a bare binary, and a zip's member, install as the command", () => {
239
243
  const tg = Buffer.from("#!/bin/sh\necho terragrunt\n");
240
244
  const out = tmp();
241
- const s1 = ciToolFetchScript("terragrunt", "1.2.0", { dir: `${out}/tg`, arch: CI_TOOL_DOCKER_ARCH });
245
+ const s1 = ciToolFetchScript("terragrunt", "1.1.0", { dir: `${out}/tg`, arch: CI_TOOL_DOCKER_ARCH });
242
246
  expect(runShell(s1, { terragrunt_linux_arm64: tg, SHA256SUMS: `${sha(tg)} *terragrunt_linux_arm64\n` }, { TARGETARCH: "arm64" }).status).toBe(0);
243
247
  expect(readFileSync(`${out}/tg/terragrunt`, "utf-8")).toContain("echo terragrunt");
244
248
 
245
249
  const z = zip({ terraform: "#!/bin/sh\necho terraform\n", "LICENSE.txt": "x" });
246
- const s2 = ciToolFetchScript("terraform", "1.14.9", { dir: `${out}/tf`, arch: CI_TOOL_DOCKER_ARCH });
247
- const r = runShell(s2, { "terraform_1.14.9_linux_amd64.zip": z, "terraform_1.14.9_SHA256SUMS": `${sha(z)} terraform_1.14.9_linux_amd64.zip\n` }, { TARGETARCH: "amd64" });
250
+ const s2 = ciToolFetchScript("terraform", "1.14.8", { dir: `${out}/tf`, arch: CI_TOOL_DOCKER_ARCH });
251
+ const r = runShell(s2, { "terraform_1.14.8_linux_amd64.zip": z, "terraform_1.14.8_SHA256SUMS": `${sha(z)} terraform_1.14.8_linux_amd64.zip\n` }, { TARGETARCH: "amd64" });
248
252
  expect(r.stderr).toBe("");
249
253
  expect(readFileSync(`${out}/tf/terraform`, "utf-8")).toContain("echo terraform");
250
254
  });
@@ -258,7 +262,7 @@ describe("ciToolFetchScript against local fixtures", () => {
258
262
 
259
263
  test("refuses, before any shell, a release that needs a recorded sha256 it lacks", () => {
260
264
  expect(() => ciToolFetchScript("act", "0.2.89", { dir: "/out/act" })).toThrow(/no recorded sha256 for act 0.2.89 on amd64 and arm64; act's release publishes no checksums file/);
261
- expect(() => ciToolFetchScript("terragrunt", "1.2.0", { dir: "/out/tg", requirePin: true })).toThrow(/no recorded sha256 for terragrunt 1.2.0/);
265
+ expect(() => ciToolFetchScript("terragrunt", "1.1.0", { dir: "/out/tg", requirePin: true })).toThrow(/no recorded sha256 for terragrunt 1.1.0/);
262
266
  expect(() => ciToolFetchScript("tofu", "1.13.1", { dir: "/out/x y" })).toThrow(/absolute path/);
263
267
  });
264
268
  });
@@ -285,6 +289,52 @@ describe("ciToolInstallLine", () => {
285
289
  });
286
290
  });
287
291
 
292
+ describe("non-root job lines (#4908)", () => {
293
+ test("sudo writes the tool root and the link, and leaves the download and the check to the job's user", () => {
294
+ const line = ciToolInstallLine("tofu", "1.13.1", { sudo: true });
295
+ expect(line).toContain('sudo mkdir -p "/opt/chant/tofu-1.13.1"');
296
+ expect(line).toContain('sudo install -m 0755 "$t/tofu" "/opt/chant/tofu-1.13.1/tofu"');
297
+ expect(line.endsWith('sudo ln -sf "/opt/chant/tofu-1.13.1/tofu" /usr/local/bin/tofu')).toBe(true);
298
+ expect(line).not.toContain("sudo curl");
299
+ expect(line).not.toContain("sudo sha256sum");
300
+ expect(ciToolFetchScript("pulumi", "3.272.0", { dir: "/opt/p/pulumi-3.272.0", sudo: true })).toContain('sudo tar -xzf "$t/$f" -C "/opt/p/pulumi-3.272.0" --strip-components=1');
301
+ expect(ciToolInstallLine("aws-cli", "2.37.9", { sudo: true })).toContain('sudo "$t/aws/install" -i "/opt/chant/aws-cli-2.37.9" -b "/opt/chant/aws-cli-2.37.9/bin"');
302
+ expect(ciToolInstallLine("tofu", "1.13.1")).not.toContain("sudo");
303
+ });
304
+
305
+ test("a root and a binDir under a variable the job expands, quoted", () => {
306
+ const line = ciToolInstallLine("aws-cli", "2.37.9", { root: "$RUNNER_TEMP/chant-tools", binDir: "${HOME}/.local/bin/" });
307
+ expect(line.startsWith('{ [ -x "$RUNNER_TEMP/chant-tools/aws-cli-2.37.9/v2/current/bin/aws" ] || (set -e;')).toBe(true);
308
+ expect(line.endsWith('mkdir -p "${HOME}/.local/bin" && ln -sf "$RUNNER_TEMP/chant-tools/aws-cli-2.37.9/v2/current/bin/aws" "${HOME}/.local/bin/aws"')).toBe(true);
309
+ expect(ciToolBin("tofu", "1.13.1", "$RUNNER_TEMP/t")).toBe("$RUNNER_TEMP/t/tofu-1.13.1/tofu");
310
+ expect(() => ciToolInstallLine("tofu", "1.13.1", { root: "$(id)/x" })).toThrow(/tool root/);
311
+ expect(() => ciToolInstallLine("tofu", "1.13.1", { root: "relative/x" })).toThrow(/tool root/);
312
+ expect(() => ciToolInstallLine("tofu", "1.13.1", { binDir: "$HOME x" })).toThrow(/binDir/);
313
+ // An image's COPY expands no shell variable.
314
+ expect(() => productImageStages({ name: "p", product: "p", description: "d", source: "s", toolRoot: "$HOME/t", tools: [{ tool: "tofu", version: "1.13.1" }], bundle: { file: "a", bin: "a" } })).toThrow(/toolRoot/);
315
+ });
316
+
317
+ test("runs as a user: installs under a variable root and links into a variable binDir", () => {
318
+ const a = tarGz({ tofu: "#!/bin/sh\necho user-install\n" });
319
+ const home = tmp();
320
+ const line = ciToolInstallLine("tofu", "1.13.1", { root: "$TOOLS/t", binDir: "$TOOLS/bin", sha256: { amd64: sha(a), arm64: sha(a) } });
321
+ const files = { "tofu_1.13.1_linux_amd64.tar.gz": a, "tofu_1.13.1_linux_arm64.tar.gz": a, "tofu_1.13.1_SHA256SUMS": `${sha(a)} tofu_1.13.1_linux_amd64.tar.gz\n${sha(a)} tofu_1.13.1_linux_arm64.tar.gz\n` };
322
+ const r = runShell(line, files, { TOOLS: home });
323
+ expect(r.stderr).toBe("");
324
+ expect(r.status).toBe(0);
325
+ expect(readFileSync(`${home}/bin/tofu`, "utf-8")).toContain("echo user-install");
326
+ });
327
+
328
+ test("chant records terragucci's terraform and terragrunt pins and its drift job's AWS CLI", () => {
329
+ expect(ciToolSha256("terraform", "1.14.9")).toEqual({ amd64: "2e5cffc20a0b48a67a76268723bd5a10b8666f69b2aa4f04906e206726bedd63", arm64: "863002085b886453795d9ff4b8989b8468784478150b70ba8a1df3e3ad66da99" });
330
+ expect(ciToolSha256("terragrunt", "1.2.0")).toEqual({ amd64: "45b6df8a8494c8cfe34b4abf919e894709557163e4d3b5704d11083002ab787a", arm64: "b069ce4310572bc46ee6f057057acc4bc6a9077ef8687e157a64b0551290a371" });
331
+ expect(ciToolSha256("aws-cli", "2.37.9")).toEqual({ amd64: "6b3a6a3d7bb3997928f0bdf7b866914224abf242c2e54e1dcebbe84bee64f356", arm64: "e7d2cca3622af4765871fe9ce7eeed03acd09dca10a99ebc46e92f79d78765c0" });
332
+ // So an image carries them with no sums of the product's, and a job line can require the pin.
333
+ expect(() => productImageStages({ name: "t", product: "t", description: "d", source: "s", tools: [{ tool: "terraform", version: "1.14.9" }, { tool: "terragrunt", version: "1.2.0" }], bundle: { file: "a", bin: "a" } })).not.toThrow();
334
+ expect(ciToolInstallLine("terragrunt", "1.2.0", { requirePin: true, sudo: true, link: false })).toContain("want=45b6df8a");
335
+ });
336
+ });
337
+
288
338
  describe("installCiTool", () => {
289
339
  const a = tarGz({ tofu: "#!/bin/sh\necho node-install\n" });
290
340
  const base = "https://github.com/opentofu/opentofu/releases/download/v1.13.1";
@@ -332,9 +382,9 @@ describe("installCiTool", () => {
332
382
  test("unpacks a zip's member, a bare binary and a tree", async () => {
333
383
  const root = tmp();
334
384
  const z = zip({ terraform: "tf" });
335
- const tf = "https://releases.hashicorp.com/terraform/1.14.9";
336
- await installCiTool("terraform", "1.14.9", { ...opts, root, download: served({ [`${tf}/terraform_1.14.9_linux_amd64.zip`]: z, [`${tf}/terraform_1.14.9_SHA256SUMS`]: `${sha(z)} terraform_1.14.9_linux_amd64.zip\n` }).download });
337
- expect(readFileSync(join(root, "terraform-1.14.9", "terraform"), "utf-8")).toBe("tf");
385
+ const tf = "https://releases.hashicorp.com/terraform/1.14.8";
386
+ await installCiTool("terraform", "1.14.8", { ...opts, root, download: served({ [`${tf}/terraform_1.14.8_linux_amd64.zip`]: z, [`${tf}/terraform_1.14.8_SHA256SUMS`]: `${sha(z)} terraform_1.14.8_linux_amd64.zip\n` }).download });
387
+ expect(readFileSync(join(root, "terraform-1.14.8", "terraform"), "utf-8")).toBe("tf");
338
388
 
339
389
  const cosign = Buffer.from("cosign");
340
390
  const cb = "https://github.com/sigstore/cosign/releases/download/v2.6.5";
@@ -407,7 +457,7 @@ describe("productImageStages", () => {
407
457
  });
408
458
 
409
459
  test("an image refuses an engine with no recorded sha256", () => {
410
- expect(() => productImageStages({ ...terragucci, tools: [{ tool: "terragrunt", version: "1.2.0" }] })).toThrow(/no recorded sha256 for terragrunt 1.2.0 on amd64 and arm64/);
460
+ expect(() => productImageStages({ ...terragucci, tools: [{ tool: "terragrunt", version: "1.1.0" }] })).toThrow(/no recorded sha256 for terragrunt 1.1.0 on amd64 and arm64/);
411
461
  expect(() => productImageStages({ ...terragucci, tools: [{ tool: "tofu", version: "1.13.1" }, { tool: "tofu", version: "1.13.1" }] })).toThrow(/listed twice/);
412
462
  });
413
463
 
package/src/ci-image.ts CHANGED
@@ -16,9 +16,10 @@
16
16
  * product records others in its own config and passes them as `sha256`.
17
17
  * - {@link ciToolFetchScript} is the shell that downloads one release and
18
18
  * checks it, for an image's fetch stage; {@link ciToolInstallLine} is the
19
- * job line that runs it unless the binary is there; {@link installCiTool}
20
- * does the same from Node, for a product that installs a pinned release
21
- * at run time.
19
+ * job line that runs it unless the binary is there (with `sudo`, or under
20
+ * a root such as `$RUNNER_TEMP/chant-tools`, for a job that is not root,
21
+ * #4908); {@link installCiTool} does the same from Node, for a product
22
+ * that installs a pinned release at run time.
22
23
  * - {@link productImageStages} is a product's image as stages a Dockerfile
23
24
  * takes (the docker lexicon's `new Dockerfile({ stages })`), and
24
25
  * {@link productImageDockerfile} is the same as text. The product passes
@@ -46,9 +47,9 @@ import { tmpdir } from "node:os";
46
47
  import { join } from "node:path";
47
48
  import { gunzipSync, inflateRawSync } from "node:zlib";
48
49
  import { tarEntry } from "./policy-engine";
49
- import { CI_IMAGE_FLOOR } from "./release-floors";
50
+ import { CI_IMAGE_DOCKER_STAGES_FLOOR, CI_IMAGE_FLOOR, CI_IMAGE_NON_ROOT_FLOOR } from "./release-floors";
50
51
 
51
- export { CI_IMAGE_FLOOR };
52
+ export { CI_IMAGE_DOCKER_STAGES_FLOOR, CI_IMAGE_FLOOR, CI_IMAGE_NON_ROOT_FLOOR };
52
53
 
53
54
  // ---------------------------------------------------------------------------
54
55
  // Engine releases
@@ -230,6 +231,14 @@ export const CI_TOOL_SHA256: Readonly<Record<string, string>> = {
230
231
  "plunge-0.2.0-linux-arm64": "c176a82f038164085aa19c8ad6530d6022e560e124050e535dbe364ae0473357",
231
232
  "aws-cli-2.22.0-linux-amd64": "f315aa564190a12ae05a05bd8ab7b0645dd4a1ad71ce9e47dae4ff3dfeee8ceb",
232
233
  "aws-cli-2.22.0-linux-arm64": "c932ac00901ea3c430f3829140b8dc00fa6e9b8b99d6891929a4795947de7f3e",
234
+ // #4908: terragucci's image pins (its TOOL_SHA256, from terraform_1.14.9_SHA256SUMS and terragrunt v1.2.0's SHA256SUMS)
235
+ // and the AWS CLI its drift job installs (its AWS_CLI), so a product's image and job lines need no sums of their own.
236
+ "terraform-1.14.9-linux-amd64": "2e5cffc20a0b48a67a76268723bd5a10b8666f69b2aa4f04906e206726bedd63",
237
+ "terraform-1.14.9-linux-arm64": "863002085b886453795d9ff4b8989b8468784478150b70ba8a1df3e3ad66da99",
238
+ "terragrunt-1.2.0-linux-amd64": "45b6df8a8494c8cfe34b4abf919e894709557163e4d3b5704d11083002ab787a",
239
+ "terragrunt-1.2.0-linux-arm64": "b069ce4310572bc46ee6f057057acc4bc6a9077ef8687e157a64b0551290a371",
240
+ "aws-cli-2.37.9-linux-amd64": "6b3a6a3d7bb3997928f0bdf7b866914224abf242c2e54e1dcebbe84bee64f356",
241
+ "aws-cli-2.37.9-linux-arm64": "e7d2cca3622af4765871fe9ce7eeed03acd09dca10a99ebc46e92f79d78765c0",
233
242
  };
234
243
 
235
244
  /** One release file of one tool for one architecture. */
@@ -256,6 +265,13 @@ export interface CiToolRelease {
256
265
  const VERSION = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.]+)?$/;
257
266
  const SHA256 = /^[0-9a-f]{64}$/;
258
267
  const DIR = /^\/[A-Za-z0-9._/-]*$/;
268
+ /**
269
+ * A directory a job line may name (#4908): an absolute path, or one under a
270
+ * variable the job's shell expands, such as `$RUNNER_TEMP/chant-tools` or
271
+ * `$HOME/.local/bin`, so a job that is not root installs where it can write.
272
+ * Every line writes it inside double quotes.
273
+ */
274
+ const SHELL_DIR = /^(?:\/|\$[A-Za-z_][A-Za-z0-9_]*(?=\/|$)|\$\{[A-Za-z_][A-Za-z0-9_]*\})[A-Za-z0-9._/-]*$/;
259
275
 
260
276
  function spec(tool: CiTool): ToolSpec {
261
277
  const s = TOOLS[tool];
@@ -304,10 +320,10 @@ export function ciToolSha256(tool: CiTool, version: string, given?: Partial<Reco
304
320
  return out;
305
321
  }
306
322
 
307
- /** Where a tool lives once installed: `<root>/<tool>-<version>`. */
323
+ /** Where a tool lives once installed: `<root>/<tool>-<version>`. A job line's root may start with a shell variable (#4908). */
308
324
  export function ciToolDir(tool: CiTool, version: string, root: string): string {
309
325
  checkVersion(tool, version);
310
- if (!DIR.test(root)) throw new Error(`a tool root is an absolute path of letters, digits and ._/-, not ${JSON.stringify(root)}`);
326
+ if (!SHELL_DIR.test(root)) throw new Error(`a tool root is an absolute path of letters, digits and ._/-, or one under a variable such as $RUNNER_TEMP, not ${JSON.stringify(root)}`);
311
327
  return `${root.replace(/\/+$/, "")}/${tool}-${version}`;
312
328
  }
313
329
 
@@ -340,6 +356,12 @@ export interface CiToolFetchOptions extends CiToolCheckOptions {
340
356
  arch?: string;
341
357
  /** A shell word for the checksums file's URL, such as `"$CHECKSUMS_URL"`. Default the release's own. */
342
358
  checksumsUrl?: string;
359
+ /**
360
+ * Write into `dir` with `sudo` (#4908), for a job that runs as a user who
361
+ * cannot write the tool root, such as GitHub's hosted runners under
362
+ * /opt. The download and the check run as the job's user. Default false.
363
+ */
364
+ sudo?: boolean;
343
365
  }
344
366
 
345
367
  function needPins(tool: CiTool, version: string, sums: Partial<Record<CiToolArch, string>>, requirePin: boolean): void {
@@ -358,7 +380,8 @@ function needPins(tool: CiTool, version: string, sums: Partial<Record<CiToolArch
358
380
  * release needs a recorded sha256 it lacks.
359
381
  */
360
382
  export function ciToolFetchScript(tool: CiTool, version: string, options: CiToolFetchOptions): string {
361
- if (!DIR.test(options.dir)) throw new Error(`a fetch directory is an absolute path of letters, digits and ._/-, not ${JSON.stringify(options.dir)}`);
383
+ if (!SHELL_DIR.test(options.dir)) throw new Error(`a fetch directory is an absolute path of letters, digits and ._/-, or one under a variable such as $RUNNER_TEMP, not ${JSON.stringify(options.dir)}`);
384
+ const su = options.sudo ? "sudo " : "";
362
385
  const s = spec(tool);
363
386
  const sums = ciToolSha256(tool, version, options.sha256);
364
387
  needPins(tool, version, sums, options.requirePin === true);
@@ -387,33 +410,49 @@ export function ciToolFetchScript(tool: CiTool, version: string, options: CiTool
387
410
  } else {
388
411
  lines.push(`{ [ -n "$want" ] || { echo "${name}: no sha256 is recorded for $f" >&2; exit 1; }; }`);
389
412
  }
390
- lines.push(`echo "$want $t/$f" | sha256sum -c - >/dev/null`, `mkdir -p "${dir}"`);
413
+ lines.push(`echo "$want $t/$f" | sha256sum -c - >/dev/null`, `${su}mkdir -p "${dir}"`);
391
414
  const member = s.member?.("$w") ?? s.bin;
392
415
  switch (s.layout) {
393
416
  case "binary":
394
- lines.push(`install -m 0755 "$t/$f" "${dir}/${s.bin}"`);
417
+ lines.push(`${su}install -m 0755 "$t/$f" "${dir}/${s.bin}"`);
395
418
  break;
396
419
  case "tar.gz":
397
- lines.push(`tar -xzf "$t/$f" -C "$t" "${member}"`, `install -m 0755 "$t/${member}" "${dir}/${s.bin}"`);
420
+ lines.push(`tar -xzf "$t/$f" -C "$t" "${member}"`, `${su}install -m 0755 "$t/${member}" "${dir}/${s.bin}"`);
398
421
  break;
399
422
  case "zip":
400
- lines.push(`unzip -q -o "$t/$f" "${member}" -d "$t"`, `install -m 0755 "$t/${member}" "${dir}/${s.bin}"`);
423
+ lines.push(`unzip -q -o "$t/$f" "${member}" -d "$t"`, `${su}install -m 0755 "$t/${member}" "${dir}/${s.bin}"`);
401
424
  break;
402
425
  case "tree":
403
- lines.push(`tar -xzf "$t/$f" -C "${dir}" --strip-components=1`);
426
+ lines.push(`${su}tar -xzf "$t/$f" -C "${dir}" --strip-components=1`);
404
427
  break;
405
428
  case "aws-cli":
406
- lines.push(`unzip -q "$t/$f" -d "$t"`, `"$t/aws/install" -i "${dir}" -b "${dir}/bin"`);
429
+ lines.push(`unzip -q "$t/$f" -d "$t"`, `${su}"$t/aws/install" -i "${dir}" -b "${dir}/bin"`);
407
430
  break;
408
431
  }
409
432
  return lines.join(" && ");
410
433
  }
411
434
 
412
435
  export interface CiToolInstallOptions extends CiToolCheckOptions {
413
- /** Where the versioned directories live. Default {@link CI_TOOL_ROOT}. */
436
+ /**
437
+ * Where the versioned directories live. Default {@link CI_TOOL_ROOT}. It
438
+ * may start with a variable the job's shell expands (#4908), such as
439
+ * `$RUNNER_TEMP/chant-tools`, for a job that is not root.
440
+ */
414
441
  root?: string;
415
- /** Link the binary into /usr/local/bin (default true). `false` leaves PATH alone, for a pin a step runs by its path. */
442
+ /** Link the binary into `binDir` (default true). `false` leaves PATH alone, for a pin a step runs by its path. */
416
443
  link?: boolean;
444
+ /**
445
+ * Where the link goes. Default /usr/local/bin. Like `root` it may start
446
+ * with a variable (#4908), such as `$HOME/.local/bin`; the job puts it on
447
+ * PATH.
448
+ */
449
+ binDir?: string;
450
+ /**
451
+ * Install into `root` and link into `binDir` with `sudo` (#4908), for a
452
+ * job that runs as a user who cannot write them, as on GitHub's hosted
453
+ * runners. The download and the check run as the job's user. Default false.
454
+ */
455
+ sudo?: boolean;
417
456
  /** Skip the install when any `<bin>` is on PATH, whatever its version. Default false: only the versioned directory counts. */
418
457
  onPath?: boolean;
419
458
  }
@@ -433,9 +472,15 @@ export function ciToolInstallLine(tool: CiTool, version: string, options: CiTool
433
472
  const dir = ciToolDir(tool, version, root);
434
473
  const bin = ciToolBin(tool, version, root);
435
474
  const s = spec(tool);
436
- const install = `(set -e; ${ciToolFetchScript(tool, version, { dir, sha256: options.sha256, requirePin: options.requirePin })})`;
475
+ const binDir = (options.binDir ?? "/usr/local/bin").replace(/(.)\/+$/, "$1");
476
+ if (!SHELL_DIR.test(binDir)) throw new Error(`binDir is an absolute path of letters, digits and ._/-, or one under a variable such as $HOME, not ${JSON.stringify(options.binDir)}`);
477
+ const su = options.sudo ? "sudo " : "";
478
+ const install = `(set -e; ${ciToolFetchScript(tool, version, { dir, sha256: options.sha256, requirePin: options.requirePin, sudo: options.sudo })})`;
437
479
  const inDir = `[ -x "${bin}" ]`;
438
- const line = options.link === false ? `${inDir} || ${install}` : `{ ${inDir} || ${install}; } && ln -sf "${bin}" /usr/local/bin/${s.bin}`;
480
+ // A plain path is written as it always was; one under a variable is quoted, so the shell expands it as one word.
481
+ const target = DIR.test(binDir) ? `${binDir}/${s.bin}` : `"${binDir}/${s.bin}"`;
482
+ const link = `${su}${options.binDir !== undefined ? `mkdir -p "${binDir}" && ${su}` : ""}ln -sf "${bin}" ${target}`;
483
+ const line = options.link === false ? `${inDir} || ${install}` : `{ ${inDir} || ${install}; } && ${link}`;
439
484
  return options.onPath ? `command -v ${s.bin} >/dev/null 2>&1 || { ${line}; }` : line;
440
485
  }
441
486
 
@@ -582,7 +627,19 @@ export const CI_BASE_IMAGES = {
582
627
  export const CI_IMAGE_LABEL_ARG = "CHANT_RELEASE_LABEL";
583
628
 
584
629
  /** One Dockerfile instruction, as the docker lexicon's stage `steps` take it: `{ run: "..." }`. */
585
- export type CiImageStep = Readonly<Partial<Record<"arg" | "env" | "run" | "copy" | "label" | "cmd" | "user" | "workdir" | "expose" | "entrypoint", string>>>;
630
+ /** The Dockerfile instructions a {@link CiImageStep} names. */
631
+ export type CiImageInstruction = "arg" | "env" | "run" | "copy" | "label" | "cmd" | "user" | "workdir" | "expose" | "entrypoint";
632
+
633
+ /**
634
+ * One Dockerfile instruction, as the docker lexicon's stage `steps` take it:
635
+ * `{ run: "..." }`. One key each, the others `never`, the shape of the
636
+ * lexicon's `DockerfileStep`, so `new Dockerfile({ stages:
637
+ * productImageStages(spec) })` compiles under `exactOptionalPropertyTypes`
638
+ * (#4932).
639
+ */
640
+ export type CiImageStep = {
641
+ [K in CiImageInstruction]: { readonly [P in K]: string } & { readonly [P in Exclude<CiImageInstruction, K>]?: never };
642
+ }[CiImageInstruction];
586
643
 
587
644
  /** One stage, as the docker lexicon's `new Dockerfile({ stages })` takes it. */
588
645
  export interface CiImageStage {
@@ -736,6 +793,8 @@ export function productImageStages(spec: ProductImageSpec): CiImageStage[] {
736
793
  for (const p of spec.npm ?? []) if (!PKG.test(p)) throw new Error(`npm package ${JSON.stringify(p)} is not a name at an exact version`);
737
794
  if (spec.chant !== undefined && !VERSION.test(spec.chant)) throw new Error(`chant ${JSON.stringify(spec.chant)} is not a release version`);
738
795
  const root = spec.toolRoot ?? `/opt/${spec.product}`;
796
+ // An image's COPY takes no shell variable, so the tool root is a plain path here.
797
+ if (!DIR.test(root)) throw new Error(`toolRoot ${JSON.stringify(root)} is not an absolute path of letters, digits and ._/-`);
739
798
  const tools = spec.tools ?? [];
740
799
  const seen = new Set<string>();
741
800
  for (const t of tools) {
package/src/ci-jobs.ts CHANGED
@@ -339,6 +339,9 @@ const USES_PATTERN = /^([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)((?:\/[A-Za-z0-9_.-]+
339
339
  export function assertSetupSteps(name: string, setup: OpSetupStep[]): void {
340
340
  setup.forEach((step, index) => {
341
341
  const where = `Scheduled Op "${name}" setup step ${index + 1}`;
342
+ if (step.name !== undefined && (step.name.trim() === "" || /[\r\n]/.test(step.name))) {
343
+ throw new Error(`${where} has a blank or multi-line \`name\`. Give the step a one-line name, or leave it out.`);
344
+ }
342
345
  if ("uses" in step) {
343
346
  const ref = step.uses.trim();
344
347
  const match = USES_PATTERN.exec(ref);
@@ -368,16 +371,18 @@ export function assertSetupSteps(name: string, setup: OpSetupStep[]): void {
368
371
  });
369
372
  }
370
373
 
371
- /** One setup entry as a GitHub Actions step: `with:` and `env:` only when they hold something. */
374
+ /** One setup entry as a GitHub Actions step: its `name` when it has one (#4932), `with:` and `env:` only when they hold something. */
372
375
  export function setupStepDoc(step: OpSetupStep): Record<string, unknown> {
376
+ const name = step.name !== undefined ? { name: step.name } : {};
373
377
  if ("uses" in step) {
374
378
  return {
379
+ ...name,
375
380
  uses: step.uses,
376
381
  ...nonEmpty("with", step.with),
377
382
  ...nonEmpty("env", step.env),
378
383
  };
379
384
  }
380
- return { run: step.run, ...nonEmpty("env", step.env) };
385
+ return { ...name, run: step.run, ...nonEmpty("env", step.env) };
381
386
  }
382
387
 
383
388
  /**
@@ -13,8 +13,8 @@ import { tmpdir } from "node:os";
13
13
  import { join } from "node:path";
14
14
  import { promisify } from "node:util";
15
15
  import { afterAll, beforeAll, describe, expect, test } from "vitest";
16
- import { cloudLogin, forgejoCloudLogin, githubCloudLogin, gitlabCloudLogin, LOGIN_JS, LOGIN_SPEC_ENV, type CloudLoginSpec, type LoginForge } from "./ci-login";
17
- import { CLOUD_TARGETS_ENV, resolveCloudIdentity, targetCloudEnv, type CloudIdentityDeclaration } from "./ci-identity";
16
+ import { cloudLogin, cloudLoginSpec, forgejoCloudLogin, githubCloudLogin, GITLAB_LOGIN_VARS, gitlabCloudLogin, LOGIN_JS, LOGIN_SPEC_ENV, type CloudLoginSpec, type LoginForge } from "./ci-login";
17
+ import { CLOUD_TARGETS_ENV, CLOUD_TRADED_ENV, cloudsTraded, resolveCloudIdentity, targetCloudEnv, TRADE_SPEC_ENV, tradeLine, type CloudIdentityDeclaration, type CloudTradeSpec } from "./ci-identity";
18
18
  import { EMULATED_JWT_PREFIX, startOidcEmulator, type OidcEmulator } from "./__fixtures__/oidc-emulator";
19
19
 
20
20
  const run = promisify(execFile);
@@ -78,7 +78,7 @@ describe("the rendered login (#4788)", () => {
78
78
  expect(() => githubCloudLogin({ pulumi: { organization: "o", audience: "a", token: "team:x" } } as unknown as CloudLoginSpec)).toThrow(/Pulumi Cloud\) is traded/);
79
79
  expect(() => githubCloudLogin({ azure: { ...SPEC.azure!, database: true } } as unknown as CloudLoginSpec)).toThrow(/no database token/);
80
80
  expect(() => githubCloudLogin({ aws: { role: "arn:aws:iam::1:role/a b" } })).toThrow(/role is .*printable ASCII with no space/);
81
- expect(() => githubCloudLogin({ aws: {} })).toThrow(/names no identity/);
81
+ expect(() => githubCloudLogin({ azure: { tenantId: TENANT } })).toThrow(/names no identity/);
82
82
  expect(() => githubCloudLogin({ aws: { role: "r", sessionName: "x" } })).toThrow(/sessionName/);
83
83
  expect(() => githubCloudLogin({ aws: { role: "r", tokenFile: "$(id)" } })).toThrow(/tokenFile/);
84
84
  expect(() => githubCloudLogin({ azure: { tenantId: TENANT, targets: [{ targets: ["a"], clientId: "c" }], cli: true } })).toThrow(/needs clientId/);
@@ -233,3 +233,131 @@ describe("the login, run (#4788)", () => {
233
233
  expect(lines[1]).toBe(`account set --subscription ${SPEC.azure!.subscriptionId}`);
234
234
  });
235
235
  });
236
+
237
+ describe("the gaps terragucci's login needs closed (#4930)", () => {
238
+ let emu: OidcEmulator;
239
+ beforeAll(async () => {
240
+ emu = await startOidcEmulator();
241
+ });
242
+ afterAll(async () => {
243
+ await emu.close();
244
+ });
245
+
246
+ const parseEnv = (text: string): Record<string, string> => Object.fromEntries(text.trim().split("\n").filter(Boolean).map((l) => [l.slice(0, l.indexOf("=")), l.slice(l.indexOf("=") + 1)]));
247
+
248
+ /**
249
+ * Runs a login and then `env` in one shell with -e off, as terragucci's
250
+ * steps run (they read each stage's exit code): the variables the same
251
+ * step sees, and what `$GITHUB_ENV` got.
252
+ */
253
+ async function oneStep(forge: LoginForge, spec: CloudLoginSpec, sameStep: boolean, env: Record<string, string> = {}) {
254
+ const dir = mkdtempSync(join(tmpdir(), "chant-login-4930-"));
255
+ const githubEnv = join(dir, "github-env");
256
+ writeFileSync(githubEnv, "");
257
+ const { steps, idTokens } = cloudLogin(forge, spec, { sameStep });
258
+ const tokens = forge === "gitlab" ? Object.fromEntries(Object.keys(idTokens).map((k) => [k, `eyJgitlab.${k}.1`])) : emu.requestEnv;
259
+ const script = ["set +e", ...steps[0]!.run, "env"].join("\n");
260
+ const r = await run("bash", ["-c", script], { env: { PATH: process.env.PATH!, GITHUB_ENV: githubEnv, RUNNER_TEMP: dir, TMPDIR: dir, ...tokens, ...env } }).catch((e: { stdout: string; stderr: string; code: number }) => ({ stdout: e.stdout, stderr: e.stderr, failed: e.code }));
261
+ return { dir, step: parseEnv(r.stdout), githubEnv: parseEnv(readFileSync(githubEnv, "utf-8")), run: r };
262
+ }
263
+
264
+ test.each(FORGES)("%s: a spec with no region leaves the job's region, and one that names it sets it as before", async (forge) => {
265
+ const none = await oneStep(forge, { aws: { role: "arn:aws:iam::1:role/p" } }, true, { AWS_REGION: "ap-south-1", AWS_DEFAULT_REGION: "ap-south-1" });
266
+ expect(none.step).toMatchObject({ AWS_ROLE_ARN: "arn:aws:iam::1:role/p", AWS_REGION: "ap-south-1", AWS_DEFAULT_REGION: "ap-south-1" });
267
+ const unset = await oneStep(forge, { aws: { role: "arn:aws:iam::1:role/p" } }, true);
268
+ expect(unset.step.AWS_REGION).toBeUndefined();
269
+ expect(unset.step.AWS_DEFAULT_REGION).toBeUndefined();
270
+ expect(cloudLoginSpec({ aws: { role: "r" } })).toEqual({ aws: { role: "r", audience: "sts.amazonaws.com" } });
271
+ const named = await oneStep(forge, SPEC, true);
272
+ expect(named.step).toMatchObject({ AWS_REGION: "eu-west-1", AWS_DEFAULT_REGION: "eu-west-1" });
273
+ });
274
+
275
+ test("a spec that names a region renders as before: the same spec, in the same order", () => {
276
+ expect(cloudLoginSpec(SPEC).aws).toEqual({ role: SPEC.aws!.role, region: "eu-west-1", sessionName: "terragucci-plan", audience: "sts.amazonaws.com" });
277
+ expect(Object.keys(cloudLoginSpec(SPEC).aws!)).toEqual(["role", "region", "sessionName", "audience"]);
278
+ expect(Object.keys(cloudLoginSpec({ aws: { region: "eu-west-1", role: "r" } }).aws!)).toEqual(["region", "role", "audience"]);
279
+ for (const forge of FORGES) expect(cloudLogin(forge, SPEC, { sameStep: false })).toEqual(cloudLogin(forge, SPEC));
280
+ });
281
+
282
+ test.each(["github", "forgejo"] as const)("%s: sameStep exports into the step that runs the login, and leaves $GITHUB_ENV alone", async (forge) => {
283
+ const { step, githubEnv, run: r } = await oneStep(forge, SPEC, true);
284
+ expect(r).not.toHaveProperty("failed");
285
+ expect(githubEnv).toEqual({});
286
+ expect(step).toMatchObject({ AWS_ROLE_ARN: SPEC.aws!.role, ARM_CLIENT_ID: SPEC.azure!.clientId });
287
+ expect(readFileSync(step.AWS_WEB_IDENTITY_TOKEN_FILE!, "utf-8")).toContain(Buffer.from(AUD.aws).toString("base64url"));
288
+ expect(JSON.parse(readFileSync(step.GOOGLE_APPLICATION_CREDENTIALS!, "utf-8")).type).toBe("external_account");
289
+ for (const k of [LOGIN_SPEC_ENV, GITLAB_LOGIN_VARS]) expect(step[k]).toBeUndefined();
290
+ // Without it, the step itself sees nothing: the variables are for later steps.
291
+ const later = await oneStep(forge, SPEC, false);
292
+ expect(later.step.AWS_ROLE_ARN).toBeUndefined();
293
+ expect(later.githubEnv.AWS_ROLE_ARN).toBe(SPEC.aws!.role);
294
+ });
295
+
296
+ test("gitlab: sameStep is the script's own lines, as before, and the id_tokens variables are unset", async () => {
297
+ const { step, run: r } = await oneStep("gitlab", SPEC, true);
298
+ expect(r).not.toHaveProperty("failed");
299
+ expect(step).toMatchObject({ AWS_ROLE_ARN: SPEC.aws!.role });
300
+ expect(readFileSync(step.AWS_WEB_IDENTITY_TOKEN_FILE!, "utf-8")).toBe("eyJgitlab.CHANT_ID_TOKEN_AWS.1");
301
+ for (const k of ["CHANT_ID_TOKEN_AWS", "CHANT_ID_TOKEN_GCP", "CHANT_ID_TOKEN_AZURE", LOGIN_SPEC_ENV]) expect(step[k]).toBeUndefined();
302
+ });
303
+
304
+ test.each(FORGES)("%s: sameStep stops the step on a failed login even with -e off, before the next line", async (forge) => {
305
+ const { run: r, step } = await oneStep(forge, { aws: { role: "r", tokenFile: "$NOWHERE/token" } }, true, { NOWHERE: "/nonexistent-4930" });
306
+ expect(r).toMatchObject({ failed: 1, stderr: expect.stringContaining("aws's tokenFile /nonexistent-4930/token cannot be read") });
307
+ expect(step).toEqual({});
308
+ });
309
+
310
+ test.each(FORGES)("%s: an AWS spec with no role points the job at the token file alone, as a Terragrunt credentials job takes it", async (forge) => {
311
+ const dir = mkdtempSync(join(tmpdir(), "chant-login-4930-tok-"));
312
+ writeFileSync(join(dir, "aws"), "eyJstaged.token.1\n");
313
+ expect(cloudLogin(forge, { aws: { tokenFile: "$STAGED/aws" } }).idTokens).toEqual({});
314
+ const staged = await oneStep(forge, { aws: { tokenFile: "$STAGED/aws", sessionName: "terragucci-plan" } }, true, { STAGED: dir });
315
+ expect(staged.run).not.toHaveProperty("failed");
316
+ expect(staged.step).toMatchObject({ AWS_WEB_IDENTITY_TOKEN_FILE: join(dir, "aws"), AWS_ROLE_SESSION_NAME: "terragucci-plan" });
317
+ expect(staged.step.AWS_ROLE_ARN).toBeUndefined();
318
+ // With no tokenFile the job requests the token, as for a role.
319
+ expect(cloudLogin(forge, { aws: {} }).idTokens).toEqual({ CHANT_ID_TOKEN_AWS: AUD.aws });
320
+ const requested = await oneStep(forge, { aws: {} }, true);
321
+ expect(readFileSync(requested.step.AWS_WEB_IDENTITY_TOKEN_FILE!, "utf-8")).toMatch(forge === "gitlab" ? /^eyJgitlab\.CHANT_ID_TOKEN_AWS\.1$/ : new RegExp(Buffer.from(AUD.aws).toString("base64url")));
322
+ expect(requested.step.AWS_ROLE_SESSION_NAME).toBe("chant");
323
+ // GCP and Azure still need an identity: their files and variables name one.
324
+ expect(() => cloudLogin(forge, { gcp: { provider: PROVIDER } })).toThrow(/names no identity/);
325
+ });
326
+
327
+ test("an AWS spec with roles by target and none of its own: each target's role, and the token file for the rest", async () => {
328
+ const { step } = await oneStep("github", { aws: { targets: [{ targets: ["envs/prod/**"], role: "arn:aws:iam::1:role/prod" }] } }, true, { AWS_REGION: "ap-south-1" });
329
+ expect(step.AWS_ROLE_ARN).toBeUndefined();
330
+ expect(step.AWS_WEB_IDENTITY_TOKEN_FILE).toBeDefined();
331
+ const prod = targetCloudEnv(step, "envs/prod/net");
332
+ expect(prod).toMatchObject({ AWS_ROLE_ARN: "arn:aws:iam::1:role/prod", AWS_WEB_IDENTITY_TOKEN_FILE: step.AWS_WEB_IDENTITY_TOKEN_FILE, AWS_REGION: "ap-south-1" });
333
+ expect(targetCloudEnv(step, "envs/dev/net").AWS_ROLE_ARN).toBeUndefined();
334
+ });
335
+
336
+ test.each(FORGES)("%s: a login's targets file is no trade's: CHANT_CLOUD_TRADED stays unset", async (forge) => {
337
+ const spec: CloudLoginSpec = { aws: { role: "arn:aws:iam::1:role/default", targets: [{ targets: ["envs/prod/**"], role: "arn:aws:iam::1:role/prod" }] } };
338
+ const { step } = await oneStep(forge, spec, true);
339
+ expect(step[CLOUD_TARGETS_ENV]).toBeDefined();
340
+ expect(step[CLOUD_TRADED_ENV]).toBeUndefined();
341
+ expect(cloudsTraded(step)).toEqual([]);
342
+ });
343
+
344
+ test("the trade says it traded, with or without targets, so its targets file is told from a login's", async () => {
345
+ const dir = mkdtempSync(join(tmpdir(), "chant-trade-4930-"));
346
+ const trade = async (spec: CloudTradeSpec): Promise<Record<string, string>> => {
347
+ const file = join(dir, `github-env-${Math.random().toString(16).slice(2)}`);
348
+ writeFileSync(file, "");
349
+ await run("sh", ["-c", tradeLine(file, "github-env")], { env: { PATH: process.env.PATH!, ...emu.requestEnv, RUNNER_TEMP: dir, [TRADE_SPEC_ENV]: JSON.stringify(emu.pointAt(spec)) } });
350
+ return parseEnv(readFileSync(file, "utf-8"));
351
+ };
352
+ const aws = { role: "arn:aws:iam::1:role/default", region: "eu-west-1", audience: "sts.amazonaws.com" };
353
+ const targeted = await trade({ aws: { ...aws, targets: [{ targets: ["envs/prod/**"], role: "arn:aws:iam::1:role/prod" }] }, gcp: { serviceAccount: "plan@p.iam.gserviceaccount.com", provider: PROVIDER, audience: AUD.gcp } });
354
+ expect(targeted[CLOUD_TARGETS_ENV]).toBeDefined();
355
+ expect(targeted[CLOUD_TRADED_ENV]).toBe("aws,gcp");
356
+ expect(cloudsTraded(targeted)).toEqual(["aws", "gcp"]);
357
+ // A trade's identity sets its own region, so a target still gets it.
358
+ expect(targetCloudEnv({ ...targeted, AWS_REGION: "ap-south-1" }, "envs/prod/net").AWS_REGION).toBe("eu-west-1");
359
+ const plain = await trade({ aws });
360
+ expect(plain[CLOUD_TARGETS_ENV]).toBeUndefined();
361
+ expect(plain[CLOUD_TRADED_ENV]).toBe("aws");
362
+ });
363
+ });