@smoothbricks/nx-plugin 0.4.26 → 0.4.27

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 (343) hide show
  1. package/README.md +994 -117
  2. package/dist/bin/smoo-nx-bound-failures.d.ts +3 -0
  3. package/dist/bin/smoo-nx-bound-failures.d.ts.map +1 -0
  4. package/dist/bin/smoo-nx-bound-failures.js +31 -0
  5. package/dist/bin/smoo-nx-cargo-hash.js +28 -3
  6. package/dist/bin/smoo-nx-exec.js +15 -73
  7. package/dist/bin/smoo-nx-failures.d.ts +3 -0
  8. package/dist/bin/smoo-nx-failures.d.ts.map +1 -0
  9. package/dist/bin/smoo-nx-failures.js +3 -0
  10. package/dist/bin/smoo-nx-nextest-extract.js +3 -2
  11. package/dist/bin/smoo-nx-test-walks.d.ts +3 -0
  12. package/dist/bin/smoo-nx-test-walks.d.ts.map +1 -0
  13. package/dist/bin/smoo-nx-test-walks.js +34 -0
  14. package/dist/bounded-test-policy.d.ts +7 -1
  15. package/dist/bounded-test-policy.d.ts.map +1 -1
  16. package/dist/bounded-test-policy.js +101 -40
  17. package/dist/build-state-output-policy.d.ts +25 -0
  18. package/dist/build-state-output-policy.d.ts.map +1 -0
  19. package/dist/build-state-output-policy.js +64 -0
  20. package/dist/cargo-closure-input.d.ts +3 -2
  21. package/dist/cargo-closure-input.d.ts.map +1 -1
  22. package/dist/cargo-closure-input.js +16 -15
  23. package/dist/cargo-dev-profile.d.ts +37 -0
  24. package/dist/cargo-dev-profile.d.ts.map +1 -0
  25. package/dist/cargo-dev-profile.js +108 -0
  26. package/dist/cargo-source-hash.d.ts +43 -6
  27. package/dist/cargo-source-hash.d.ts.map +1 -1
  28. package/dist/cargo-source-hash.js +309 -73
  29. package/dist/cargo-toolchain-policy.d.ts +4 -0
  30. package/dist/cargo-toolchain-policy.d.ts.map +1 -1
  31. package/dist/cargo-toolchain-policy.js +5 -0
  32. package/dist/cargo-workspace.d.ts +101 -5
  33. package/dist/cargo-workspace.d.ts.map +1 -1
  34. package/dist/cargo-workspace.js +291 -10
  35. package/dist/cross-check-policy.d.ts +21 -3
  36. package/dist/cross-check-policy.d.ts.map +1 -1
  37. package/dist/cross-check-policy.js +24 -6
  38. package/dist/disk-command-policy.d.ts +7 -0
  39. package/dist/disk-command-policy.d.ts.map +1 -0
  40. package/dist/disk-command-policy.js +98 -0
  41. package/dist/ensure-built-receipt.d.ts +25 -0
  42. package/dist/ensure-built-receipt.d.ts.map +1 -0
  43. package/dist/ensure-built-receipt.js +261 -0
  44. package/dist/ensure-built-witness.d.ts +57 -0
  45. package/dist/ensure-built-witness.d.ts.map +1 -0
  46. package/dist/ensure-built-witness.js +412 -0
  47. package/dist/ensure-built.d.ts +207 -12
  48. package/dist/ensure-built.d.ts.map +1 -1
  49. package/dist/ensure-built.js +576 -202
  50. package/dist/eslint-file-set.d.ts +7 -0
  51. package/dist/eslint-file-set.d.ts.map +1 -0
  52. package/dist/eslint-file-set.js +12 -0
  53. package/dist/executors/bounded-exec/cpu-pool.d.ts +63 -0
  54. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -0
  55. package/dist/executors/bounded-exec/cpu-pool.js +379 -0
  56. package/dist/executors/bounded-exec/cpu-tokens.d.ts +82 -0
  57. package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +1 -0
  58. package/dist/executors/bounded-exec/cpu-tokens.js +114 -0
  59. package/dist/executors/bounded-exec/disk-lease.d.ts +61 -0
  60. package/dist/executors/bounded-exec/disk-lease.d.ts.map +1 -0
  61. package/dist/executors/bounded-exec/disk-lease.js +91 -0
  62. package/dist/executors/bounded-exec/executor.d.ts +45 -2
  63. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  64. package/dist/executors/bounded-exec/executor.js +447 -52
  65. package/dist/executors/bounded-exec/gateway-lease.d.ts +52 -0
  66. package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -0
  67. package/dist/executors/bounded-exec/gateway-lease.js +143 -0
  68. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +35 -0
  69. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -0
  70. package/dist/executors/bounded-exec/hang-diagnostics.js +231 -0
  71. package/dist/executors/bounded-exec/progress.d.ts +35 -0
  72. package/dist/executors/bounded-exec/progress.d.ts.map +1 -0
  73. package/dist/executors/bounded-exec/progress.js +79 -0
  74. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts +3 -0
  75. package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts.map +1 -0
  76. package/dist/executors/bounded-exec/ram-temp-fixtures.js +12 -0
  77. package/dist/executors/bounded-exec/ram-temp-held.d.ts +91 -0
  78. package/dist/executors/bounded-exec/ram-temp-held.d.ts.map +1 -0
  79. package/dist/executors/bounded-exec/ram-temp-held.js +152 -0
  80. package/dist/executors/bounded-exec/ram-temp.d.ts +223 -0
  81. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -0
  82. package/dist/executors/bounded-exec/ram-temp.js +1528 -0
  83. package/dist/executors/bounded-exec/schema.d.ts +29 -11
  84. package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
  85. package/dist/executors/bounded-exec/verdict.d.ts +162 -0
  86. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -0
  87. package/dist/executors/bounded-exec/verdict.js +318 -0
  88. package/dist/executors/shard-timings/executor.d.ts +14 -0
  89. package/dist/executors/shard-timings/executor.d.ts.map +1 -0
  90. package/dist/executors/shard-timings/executor.js +25 -0
  91. package/dist/executors/shard-timings/schema.d.ts +4 -0
  92. package/dist/executors/shard-timings/schema.d.ts.map +1 -0
  93. package/dist/executors/shard-timings/schema.js +1 -0
  94. package/dist/failure-summary.d.ts +5 -0
  95. package/dist/failure-summary.d.ts.map +1 -0
  96. package/dist/failure-summary.js +118 -0
  97. package/dist/generators/create-package/generator.d.ts.map +1 -1
  98. package/dist/generators/create-package/generator.js +6 -2
  99. package/dist/index.d.ts +14 -2
  100. package/dist/index.d.ts.map +1 -1
  101. package/dist/index.js +370 -138
  102. package/dist/managed-files/ci-workflow.d.ts +13 -0
  103. package/dist/managed-files/ci-workflow.d.ts.map +1 -1
  104. package/dist/managed-files/ci-workflow.js +44 -13
  105. package/dist/managed-files/files.d.ts +7 -1
  106. package/dist/managed-files/files.d.ts.map +1 -1
  107. package/dist/managed-files/files.js +62 -8
  108. package/dist/managed-files/json-edit.d.ts +21 -0
  109. package/dist/managed-files/json-edit.d.ts.map +1 -0
  110. package/dist/managed-files/json-edit.js +295 -0
  111. package/dist/managed-files/managed-format.d.ts +33 -1
  112. package/dist/managed-files/managed-format.d.ts.map +1 -1
  113. package/dist/managed-files/managed-format.js +82 -2
  114. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts +7 -0
  115. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts.map +1 -1
  116. package/dist/managed-files/pr-preview-cleanup-workflow.js +68 -4
  117. package/dist/managed-files/publish-workflow.d.ts.map +1 -1
  118. package/dist/managed-files/publish-workflow.js +231 -48
  119. package/dist/managed-files/tree.d.ts +5 -0
  120. package/dist/managed-files/tree.d.ts.map +1 -1
  121. package/dist/managed-files/tree.js +5 -3
  122. package/dist/manifest-hash.d.ts.map +1 -1
  123. package/dist/manifest-hash.js +2 -5
  124. package/dist/nextest-code-bound.d.ts +62 -0
  125. package/dist/nextest-code-bound.d.ts.map +1 -0
  126. package/dist/nextest-code-bound.js +154 -0
  127. package/dist/nextest-extraction.d.ts +24 -8
  128. package/dist/nextest-extraction.d.ts.map +1 -1
  129. package/dist/nextest-extraction.js +42 -7
  130. package/dist/package-target-policy.d.ts.map +1 -1
  131. package/dist/package-target-policy.js +3 -5
  132. package/dist/release-config-policy.d.ts.map +1 -1
  133. package/dist/release-config-policy.js +3 -5
  134. package/dist/runtime-input.d.ts +14 -0
  135. package/dist/runtime-input.d.ts.map +1 -0
  136. package/dist/runtime-input.js +15 -0
  137. package/dist/rust-tokens.d.ts +11 -0
  138. package/dist/rust-tokens.d.ts.map +1 -0
  139. package/dist/rust-tokens.js +81 -0
  140. package/dist/task-results.d.ts +6 -0
  141. package/dist/task-results.d.ts.map +1 -0
  142. package/dist/task-results.js +61 -0
  143. package/dist/test-program.d.ts +54 -0
  144. package/dist/test-program.d.ts.map +1 -0
  145. package/dist/test-program.js +292 -0
  146. package/dist/test-timings.d.ts +71 -0
  147. package/dist/test-timings.d.ts.map +1 -0
  148. package/dist/test-timings.js +393 -0
  149. package/dist/test-walk-policy.d.ts +103 -0
  150. package/dist/test-walk-policy.d.ts.map +1 -0
  151. package/dist/test-walk-policy.js +657 -0
  152. package/dist/testing.d.ts +177 -0
  153. package/dist/testing.d.ts.map +1 -0
  154. package/dist/testing.js +824 -0
  155. package/dist/type-guards.d.ts +3 -0
  156. package/dist/type-guards.d.ts.map +1 -0
  157. package/dist/type-guards.js +4 -0
  158. package/dist/typecheck-test-policy.d.ts +8 -5
  159. package/dist/typecheck-test-policy.d.ts.map +1 -1
  160. package/dist/typecheck-test-policy.js +113 -100
  161. package/dist/workspace-config-policy.d.ts +8 -0
  162. package/dist/workspace-config-policy.d.ts.map +1 -1
  163. package/dist/workspace-config-policy.js +175 -63
  164. package/dist/workspace-index.d.ts +12 -0
  165. package/dist/workspace-index.d.ts.map +1 -0
  166. package/dist/workspace-index.js +17 -0
  167. package/dist/workspace-manifest.d.ts +37 -0
  168. package/dist/workspace-manifest.d.ts.map +1 -1
  169. package/executors.json +5 -0
  170. package/loader.js +13 -11
  171. package/managed/raw/envrc +33 -67
  172. package/managed/raw/git-format-staged.yml +30 -35
  173. package/managed/raw/patches/nx@23.2.1.patch +3484 -0
  174. package/managed/raw/tooling/direnv/apple-developer.sh +83 -0
  175. package/managed/raw/tooling/direnv/developer-links.ts +569 -11
  176. package/managed/raw/tooling/direnv/devenv.smoo.nix +314 -93
  177. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +20 -11
  178. package/managed/raw/tooling/direnv/linked-snapshots.ts +845 -0
  179. package/managed/raw/tooling/direnv/nx-socket-dir.sh +82 -0
  180. package/managed/raw/tooling/direnv/repo-path +14 -2
  181. package/managed/raw/tooling/direnv/setup-environment.ts +962 -148
  182. package/managed/raw/tooling/direnv/toolchain-stamp.ts +45 -3
  183. package/managed/raw/tooling/direnv/ttsc-env.sh +39 -0
  184. package/managed/raw/tooling/git-hooks/commit-msg.sh +5 -6
  185. package/managed/raw/tooling/git-hooks/pre-commit.sh +7 -6
  186. package/managed/raw/tooling/git-hooks/pre-push.sh +20 -15
  187. package/managed/templates/github/actions/cache-nix-devenv/action.yml +6 -6
  188. package/managed/templates/github/actions/cache-node-modules/action.yml +6 -4
  189. package/managed/templates/github/actions/cache-nx/action.yml +1 -1
  190. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +1 -1
  191. package/managed/templates/github/actions/forgejo-artifact.cjs +99 -0
  192. package/managed/templates/github/actions/forgejo-download-artifact/action.yml +49 -0
  193. package/managed/templates/github/actions/forgejo-download-artifact/index.cjs +7 -0
  194. package/managed/templates/github/actions/forgejo-upload-artifact/action.yml +65 -0
  195. package/managed/templates/github/actions/forgejo-upload-artifact/index.cjs +7 -0
  196. package/managed/templates/github/actions/setup-devenv/action.yml +21 -3
  197. package/managed/templates/github/workflows/managed-files.yml +1 -2
  198. package/nextest.toml +8 -41
  199. package/package.json +74 -12
  200. package/runtime-input.sh +81 -0
  201. package/src/__tests__/counted-cargo.ts +33 -14
  202. package/src/__tests__/fixture-nx-env.ts +111 -46
  203. package/src/__tests__/progress-clock.ts +43 -0
  204. package/src/__tests__/runtime-input.ts +23 -0
  205. package/src/bin/smoo-nx-bound-failures.test.ts +127 -0
  206. package/src/bin/smoo-nx-bound-failures.ts +33 -0
  207. package/src/bin/smoo-nx-cargo-hash.ts +28 -3
  208. package/src/bin/smoo-nx-exec.ts +16 -74
  209. package/src/bin/smoo-nx-failures.ts +4 -0
  210. package/src/bin/smoo-nx-nextest-extract.ts +3 -2
  211. package/src/bin/smoo-nx-test-walks.ts +42 -0
  212. package/src/bounded-test-policy.test.ts +268 -21
  213. package/src/bounded-test-policy.ts +114 -42
  214. package/src/build-state-output-policy.test.ts +115 -0
  215. package/src/build-state-output-policy.ts +90 -0
  216. package/src/bun-bootstrap.test.ts +57 -3
  217. package/src/bun-file-packages.test.ts +47 -0
  218. package/src/cargo-closure-input.test.ts +138 -66
  219. package/src/cargo-closure-input.ts +17 -15
  220. package/src/cargo-dev-profile.ts +137 -0
  221. package/src/cargo-resolve-cache.test.ts +70 -1
  222. package/src/cargo-source-hash.test.ts +193 -97
  223. package/src/cargo-source-hash.ts +345 -68
  224. package/src/cargo-toolchain-policy.ts +6 -0
  225. package/src/cargo-workspace.test.ts +320 -0
  226. package/src/cargo-workspace.ts +336 -10
  227. package/src/cross-check-policy.test.ts +59 -1
  228. package/src/cross-check-policy.ts +25 -6
  229. package/src/disk-command-policy.test.ts +61 -0
  230. package/src/disk-command-policy.ts +107 -0
  231. package/src/ensure-built-receipt.test.ts +184 -0
  232. package/src/ensure-built-receipt.ts +263 -0
  233. package/src/ensure-built-witness.test.ts +344 -0
  234. package/src/ensure-built-witness.ts +252 -0
  235. package/src/ensure-built.test.ts +1036 -578
  236. package/src/ensure-built.ts +820 -224
  237. package/src/eslint-file-set.ts +9 -0
  238. package/src/executors/bounded-exec/cpu-pool.test.ts +454 -0
  239. package/src/executors/bounded-exec/cpu-pool.ts +417 -0
  240. package/src/executors/bounded-exec/cpu-tokens.test.ts +269 -0
  241. package/src/executors/bounded-exec/cpu-tokens.ts +177 -0
  242. package/src/executors/bounded-exec/disk-lease.test.ts +185 -0
  243. package/src/executors/bounded-exec/disk-lease.ts +139 -0
  244. package/src/executors/bounded-exec/executor-host.test.ts +778 -0
  245. package/src/executors/bounded-exec/executor.test.ts +1116 -63
  246. package/src/executors/bounded-exec/executor.ts +565 -67
  247. package/src/executors/bounded-exec/gateway-lease.ts +176 -0
  248. package/src/executors/bounded-exec/hang-diagnostics.test.ts +285 -0
  249. package/src/executors/bounded-exec/hang-diagnostics.ts +283 -0
  250. package/src/executors/bounded-exec/progress.test.ts +79 -0
  251. package/src/executors/bounded-exec/progress.ts +118 -0
  252. package/src/executors/bounded-exec/ram-temp-fixtures.ts +12 -0
  253. package/src/executors/bounded-exec/ram-temp-held.test.ts +264 -0
  254. package/src/executors/bounded-exec/ram-temp-held.ts +242 -0
  255. package/src/executors/bounded-exec/ram-temp-host.test.ts +605 -0
  256. package/src/executors/bounded-exec/ram-temp.test.ts +674 -0
  257. package/src/executors/bounded-exec/ram-temp.ts +1918 -0
  258. package/src/executors/bounded-exec/schema.json +11 -5
  259. package/src/executors/bounded-exec/schema.ts +27 -11
  260. package/src/executors/bounded-exec/verdict.test.ts +440 -0
  261. package/src/executors/bounded-exec/verdict.ts +433 -0
  262. package/src/executors/shard-timings/executor.ts +36 -0
  263. package/src/executors/shard-timings/schema.json +21 -0
  264. package/src/executors/shard-timings/schema.ts +4 -0
  265. package/src/failure-summary.ts +119 -0
  266. package/src/generators/bounded-test-targets/generator.test.ts +4 -4
  267. package/src/generators/bun-test-tracing/generator.test.ts +2 -2
  268. package/src/generators/create-package/generator.test.ts +6 -0
  269. package/src/generators/create-package/generator.ts +6 -2
  270. package/src/host-controller-wiring.test.ts +31 -0
  271. package/src/index.test.ts +909 -295
  272. package/src/index.ts +441 -143
  273. package/src/linked-snapshots.nx.test.ts +172 -0
  274. package/src/managed-files/ci-workflow.ts +54 -13
  275. package/src/managed-files/files.ts +65 -9
  276. package/src/managed-files/forgejo-artifact.test.ts +395 -0
  277. package/src/managed-files/generator.test.ts +60 -1
  278. package/src/managed-files/json-edit.test.ts +216 -0
  279. package/src/managed-files/json-edit.ts +290 -0
  280. package/src/managed-files/managed-format-json.test.ts +308 -0
  281. package/src/managed-files/managed-format.ts +90 -2
  282. package/src/managed-files/pr-preview-cleanup-workflow.ts +69 -3
  283. package/src/managed-files/publish-workflow.ts +285 -67
  284. package/src/managed-files/repo-path.test.ts +129 -0
  285. package/src/managed-files/trace-db-artifact.test.ts +7 -0
  286. package/src/managed-files/tree.ts +11 -3
  287. package/src/manifest-hash.ts +2 -6
  288. package/src/nextest-code-bound.test.ts +155 -0
  289. package/src/nextest-code-bound.ts +195 -0
  290. package/src/nextest-extraction.test.ts +37 -5
  291. package/src/nextest-extraction.ts +51 -9
  292. package/src/nextest-partitions.test.ts +427 -82
  293. package/src/nx-cache-bound.test.ts +5 -10
  294. package/src/nx-cache-restore-mtime.test.ts +170 -0
  295. package/src/nx-daemon-claim.test.ts +277 -0
  296. package/src/nx-daemon-idle-cpu.test.ts +81 -0
  297. package/src/nx-daemon-idle-policy.test.ts +51 -0
  298. package/src/nx-daemon-ignore-files.test.ts +210 -0
  299. package/src/nx-daemon-root-normalization.test.ts +105 -0
  300. package/src/nx-daemon-validity.test.ts +925 -0
  301. package/src/nx-dot-input-policy.test.ts +353 -0
  302. package/src/nx-failure-life-cycles.test.ts +207 -0
  303. package/src/nx-files-archive-racy.test.ts +97 -0
  304. package/src/nx-foreign-workspace-env.test.ts +329 -0
  305. package/src/nx-incomplete-run-summary.test.ts +70 -0
  306. package/src/nx-plugin-load-errors.test.ts +120 -0
  307. package/src/nx-project-resolution-cache.test.ts +176 -0
  308. package/src/nx-raw-inputs.test.ts +166 -0
  309. package/src/nx-resident-graph-workers.test.ts +7 -16
  310. package/src/nx-run-information.test.ts +118 -0
  311. package/src/nx-skipped-task-exit.test.ts +180 -0
  312. package/src/nx-state-location.test.ts +63 -0
  313. package/src/nx-store-resolution.test.ts +26 -25
  314. package/src/nx-task-graph-cycles.test.ts +148 -0
  315. package/src/nx-task-output-lease.test.ts +414 -0
  316. package/src/nx-use-local.test.ts +103 -0
  317. package/src/package-target-policy.ts +3 -6
  318. package/src/release-config-policy.ts +3 -6
  319. package/src/runtime-input.test.ts +215 -0
  320. package/src/runtime-input.ts +17 -0
  321. package/src/rust-tokens.ts +78 -0
  322. package/src/serial-group-wiring.test.ts +326 -0
  323. package/src/task-history-namespace.test.ts +87 -89
  324. package/src/task-results.test.ts +226 -0
  325. package/src/task-results.ts +75 -0
  326. package/src/test-program.test.ts +303 -0
  327. package/src/test-program.ts +341 -0
  328. package/src/test-timings.test.ts +240 -0
  329. package/src/test-timings.ts +311 -0
  330. package/src/test-walk-policy.test.ts +585 -0
  331. package/src/test-walk-policy.ts +731 -0
  332. package/src/testing.test.ts +509 -0
  333. package/src/testing.ts +922 -0
  334. package/src/type-guards.ts +4 -0
  335. package/src/typecheck-test-policy.test.ts +496 -11
  336. package/src/typecheck-test-policy.ts +137 -103
  337. package/src/workspace-config-policy.test.ts +212 -13
  338. package/src/workspace-config-policy.ts +101 -73
  339. package/src/workspace-index.ts +18 -0
  340. package/src/workspace-manifest.ts +41 -0
  341. package/test-timings.json +85 -30
  342. package/managed/raw/tooling/direnv/inherited-devenv.ts +0 -665
  343. package/managed/raw/tooling/direnv/shared-caches.sh +0 -53
@@ -1,5 +1,7 @@
1
1
  /* biome-ignore-all lint/suspicious/noTemplateCurlyInString: GitHub Actions expressions are emitted literally. */
2
2
 
3
+ import { isMap, isScalar, parseDocument } from 'yaml';
4
+
3
5
  import {
4
6
  LINUX_PLATFORM_TARGET_GLOBS,
5
7
  MACOS_PLATFORM_TARGET_GLOBS,
@@ -20,8 +22,10 @@ import {
20
22
  cargoCredentialStepLines,
21
23
  type DeployStepSecretConfig,
22
24
  deployStepSecretEnvLines,
25
+ githubActionPins,
23
26
  remoteCacheJobEnvLines,
24
27
  sourceCheckoutsStepLines,
28
+ TRACE_DB_ARTIFACT_GLOB,
25
29
  } from './ci-workflow.js';
26
30
  import { GITHUB_HOSTED_LINUX_RUNNER, renderRunsOnLine, type WorkflowRunsOn } from './github-runs-on.js';
27
31
 
@@ -424,7 +428,12 @@ function shouldRunStep(
424
428
  */
425
429
  export function renderPublishWorkflowYaml(options: PublishWorkflowDefinitionOptions = {}): string {
426
430
  if (options.release === false) {
427
- return `${renderPublishWorkflowHeader(options)}${renderPublishWorkflowSteps(definePublishWorkflow(options).steps, options)}`;
431
+ const steps = definePublishWorkflow(options).steps;
432
+ const rendered =
433
+ skipsPublishHandoff(options) && options.platformProducer !== undefined
434
+ ? renderSingleJobPublishWorkflowSteps(steps, options)
435
+ : renderPublishWorkflowSteps(steps, options);
436
+ return `${renderPublishWorkflowHeader(options)}${rendered}`;
428
437
  }
429
438
  if (hasMacosPlatformTargets(options) && !skipsPublishHandoff(options)) {
430
439
  return renderPlatformPublishWorkflowYaml(options);
@@ -433,7 +442,11 @@ export function renderPublishWorkflowYaml(options: PublishWorkflowDefinitionOpti
433
442
  // runner. Splitting jobs then buys nothing and costs a real transfer: the
434
443
  // outputs get tarred, uploaded, downloaded into a second checkout, and two
435
444
  // more devenv setups pay for themselves twice. One job, no artifacts.
436
- if (hasMacosPlatformTargets(options) || hasLinuxPlatformTargets(options)) {
445
+ if (
446
+ hasMacosPlatformTargets(options) ||
447
+ hasLinuxPlatformTargets(options) ||
448
+ (skipsPublishHandoff(options) && options.platformProducer !== undefined)
449
+ ) {
437
450
  return `${renderPublishWorkflowHeader(options)}${renderSingleJobPublishWorkflowSteps(
438
451
  definePublishWorkflow(options).steps,
439
452
  options,
@@ -498,8 +511,10 @@ defaults:
498
511
  jobs:
499
512
  publish:
500
513
  ${options.release === false ? renderRunsOnLine(options.runsOn) : publishJobRunsOnLine(options)}
514
+ timeout-minutes: ${options.platformTargetGlobs?.length ? 90 : 45}
501
515
  env:
502
- GH_TOKEN: ${githubExpression('github.token')}${remoteCacheJobEnv(options)}${cargoCredentialsJobEnv(options)}${privateNpmInstallJobEnv(options)}${platformProducerJobEnv(options)}
516
+ LMAO_GIT_REVISION: ${githubExpression('github.sha')}
517
+ GH_TOKEN: ${githubExpression('github.token')}${remoteCacheJobEnv(options)}${cargoCredentialsJobEnv(options)}${privateNpmInstallJobEnv(options)}
503
518
  steps:
504
519
  `;
505
520
  }
@@ -557,10 +572,15 @@ function yamlLinesForStep(step: PublishWorkflowStep, options: PublishWorkflowDef
557
572
  case PublishWorkflowStepKind.Checkout:
558
573
  return [
559
574
  ` - name: ${step.name}`,
560
- ' uses: actions/checkout@v6.0.2',
575
+ ` uses: ${githubActionPins.checkout.ref} # ${githubActionPins.checkout.version}`,
561
576
  ' with:',
562
- ' filter: blob:none',
563
577
  ' fetch-depth: 0',
578
+ ...(options.release === false
579
+ ? [' persist-credentials: false']
580
+ : [
581
+ ' # smoo publish and pending-release repair push release refs.',
582
+ ' persist-credentials: true',
583
+ ]),
564
584
  ];
565
585
  case PublishWorkflowStepKind.SourceCheckouts:
566
586
  return siblingSourceCheckoutStepLines(options);
@@ -602,16 +622,20 @@ function yamlLinesForStep(step: PublishWorkflowStep, options: PublishWorkflowDef
602
622
  return [
603
623
  ` - name: ${step.name}`,
604
624
  ' id: plan',
625
+ ' env:',
626
+ ` SMOO_RELEASE_PROJECTS: ${githubExpression('inputs.projects')}`,
605
627
  ' run:',
606
- ` smoo release version --bump "${githubExpression('inputs.bump')}" --projects "${githubExpression('inputs.projects')}" --dry-run "true" --github-output`,
628
+ ` smoo release version --bump "${githubExpression('inputs.bump')}" --projects "$SMOO_RELEASE_PROJECTS" --dry-run "true" --github-output`,
607
629
  ' "$GITHUB_OUTPUT"',
608
630
  ];
609
631
  case PublishWorkflowStepKind.VersionRelease:
610
632
  return [
611
633
  ` - name: ${step.name}`,
612
634
  ' id: version',
635
+ ' env:',
636
+ ` SMOO_RELEASE_PROJECTS: ${githubExpression('inputs.projects')}`,
613
637
  ' run:',
614
- ` smoo release version --bump "${githubExpression('inputs.bump')}" --projects "${githubExpression('inputs.projects')}" --dry-run "${githubExpression('inputs.dry_run')}" --github-output`,
638
+ ` smoo release version --bump "${githubExpression('inputs.bump')}" --projects "$SMOO_RELEASE_PROJECTS" --dry-run "${githubExpression('inputs.dry_run')}" --github-output`,
615
639
  ' "$GITHUB_OUTPUT"',
616
640
  ];
617
641
  case PublishWorkflowStepKind.CheckManagedMonorepoFiles:
@@ -640,7 +664,7 @@ function yamlLinesForStep(step: PublishWorkflowStep, options: PublishWorkflowDef
640
664
  'upload',
641
665
  [
642
666
  `name: trace-results-${githubExpression('github.run_id')}`,
643
- 'path: packages/*/.cache/trace-results.db*',
667
+ `path: ${TRACE_DB_ARTIFACT_GLOB}`,
644
668
  'if-no-files-found: ignore',
645
669
  'retention-days: 14',
646
670
  'include-hidden-files: true',
@@ -786,47 +810,57 @@ function renderSingleJobPublishWorkflowSteps(
786
810
  options: PublishWorkflowDefinitionOptions,
787
811
  ): string {
788
812
  const lines: string[] = [];
789
- const producer = options.platformProducer;
790
- const crossOnThisRunner = skipsPublishHandoff(options) && hasMacosPlatformTargets(options);
813
+ const handoffSkipped = skipsPublishHandoff(options);
814
+ // The declared producer runs only in a job that skips the publish handoff; any other
815
+ // single job renders without it, and so without its environment.
816
+ const producer = handoffSkipped ? options.platformProducer : undefined;
817
+ const crossOnThisRunner = handoffSkipped && hasMacosPlatformTargets(options);
818
+ let stepNumber = 2;
791
819
  for (const step of steps) {
792
- lines.push(...sectionLinesBefore(step));
793
- lines.push(...commentLinesForStep(step));
794
- lines.push(...yamlLinesForStep(step, options));
820
+ const numberedStep = { ...step, number: stepNumber++ };
821
+ lines.push(...sectionLinesBefore(numberedStep));
822
+ lines.push(...commentLinesForStep(numberedStep));
823
+ lines.push(...yamlLinesForStep(numberedStep, options));
795
824
  lines.push('');
796
- if (crossOnThisRunner && producer && step.kind === PublishWorkflowStepKind.Checkout) {
797
- // Before any toolchain setup or build, exactly as the dedicated producer
798
- // job ordered it: the SDK has to be on disk before devenv resolves it.
799
- lines.push(
800
- ' - name: Check cross-platform toolchain prerequisites',
801
- ' working-directory: .',
802
- ' run: |',
803
- ' set -euo pipefail',
804
- ...producer.preflight.split('\n').map((line) => ` ${line}`),
805
- '',
806
- );
825
+ if (producer && step.kind === PublishWorkflowStepKind.Checkout) {
826
+ // A declared producer always runs, even when the graph selects no platform family.
827
+ lines.push(' # Step ' + stepNumber++, ...platformProducerPreflightStepLines(producer), '');
807
828
  }
808
- if (step.kind === PublishWorkflowStepKind.Build) {
829
+ if (
830
+ step.kind === PublishWorkflowStepKind.Build &&
831
+ (hasMacosPlatformTargets(options) || hasLinuxPlatformTargets(options))
832
+ ) {
809
833
  lines.push(
834
+ ' # Step ' + stepNumber++,
810
835
  ' - name: 🐧 Build supplemental Linux targets',
811
836
  " if: steps.version.outputs.mode != 'none'",
812
- ` run: smoo github-ci nx-run-many --targets "${LINUX_PLATFORM_TARGET_GLOBS.join(',')}" --projects "${githubExpression(
813
- 'steps.version.outputs.projects',
814
- )}" ${RELEASE_BUILD_ARGUMENT}`,
837
+ ' run:',
838
+ ' smoo github-ci nx-run-many --targets "' +
839
+ LINUX_PLATFORM_TARGET_GLOBS.join(',') +
840
+ '" --projects "' +
841
+ githubExpression('steps.version.outputs.projects') +
842
+ '" ' +
843
+ RELEASE_BUILD_ARGUMENT,
815
844
  '',
816
845
  );
817
846
  if (crossOnThisRunner) {
818
847
  lines.push(
848
+ ' # Step ' + stepNumber++,
819
849
  ' - name: 🍎 Build selected macOS and iOS release outputs',
820
850
  " if: steps.version.outputs.mode != 'none'",
821
- ` run: smoo github-ci nx-run-many --targets "${macosPlatformFamilies(options).join(',')}" --projects "${githubExpression(
822
- 'steps.version.outputs.projects',
823
- )}" ${RELEASE_BUILD_ARGUMENT}`,
851
+ ' run:',
852
+ ' smoo github-ci nx-run-many --targets "' +
853
+ macosPlatformFamilies(options).join(',') +
854
+ '" --projects "' +
855
+ githubExpression('steps.version.outputs.projects') +
856
+ '" ' +
857
+ RELEASE_BUILD_ARGUMENT,
824
858
  '',
825
859
  );
826
860
  }
827
861
  }
828
862
  }
829
- return `${lines.join('\n').trimEnd()}\n`;
863
+ return mergeProducerStepEnvironment(lines, producer).join('\n').trimEnd() + '\n';
830
864
  }
831
865
 
832
866
  function renderPlatformPublishWorkflowYaml(options: PublishWorkflowDefinitionOptions): string {
@@ -877,6 +911,7 @@ defaults:
877
911
  jobs:
878
912
  linux-release-candidate:
879
913
  ${renderRunsOnLine(options.runsOn)}
914
+ timeout-minutes: 45
880
915
  permissions:
881
916
  contents: write
882
917
  id-token: none
@@ -884,30 +919,32 @@ ${renderRunsOnLine(options.runsOn)}
884
919
  mode: ${githubExpression('steps.version.outputs.mode')}
885
920
  release-sha: ${githubExpression('steps.release-state.outputs.sha')}
886
921
  env:
922
+ LMAO_GIT_REVISION: ${githubExpression('github.sha')}
887
923
  GH_TOKEN: ${githubExpression('github.token')}${remoteCacheJobEnv(options)}${cargoCredentialsJobEnv(options)}${privateNpmInstallJobEnv(options)}
888
924
  steps:
889
925
  ${renderLinuxReleaseCandidateSteps(steps, options)}
890
926
 
891
927
  ${options.platformProducer?.kind === 'linux-cross' ? 'cross-platform' : 'macos-platform'}:
892
928
  ${renderMacosJobHeaderLines(options)}
929
+ timeout-minutes: 90
893
930
  permissions:
894
931
  contents: read
895
932
  id-token: none
896
933
  env:
934
+ LMAO_GIT_REVISION: ${githubExpression('github.sha')}
897
935
  GH_TOKEN: ${githubExpression('github.token')}${remoteCacheJobEnv(options)}${cargoCredentialsJobEnv(options)}${privateNpmInstallJobEnv(options)}
898
- ${Object.entries(options.platformProducer?.env ?? {})
899
- .map(([name, value]) => ` ${name}: ${JSON.stringify(value)}`)
900
- .join('\n')}
901
936
  steps:
902
937
  ${renderMacosPlatformSteps(options)}
903
938
 
904
939
  publish-on-linux:
905
940
  needs: [linux-release-candidate, ${options.platformProducer?.kind === 'linux-cross' ? 'cross-platform' : 'macos-platform'}]
906
941
  ${publishJobRunsOnLine(options)}
942
+ timeout-minutes: 45
907
943
  permissions:
908
944
  contents: write
909
945
  id-token: write
910
946
  env:
947
+ LMAO_GIT_REVISION: ${githubExpression('github.sha')}
911
948
  TTSC_TSGO_BINARY: ${githubExpression('github.workspace')}/node_modules/@typescript/native/bin/tsc
912
949
  GH_TOKEN: ${githubExpression('github.token')}${remoteCacheJobEnv(options)}${cargoCredentialsJobEnv(options)}${privateNpmInstallJobEnv(options)}
913
950
  steps:
@@ -945,11 +982,13 @@ function renderLinuxReleaseCandidateSteps(
945
982
  if (step.kind === PublishWorkflowStepKind.Checkout) {
946
983
  lines.push(
947
984
  ` - name: ${step.name}`,
948
- ' uses: actions/checkout@v6.0.2',
985
+ ` uses: ${githubActionPins.checkout.ref} # ${githubActionPins.checkout.version}`,
949
986
  ' with:',
950
987
  ` ref: ${githubExpression('github.sha')}`,
951
- ' filter: blob:none',
952
988
  ' fetch-depth: 0',
989
+ ' # No remote is read or written from this job: the clone is complete and the',
990
+ ' # candidate commit leaves only as the transferred bundle.',
991
+ ' persist-credentials: false',
953
992
  );
954
993
  } else if (step.kind === PublishWorkflowStepKind.Build) {
955
994
  lines.push(
@@ -1066,25 +1105,17 @@ function renderMacosPlatformSteps(options: PublishWorkflowDefinitionOptions): st
1066
1105
  ' # Step 1: GitHub adds "Set up job" automatically',
1067
1106
  ' # Step 2',
1068
1107
  ' - name: 📥 Checkout dispatch commit',
1069
- ' uses: actions/checkout@v6.0.2',
1108
+ ` uses: ${githubActionPins.checkout.ref} # ${githubActionPins.checkout.version}`,
1070
1109
  ' with:',
1071
1110
  ` ref: ${githubExpression('github.sha')}`,
1072
- ' filter: blob:none',
1073
1111
  ' fetch-depth: 0',
1112
+ ' # build-platform-outputs fetches the release branch and tags from origin',
1113
+ ' # (packages/cli/src/release/index.ts:335). This job pushes nothing, but a private origin refuses',
1114
+ ' # that fetch without the checkout credential, so it stays persisted.',
1115
+ ' persist-credentials: true',
1074
1116
  ];
1075
1117
  if (options.platformProducer) {
1076
- if (!options.platformProducer.preflight.trim()) {
1077
- throw new Error('Linux cross-platform production requires a nonempty toolchain preflight command.');
1078
- }
1079
- lines.push(
1080
- '',
1081
- ` # Step ${stepNumber++}`,
1082
- ' - name: Check cross-platform toolchain prerequisites',
1083
- ' working-directory: .',
1084
- ' run: |',
1085
- ' set -euo pipefail',
1086
- ...options.platformProducer.preflight.split('\n').map((line) => ` ${line}`),
1087
- );
1118
+ lines.push('', ` # Step ${stepNumber++}`, ...platformProducerPreflightStepLines(options.platformProducer));
1088
1119
  }
1089
1120
  const macosCargoCredentials = cargoCredentialsStepLines(options);
1090
1121
  if (macosCargoCredentials.length > 0) {
@@ -1131,8 +1162,10 @@ function renderMacosPlatformSteps(options: PublishWorkflowDefinitionOptions): st
1131
1162
  ` # Step ${stepNumber++}`,
1132
1163
  ' - name: 🔢 Version release',
1133
1164
  ' id: version',
1165
+ ' env:',
1166
+ ` SMOO_RELEASE_PROJECTS: ${githubExpression('inputs.projects')}`,
1134
1167
  ' run:',
1135
- ` smoo release version --bump "${githubExpression('inputs.bump')}" --projects "${githubExpression('inputs.projects')}" --dry-run "${githubExpression('inputs.dry_run')}" --github-output`,
1168
+ ` smoo release version --bump "${githubExpression('inputs.bump')}" --projects "$SMOO_RELEASE_PROJECTS" --dry-run "${githubExpression('inputs.dry_run')}" --github-output`,
1136
1169
  ' "$GITHUB_OUTPUT"',
1137
1170
  );
1138
1171
  const architectures = macosPlatformArchitectures(options);
@@ -1148,10 +1181,12 @@ function renderMacosPlatformSteps(options: PublishWorkflowDefinitionOptions): st
1148
1181
  ` # Step ${stepNumber++}`,
1149
1182
  ` - name: 🍎 Build selected macOS and iOS release outputs${legLabel}`,
1150
1183
  ' id: platform-outputs',
1184
+ ' env:',
1185
+ ` SMOO_RELEASE_PROJECTS: ${githubExpression('inputs.projects')}`,
1151
1186
  ' run:',
1152
1187
  ` smoo release build-platform-outputs --bump "${githubExpression(
1153
1188
  'inputs.bump',
1154
- )}" --projects "${githubExpression('inputs.projects')}" --ref "${githubExpression('github.sha')}" --targets "${macosPlatformTargetSelector(options)}" --output`,
1189
+ )}" --projects "$SMOO_RELEASE_PROJECTS" --ref "${githubExpression('github.sha')}" --targets "${macosPlatformTargetSelector(options)}" --output`,
1155
1190
  ` "${githubExpression('runner.temp')}/macos-platform-outputs" --github-output "$GITHUB_OUTPUT"`,
1156
1191
  );
1157
1192
  if (options.platformProducer?.kind !== 'linux-cross') {
@@ -1194,7 +1229,7 @@ function renderMacosPlatformSteps(options: PublishWorkflowDefinitionOptions): st
1194
1229
  ' with:',
1195
1230
  ` devenv-cache-hit: ${githubExpression('steps.setup.outputs.devenv-cache-hit')}`,
1196
1231
  );
1197
- return lines.join('\n').trimEnd();
1232
+ return mergeProducerStepEnvironment(lines, options.platformProducer).join('\n').trimEnd();
1198
1233
  }
1199
1234
 
1200
1235
  function renderFinalLinuxPublishSteps(options: PublishWorkflowDefinitionOptions): string {
@@ -1206,11 +1241,12 @@ function renderFinalLinuxPublishSteps(options: PublishWorkflowDefinitionOptions)
1206
1241
  ' # Step 1: GitHub adds "Set up job" automatically',
1207
1242
  ` # Step ${stepNumber++}`,
1208
1243
  ' - name: 📥 Checkout dispatch commit',
1209
- ' uses: actions/checkout@v6.0.2',
1244
+ ` uses: ${githubActionPins.checkout.ref} # ${githubActionPins.checkout.version}`,
1210
1245
  ' with:',
1211
1246
  ` ref: ${githubExpression('github.sha')}`,
1212
- ' filter: blob:none',
1213
1247
  ' fetch-depth: 0',
1248
+ ' # smoo publish and pending-release repair push release refs.',
1249
+ ' persist-credentials: true',
1214
1250
  ];
1215
1251
  const publishCargoCredentials = cargoCredentialsStepLines(options);
1216
1252
  if (publishCargoCredentials.length > 0) {
@@ -1503,20 +1539,202 @@ function skipsPublishHandoff(options: PublishWorkflowDefinitionOptions): boolean
1503
1539
  return !hasMacosPlatformTargets(options) || options.platformProducer?.kind === 'linux-cross';
1504
1540
  }
1505
1541
 
1542
+ type PlatformProducer = NonNullable<PublishWorkflowDefinitionOptions['platformProducer']>;
1543
+
1544
+ /** Names become YAML keys of every step's `env:`, so only portable identifiers are admissible. */
1545
+ const PLATFORM_PRODUCER_ENV_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
1546
+
1506
1547
  /**
1507
- * Toolchain environment for a foreign-platform producer, rendered onto whichever
1508
- * job runs its builds. In the flattened single-job shape that is the publish job
1509
- * itself, so the SDK path and cross flags have to reach it the same way the
1510
- * dedicated producer job received them.
1548
+ * The producer's toolchain preflight, shared by the dedicated producer job and
1549
+ * the flattened single job. It is an ordinary step of that job: the declared
1550
+ * environment reaches it through `mergeProducerStepEnvironment` exactly as it
1551
+ * reaches every other step, so the preflight checks the toolchain the build sees.
1511
1552
  */
1512
- function platformProducerJobEnv(options: PublishWorkflowDefinitionOptions): string {
1513
- const producer = options.platformProducer;
1514
- if (!producer || !skipsPublishHandoff(options)) {
1515
- return '';
1553
+ function platformProducerPreflightStepLines(producer: PlatformProducer): string[] {
1554
+ if (!producer.preflight.trim()) {
1555
+ throw new Error('Linux cross-platform production requires a nonempty toolchain preflight command.');
1516
1556
  }
1517
- return Object.entries(producer.env ?? {})
1518
- .map(([name, value]) => `\n ${name}: ${JSON.stringify(value)}`)
1519
- .join('');
1557
+ return [
1558
+ ' - name: Check cross-platform toolchain prerequisites',
1559
+ ' working-directory: .',
1560
+ ' run: |',
1561
+ ' set -euo pipefail',
1562
+ ...producer.preflight.split('\n').map((line) => ` ${line}`),
1563
+ ];
1564
+ }
1565
+
1566
+ /** One declared producer variable. */
1567
+ type ProducerEnvEntry = readonly [name: string, value: string];
1568
+
1569
+ /**
1570
+ * The declared variables, each proved a valid key of a step `env:`. GitHub
1571
+ * rejects mapping keys that differ only by case as duplicates, so such a pair
1572
+ * cannot share one env mapping: it fails here, naming both, not in CI.
1573
+ */
1574
+ function platformProducerEnvEntries(producer: PlatformProducer | undefined): ProducerEnvEntry[] {
1575
+ const entries = Object.entries(producer?.env ?? {});
1576
+ const byUpperCase = new Map<string, string>();
1577
+ for (const [name] of entries) {
1578
+ if (!PLATFORM_PRODUCER_ENV_NAME.test(name)) {
1579
+ throw new Error(
1580
+ `smoo.github.platformProducer.env name ${JSON.stringify(name)} is not a valid environment variable name.`,
1581
+ );
1582
+ }
1583
+ const upper = name.toUpperCase();
1584
+ const twin = byUpperCase.get(upper);
1585
+ if (twin !== undefined) {
1586
+ throw new Error(
1587
+ `smoo.github.platformProducer.env names ${JSON.stringify(twin)} and ${JSON.stringify(name)} differ only by case, which GitHub Actions rejects as a duplicate env key.`,
1588
+ );
1589
+ }
1590
+ byUpperCase.set(upper, name);
1591
+ }
1592
+ return entries;
1593
+ }
1594
+
1595
+ /** A top-level step opens with exactly this prefix, and its own env mapping with exactly this header. */
1596
+ const RENDERED_STEP_OPENER = ' - name:';
1597
+ const RENDERED_STEP_ENV_HEADER = ' env:';
1598
+
1599
+ /**
1600
+ * The producer's declared environment, carried by every step of its job as that
1601
+ * step's own `env:`.
1602
+ *
1603
+ * Step env is the one transport that carries every declarable name: GitHub
1604
+ * forbids `NODE_OPTIONS` in `GITHUB_ENV`, and a job-level `env` cannot evaluate
1605
+ * the `runner` context an SDK path under `runner.temp` needs. A step's own fields
1606
+ * win: a variable the step already scopes (release inputs, the publisher
1607
+ * credential, Cargo and source-checkout secrets) keeps its value and only the
1608
+ * producer's copy is omitted from that step, so no step carries a key twice.
1609
+ * What cannot be carried fails generation naming the declared variables and the
1610
+ * step: a step-local key equal to a declared name ignoring case (GitHub rejects
1611
+ * such duplicates), or an `env:` this function cannot read.
1612
+ *
1613
+ * `lines` are the renderer's own fragments, not arbitrary YAML: every top-level
1614
+ * step opens with exactly ` - name:` and its own env is exactly
1615
+ * ` env:` with entries nested deeper. Only that block is parsed, and only
1616
+ * for its keys; every existing line and comment is kept as written.
1617
+ */
1618
+ function mergeProducerStepEnvironment(lines: string[], producer: PlatformProducer | undefined): string[] {
1619
+ const entries = platformProducerEnvEntries(producer);
1620
+ if (entries.length === 0) {
1621
+ return lines;
1622
+ }
1623
+ const merged: string[] = [];
1624
+ let steps = 0;
1625
+ let index = 0;
1626
+ while (index < lines.length) {
1627
+ const line = lines[index];
1628
+ if (!line.startsWith(RENDERED_STEP_OPENER)) {
1629
+ if (/^ {6}- /.test(line)) {
1630
+ throw producerEnvMergeError(
1631
+ entries,
1632
+ `generated step ${JSON.stringify(line.trim())}`,
1633
+ 'a top-level step must open with "- name:"',
1634
+ );
1635
+ }
1636
+ merged.push(line);
1637
+ index += 1;
1638
+ continue;
1639
+ }
1640
+ // A step runs until the next non-blank line indented no deeper than its opener:
1641
+ // the next step, or the anchor comment above it.
1642
+ let end = index + 1;
1643
+ while (end < lines.length && (lines[end].trim() === '' || /^ {7}/.test(lines[end]))) {
1644
+ end += 1;
1645
+ }
1646
+ merged.push(...mergeStepEnvironment(lines.slice(index, end), entries));
1647
+ steps += 1;
1648
+ index = end;
1649
+ }
1650
+ if (steps === 0) {
1651
+ throw producerEnvMergeError(entries, 'the rendered job', 'it has no step to carry the environment');
1652
+ }
1653
+ return merged;
1654
+ }
1655
+
1656
+ /**
1657
+ * One step's lines with the producer's variables added to its own `env:`. A step
1658
+ * without one gets an empty header under its opener, so both shapes merge the
1659
+ * same way; the step's own keys win.
1660
+ */
1661
+ function mergeStepEnvironment(step: readonly string[], entries: readonly ProducerEnvEntry[]): string[] {
1662
+ const where = `generated step ${JSON.stringify(step[0].slice(RENDERED_STEP_OPENER.length).trim())}`;
1663
+ const envFields = step.flatMap((line, index) => (/^ {8}env:/.test(line) ? [index] : []));
1664
+ if (envFields.length > 1) {
1665
+ throw producerEnvMergeError(entries, where, 'it declares env more than once');
1666
+ }
1667
+ const lines = envFields.length === 0 ? [step[0], RENDERED_STEP_ENV_HEADER, ...step.slice(1)] : step;
1668
+ const header = envFields.length === 0 ? 1 : envFields[0];
1669
+ if (lines[header] !== RENDERED_STEP_ENV_HEADER) {
1670
+ throw producerEnvMergeError(
1671
+ entries,
1672
+ where,
1673
+ `its env field ${JSON.stringify(lines[header])} is not a block mapping header`,
1674
+ );
1675
+ }
1676
+ // Entries are indented deeper than the header; the block ends at the next field or step comment.
1677
+ let end = header + 1;
1678
+ while (end < lines.length && /^ {9}/.test(lines[end])) {
1679
+ end += 1;
1680
+ }
1681
+ const ownKeys =
1682
+ envFields.length === 0
1683
+ ? []
1684
+ : stepEnvKeys(lines.slice(header, end), (reason, cause) => producerEnvMergeError(entries, where, reason, cause));
1685
+ const stamped: string[] = [];
1686
+ for (const entry of entries) {
1687
+ const [name, value] = entry;
1688
+ const ownKey = ownKeys.find((key) => key.toUpperCase() === name.toUpperCase());
1689
+ if (ownKey === undefined) {
1690
+ stamped.push(` ${JSON.stringify(name)}: ${JSON.stringify(value)}`);
1691
+ } else if (ownKey !== name) {
1692
+ throw producerEnvMergeError(
1693
+ [entry],
1694
+ where,
1695
+ `its own env key ${JSON.stringify(ownKey)} differs from the declared name only by case, which GitHub Actions rejects as a duplicate key`,
1696
+ );
1697
+ }
1698
+ }
1699
+ return [...lines.slice(0, header + 1), ...stamped, ...lines.slice(header + 1)];
1700
+ }
1701
+
1702
+ /** The keys of one step's own `env:` block, read by the YAML parser; the block's lines stay as written. */
1703
+ function stepEnvKeys(block: readonly string[], fail: (reason: string, cause?: unknown) => Error): string[] {
1704
+ const document = parseDocument(block.join('\n'), { prettyErrors: false });
1705
+ if (document.errors.length > 0) {
1706
+ const reasons = document.errors.map((error) => `${error.message} (${error.code})`).join('; ');
1707
+ throw fail(`its env block is not valid YAML: ${reasons}`, document.errors[0]);
1708
+ }
1709
+ const root = document.contents;
1710
+ const field = isMap(root) ? root.items.find((item) => isScalar(item.key) && item.key.value === 'env') : undefined;
1711
+ const env = field?.value;
1712
+ if (env === null || (isScalar(env) && env.value === null)) {
1713
+ return [];
1714
+ }
1715
+ if (!isMap(env)) {
1716
+ throw fail('its env block is not a mapping');
1717
+ }
1718
+ return env.items.map((pair) => {
1719
+ const key = pair.key;
1720
+ if (!isScalar(key) || typeof key.value !== 'string') {
1721
+ throw fail('its env block has a key that is not a string', pair);
1722
+ }
1723
+ return key.value;
1724
+ });
1725
+ }
1726
+
1727
+ function producerEnvMergeError(
1728
+ entries: readonly ProducerEnvEntry[],
1729
+ where: string,
1730
+ reason: string,
1731
+ cause?: unknown,
1732
+ ): Error {
1733
+ const names = entries.map(([name]) => JSON.stringify(name)).join(', ');
1734
+ return new Error(
1735
+ `smoo.github.platformProducer.env ${names} cannot be merged into ${where}: ${reason}.`,
1736
+ cause === undefined ? undefined : { cause },
1737
+ );
1520
1738
  }
1521
1739
 
1522
1740
  function privateNpmInstallJobEnv(options: PublishWorkflowDefinitionOptions): string {
@@ -0,0 +1,129 @@
1
+ import { describe, expect, it } from 'bun:test';
2
+ import { spawnSync } from 'node:child_process';
3
+ import { mkdir, mkdtemp, readFile, rm, symlink, writeFile } from 'node:fs/promises';
4
+ import { tmpdir } from 'node:os';
5
+ import { dirname, join } from 'node:path';
6
+ import { managedAssetsRoot } from '../managed-assets.js';
7
+
8
+ interface RepoPathFixture {
9
+ readonly root: string;
10
+ readonly helper: string;
11
+ readonly home: string;
12
+ readonly venv: string;
13
+ readonly installed: string;
14
+ readonly tools: string;
15
+ readonly entries: string[];
16
+ }
17
+
18
+ async function executable(path: string, marker: string): Promise<void> {
19
+ await mkdir(dirname(path), { recursive: true });
20
+ await writeFile(path, `#!/bin/sh\nprintf '%s\\n' '${marker}'\n`, { mode: 0o755 });
21
+ }
22
+
23
+ async function withRepoPath(run: (fixture: RepoPathFixture) => Promise<void>): Promise<void> {
24
+ const root = await mkdtemp(join(tmpdir(), 'smoo-repo-path-'));
25
+ try {
26
+ const helper = join(root, 'tooling/direnv/repo-path');
27
+ await mkdir(dirname(helper), { recursive: true });
28
+ await writeFile(helper, await readFile(join(managedAssetsRoot, 'raw/tooling/direnv/repo-path')), { mode: 0o755 });
29
+ const tools = join(root, 'system-bin');
30
+ await mkdir(tools);
31
+ // Resolve the script's tools before scrubbing PATH; /usr/bin:/bin is not
32
+ // a coreutils installation on NixOS.
33
+ for (const tool of ['bash', 'dirname']) {
34
+ const resolved = Bun.which(tool);
35
+ if (resolved === null) throw new Error(`${tool} must be on PATH`);
36
+ await symlink(resolved, join(tools, tool));
37
+ }
38
+ const home = join(root, 'private home');
39
+ const venv = join(root, 'active venv');
40
+ const installed = join(home, 'Library/Application Support/dev.cowshed/bin');
41
+ const entries = [
42
+ join(root, 'tooling/direnv/.devenv/profile/bin'),
43
+ join(root, 'tooling/git-hooks'),
44
+ join(root, 'tooling'),
45
+ join(root, 'tooling/node_modules/.bin'),
46
+ join(root, 'node_modules/.bin'),
47
+ ];
48
+ await executable(join(entries[0], 'python3'), 'profile-python');
49
+ await executable(join(entries[0], 'cargo'), 'profile-cargo');
50
+ await executable(join(venv, 'bin/python3'), 'venv-python');
51
+ await executable(join(venv, 'bin/cargo'), 'venv-cargo');
52
+ await executable(join(installed, 'cargo'), 'installed-cargo');
53
+ await run({ root, helper, home, venv, installed, tools, entries });
54
+ } finally {
55
+ await rm(root, { recursive: true, force: true });
56
+ }
57
+ }
58
+
59
+ function helper(fixture: RepoPathFixture, args: readonly string[], virtualEnv?: string, path = fixture.tools) {
60
+ const result = spawnSync(join(fixture.tools, 'bash'), [fixture.helper, ...args], {
61
+ encoding: 'utf8',
62
+ env: { HOME: fixture.home, PATH: path, ...(virtualEnv === undefined ? {} : { VIRTUAL_ENV: virtualEnv }) },
63
+ });
64
+ expect(result.status).toBe(0);
65
+ expect(result.stderr).toBe('');
66
+ return result.stdout;
67
+ }
68
+
69
+ async function expectModes(fixture: RepoPathFixture, entries: string[], virtualEnv?: string): Promise<void> {
70
+ expect(helper(fixture, ['--print'], virtualEnv)).toBe(`${entries.join('\n')}\n`);
71
+ const githubPath = join(fixture.root, 'github-path');
72
+ await writeFile(githubPath, 'existing-entry\n');
73
+ const result = spawnSync(join(fixture.tools, 'bash'), [fixture.helper, '--github-path'], {
74
+ encoding: 'utf8',
75
+ env: {
76
+ HOME: fixture.home,
77
+ PATH: fixture.tools,
78
+ GITHUB_PATH: githubPath,
79
+ ...(virtualEnv === undefined ? {} : { VIRTUAL_ENV: virtualEnv }),
80
+ },
81
+ });
82
+ expect(result.status).toBe(0);
83
+ expect(result.stderr).toBe('');
84
+ expect(await readFile(githubPath, 'utf8')).toBe(`existing-entry\n${[...entries].reverse().join('\n')}\n`);
85
+ }
86
+
87
+ describe('managed repo-path', () => {
88
+ it.each([undefined, ''])('preserves the exact legacy ordering without an active venv (%p)', async (virtualEnv) => {
89
+ await withRepoPath(async (fixture) => {
90
+ await expectModes(fixture, fixture.entries, virtualEnv);
91
+ expect(helper(fixture, [], virtualEnv)).toBe(
92
+ `${[fixture.installed, ...fixture.entries].join(':')}:${fixture.tools}\n`,
93
+ );
94
+ });
95
+ });
96
+
97
+ it.each([false, true])(
98
+ 'keeps active Python ahead of the profile and installed Cargo first (served=%p)',
99
+ async (served) => {
100
+ await withRepoPath(async (fixture) => {
101
+ if (served) {
102
+ await mkdir(join(fixture.root, '.cowshed'), { recursive: true });
103
+ await writeFile(
104
+ join(fixture.root, '.cowshed/env'),
105
+ `export COWSHED_RUNTIME_LINK=fixture\nexport PATH=${JSON.stringify(fixture.installed)}:$PATH\n`,
106
+ );
107
+ }
108
+ const entries = [join(fixture.venv, 'bin'), ...fixture.entries];
109
+ await expectModes(fixture, entries, fixture.venv);
110
+ const incoming = `${join(fixture.venv, 'bin')}:${fixture.tools}`;
111
+ const path = helper(fixture, [], fixture.venv, incoming).trimEnd();
112
+ expect(path).toBe(`${[fixture.installed, ...entries].join(':')}:${incoming}`);
113
+ const selected = spawnSync(
114
+ join(fixture.tools, 'bash'),
115
+ ['-c', 'command -v python3; python3; command -v cargo; cargo'],
116
+ {
117
+ encoding: 'utf8',
118
+ env: { HOME: fixture.home, PATH: path },
119
+ },
120
+ );
121
+ expect(selected.status).toBe(0);
122
+ expect(selected.stderr).toBe('');
123
+ expect(selected.stdout).toBe(
124
+ `${join(fixture.venv, 'bin/python3')}\nvenv-python\n${join(fixture.installed, 'cargo')}\ninstalled-cargo\n`,
125
+ );
126
+ });
127
+ },
128
+ );
129
+ });