@intentius/chant 0.124.101 → 0.124.103

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 (109) hide show
  1. package/dist/ci-evidence-claims.d.ts +12 -0
  2. package/dist/ci-evidence-claims.js +12 -0
  3. package/dist/cli/commands/onboard.js +8 -8
  4. package/dist/cli/handlers/release-init.js +53 -19
  5. package/dist/cli/handlers/release.d.ts +1 -1
  6. package/dist/cli/handlers/release.js +12 -9
  7. package/dist/cli/main.js +13 -2
  8. package/dist/cli/parse-args.js +5 -0
  9. package/dist/cli/registry.d.ts +2 -0
  10. package/dist/cli/release-commands/cut.js +4 -3
  11. package/dist/cli/release-commands/init.js +4 -1
  12. package/dist/cli/release-commands/workflow.js +4 -2
  13. package/dist/cloud-lister/index.d.ts +4 -1
  14. package/dist/cloud-lister/index.js +2 -1
  15. package/dist/cloud-lister/kubernetes-components.d.ts +56 -0
  16. package/dist/cloud-lister/kubernetes-components.js +641 -0
  17. package/dist/cloud-lister/kubernetes.d.ts +18 -0
  18. package/dist/cloud-lister/kubernetes.js +26 -1
  19. package/dist/cloud-lister/mask.d.ts +5 -1
  20. package/dist/cloud-lister/mask.js +14 -5
  21. package/dist/config-import.d.ts +1 -1
  22. package/dist/config-import.js +6 -2
  23. package/dist/config-sandbox.d.ts +1 -1
  24. package/dist/config-sandbox.js +3 -3
  25. package/dist/config.d.ts +75 -1
  26. package/dist/config.js +27 -2
  27. package/dist/deep-observation.js +9 -3
  28. package/dist/floor-table.data.js +13 -6
  29. package/dist/lexicon.d.ts +4 -2
  30. package/dist/lifecycle/__fixtures__/package-files.d.ts +32 -0
  31. package/dist/lifecycle/__fixtures__/package-files.js +72 -0
  32. package/dist/lifecycle/__fixtures__/publish-fakes.js +5 -0
  33. package/dist/lifecycle/publish-credentials.d.ts +1 -1
  34. package/dist/lifecycle/publish-credentials.js +5 -0
  35. package/dist/lifecycle/publish-declaration.d.ts +123 -0
  36. package/dist/lifecycle/publish-declaration.js +141 -2
  37. package/dist/lifecycle/publish-helm.d.ts +83 -0
  38. package/dist/lifecycle/publish-helm.js +451 -0
  39. package/dist/lifecycle/publish-maven.d.ts +79 -0
  40. package/dist/lifecycle/publish-maven.js +363 -0
  41. package/dist/lifecycle/publish-mcp-registry.js +1 -2
  42. package/dist/lifecycle/publish-npm.d.ts +27 -1
  43. package/dist/lifecycle/publish-npm.js +52 -2
  44. package/dist/lifecycle/publish-nuget.d.ts +93 -0
  45. package/dist/lifecycle/publish-nuget.js +376 -0
  46. package/dist/lifecycle/publish-oci.d.ts +57 -1
  47. package/dist/lifecycle/publish-oci.js +1 -1
  48. package/dist/lifecycle/publish-package-files.d.ts +16 -0
  49. package/dist/lifecycle/publish-package-files.js +39 -0
  50. package/dist/lifecycle/publish-pypi.d.ts +2 -0
  51. package/dist/lifecycle/publish-pypi.js +1 -1
  52. package/dist/lifecycle/publish-rubygems.d.ts +84 -0
  53. package/dist/lifecycle/publish-rubygems.js +365 -0
  54. package/dist/lifecycle/publish-targets.d.ts +10 -0
  55. package/dist/lifecycle/publish-targets.js +22 -0
  56. package/dist/lifecycle/publish-train-names.d.ts +4 -1
  57. package/dist/lifecycle/publish-train-names.js +5 -0
  58. package/dist/lifecycle/release-artifacts.d.ts +80 -2
  59. package/dist/lifecycle/release-artifacts.js +241 -5
  60. package/dist/lifecycle/release-cut.d.ts +6 -1
  61. package/dist/lifecycle/release-cut.js +15 -0
  62. package/dist/lifecycle/release-doctor.js +208 -6
  63. package/dist/lifecycle/release-init-registries.d.ts +48 -0
  64. package/dist/lifecycle/release-init-registries.js +97 -0
  65. package/dist/lifecycle/release-init.d.ts +22 -2
  66. package/dist/lifecycle/release-init.js +139 -13
  67. package/dist/lifecycle/release-next.js +1 -2
  68. package/dist/lifecycle/release-publish.d.ts +1 -1
  69. package/dist/lifecycle/release-publish.js +1 -1
  70. package/dist/lifecycle/release-tag.js +1 -2
  71. package/dist/op/local-executor.d.ts +1 -1
  72. package/dist/op/local-executor.js +2 -2
  73. package/dist/op/op-waves-evidence.js +9 -2
  74. package/dist/release-floors.d.ts +1 -1
  75. package/dist/release-floors.js +1 -1
  76. package/dist/sensitive-key.d.ts +12 -0
  77. package/dist/sensitive-key.js +52 -0
  78. package/dist/tool-pins.d.ts +2 -0
  79. package/dist/tool-pins.js +12 -0
  80. package/dist/ts-loader.d.ts +8 -0
  81. package/dist/ts-loader.js +19 -0
  82. package/dist/wave-runtime.mjs +325 -325
  83. package/dist/workspace/lexicon-outputs.d.ts +1 -1
  84. package/dist/workspace/lexicon-outputs.js +1 -1
  85. package/dist/workspace/release-steps/index.js +4 -0
  86. package/dist/workspace/release-steps/nfpm.d.ts +13 -0
  87. package/dist/workspace/release-steps/nfpm.js +29 -0
  88. package/dist/workspace/release-steps/nuget.d.ts +14 -0
  89. package/dist/workspace/release-steps/nuget.js +16 -0
  90. package/dist/workspace/release-steps/targets.d.ts +2 -2
  91. package/dist/workspace/release-steps/targets.js +3 -3
  92. package/dist/workspace/release-train-workflow.d.ts +27 -2
  93. package/dist/workspace/release-train-workflow.js +171 -14
  94. package/dist/workspace/release-train.js +5 -1
  95. package/dist/workspace/release-workflow.d.ts +39 -3
  96. package/dist/workspace/release-workflow.js +80 -24
  97. package/dist/workspace/train-artifacts.d.ts +107 -0
  98. package/dist/workspace/train-artifacts.js +239 -0
  99. package/dist/workspace/train-cut.d.ts +14 -2
  100. package/dist/workspace/train-cut.js +49 -7
  101. package/dist/workspace/train-prepare.d.ts +6 -3
  102. package/dist/workspace/train-prepare.js +54 -8
  103. package/dist/workspace/train-publish.d.ts +9 -0
  104. package/dist/workspace/train-publish.js +29 -4
  105. package/dist/workspace/train-shell.d.ts +5 -0
  106. package/dist/workspace/train-shell.js +17 -0
  107. package/dist/workspace/trust/check-evidence-report.d.ts +3 -7
  108. package/dist/workspace/trust/check-evidence-report.js +3 -7
  109. package/package.json +1 -1
@@ -54,6 +54,7 @@ import { releaseJobSteps, releaseSetupSteps } from "./release-steps/index.js";
54
54
  import { packLine } from "./release-steps/builds.js";
55
55
  import { RELEASE_BINFMT_IMAGE, qemuArchitectures } from "./release-steps/qemu.js";
56
56
  import { targetExtras } from "./release-steps/targets.js";
57
+ import { goreleaserSetup } from "./release-steps/goreleaser.js";
57
58
  import { renderTrainWorkflow } from "./release-train-workflow.js";
58
59
  export const RELEASE_WORKFLOW_FORGES = ["github", "forgejo", "gitlab"];
59
60
  /** Where each forge's publish workflow is written, relative to the repository root. */
@@ -143,12 +144,12 @@ export function renderReleaseWorkflow(input) {
143
144
  : [];
144
145
  // #5154: the root's members released as a train.
145
146
  if (input.train) {
146
- if (input.forge === "gitlab")
147
- throw new Error("release.train: the train workflow renders for GitHub and Forgejo; on GitLab, run chant workspace train cut, prepare and publish from your own jobs");
148
147
  if (builds.length > 0)
149
148
  throw new Error("release.workflow.builds: a train cuts each member in one job, and per-platform builds are not handed to it; leave builds out of a train's workflow");
150
149
  if (images || input.artifacts)
151
- throw new Error("release.images and release.artifacts at the root: a train releases its members, and the workflow hands no image or file between its jobs; declare them in a member and release that member on its own");
150
+ throw new Error("release.images and release.artifacts at the root: a train releases its members, not the root; declare them in the member that publishes them");
151
+ const t = input.train;
152
+ const trainContext = { forge: input.forge, shape: "dispatch", input: { ...input, imagePlatforms: t.imagePlatforms ?? [] }, pipeline: p, chant, root, verify: false, images: t.images === true, archives: [], artifacts: false, version: false, doctor: false, signing: input.signing === true, green, builds: [] };
152
153
  return renderTrainWorkflow({
153
154
  forge: input.forge,
154
155
  env: input.train.env,
@@ -161,12 +162,19 @@ export function renderReleaseWorkflow(input) {
161
162
  after,
162
163
  chantSetup,
163
164
  fullSetup,
164
- extra: jobExtras({ ...p, ...(derived.permissions ? { permissions: { ...p.permissions, ...derived.permissions } } : {}), ...(derived.env ? { env: { ...p.env, ...derived.env } } : {}), setup: releaseSetupSteps({ forge: input.forge, shape: "dispatch", input, pipeline: p, chant, root, verify: false, images: false, archives: [], artifacts: false, version: false, doctor: false, signing: input.signing === true, green, builds: [] }) }, input.forge),
165
+ extra: jobExtras({ ...p, ...(derived.permissions ? { permissions: { ...p.permissions, ...derived.permissions } } : {}), ...(derived.env ? { env: { ...p.env, ...derived.env } } : {}), setup: releaseSetupSteps(trainContext) }, input.forge),
165
166
  forgeToken,
166
167
  cutToken: green === "forge-checks" && p.env?.GITHUB_TOKEN === undefined ? [" GITHUB_TOKEN: ${{ github.token }}"] : [],
167
168
  green,
168
169
  gate: p.gate ?? "last-green",
169
170
  ...(input.lane ? { lane: input.lane } : {}),
171
+ // #5216: the members' images and files, from the cut to the publish; the doctor before the cut; verify before the publish.
172
+ files: t.images === true || t.artifacts === true,
173
+ ...(t.artifacts && t.goreleaser ? { goreleaser: ((g) => (input.forge === "gitlab" ? g.gitlab : g.github))(goreleaserSetup(input.forge, [root, t.goreleaserDir].filter((d) => !!d && d !== ".").join("/") || null, p)) } : {}),
174
+ ...(input.signing ? { signing: true } : {}),
175
+ ...(input.forge === "gitlab" ? { idTokens: stepLines(releaseJobSteps({ ...trainContext, job: "publish", label: '"$CHANT_RELEASE_TRAIN"' })("idTokens"), (l) => l) } : {}),
176
+ doctor: p.trigger === "dispatch" && p.doctor !== false,
177
+ verify: input.groups.has("verified-releases"),
170
178
  });
171
179
  }
172
180
  if (shape === "dispatch") {
@@ -223,12 +231,11 @@ export function renderReleaseWorkflow(input) {
223
231
  " push:",
224
232
  ' tags: ["release/**"]',
225
233
  "permissions:",
226
- " contents: write",
227
- " id-token: write",
228
- ...extra.permissions,
234
+ " contents: read",
229
235
  "jobs:",
230
236
  " publish:",
231
237
  " runs-on: ubuntu-latest",
238
+ ...jobPermissions(extra, { contents: "write", "id-token": "write" }, "publish"),
232
239
  ...(root ? [" defaults:", " run:", ` working-directory: ${root}`] : []),
233
240
  ...extra.githubEnv(forgeToken),
234
241
  " steps:",
@@ -245,7 +252,7 @@ export function renderReleaseWorkflow(input) {
245
252
  ` - run: ${chant} release publish ${label} ${flags}`,
246
253
  ];
247
254
  if (after.length > 0) {
248
- lines.push(" after-release:", " needs: publish", " runs-on: ubuntu-latest", ...(root ? [" defaults:", " run:", ` working-directory: ${root}`] : []), " steps:", ...githubSetup(undefined, fullSetup), ' - run: echo "CHANT_RELEASE_LABEL=${GITHUB_REF_NAME#release/}" >> "$GITHUB_ENV"', ...(install ? [` - run: ${install}`] : []), ...after.map((l) => ` - run: ${l}`));
255
+ lines.push(" after-release:", " needs: publish", " runs-on: ubuntu-latest", ...jobPermissions(extra, { contents: "read" }, "after"), ...(root ? [" defaults:", " run:", ` working-directory: ${root}`] : []), " steps:", ...githubSetup(undefined, fullSetup), ' - run: echo "CHANT_RELEASE_LABEL=${GITHUB_REF_NAME#release/}" >> "$GITHUB_ENV"', ...(install ? [` - run: ${install}`] : []), ...after.map((l) => ` - run: ${l}`));
249
256
  }
250
257
  return tagComments(`${lines.join("\n")}\n`);
251
258
  }
@@ -337,12 +344,11 @@ function renderTemplatedTagWorkflow(input, o) {
337
344
  " push:",
338
345
  ` tags: [${filters.globs.map((g) => JSON.stringify(g)).join(", ")}]`,
339
346
  "permissions:",
340
- " contents: write",
341
- " id-token: write",
342
- ...extra.permissions,
347
+ " contents: read",
343
348
  "jobs:",
344
349
  " publish:",
345
350
  " runs-on: ubuntu-latest",
351
+ ...jobPermissions(extra, { contents: "write", "id-token": "write" }, "publish"),
346
352
  ...(root ? [" defaults:", " run:", ` working-directory: ${root}`] : []),
347
353
  ...(after.length > 0 ? [" outputs:", " label: ${{ steps.label.outputs.label }}"] : []),
348
354
  ...extra.githubEnv(forgeToken),
@@ -364,10 +370,28 @@ function renderTemplatedTagWorkflow(input, o) {
364
370
  run(`${chant} release publish ${label} ${flags}`),
365
371
  ];
366
372
  if (after.length > 0) {
367
- lines.push(" after-release:", " needs: publish", " runs-on: ubuntu-latest", ...(root ? [" defaults:", " run:", ` working-directory: ${root}`] : []), " env:", " CHANT_RELEASE_LABEL: ${{ needs.publish.outputs.label }}", " steps:", ...githubSetup(undefined, fullSetup), ...(install ? [run(install)] : []), ...after.map(run));
373
+ lines.push(" after-release:", " needs: publish", " runs-on: ubuntu-latest", ...jobPermissions(extra, { contents: "read" }, "after"), ...(root ? [" defaults:", " run:", ` working-directory: ${root}`] : []), " env:", " CHANT_RELEASE_LABEL: ${{ needs.publish.outputs.label }}", " steps:", ...githubSetup(undefined, fullSetup), ...(install ? [run(install)] : []), ...after.map(run));
368
374
  }
369
375
  return tagComments(`${lines.join("\n")}\n`);
370
376
  }
377
+ /**
378
+ * A job's `permissions:` block (#5234): the scopes it needs, then the config's
379
+ * and targets' extras it takes, one per line at the job's indent. The workflow
380
+ * itself grants `contents: read`, so no job holds a scope it does not name.
381
+ * The cut never takes `packages` (the publish pushes the images), and the
382
+ * extras the config set by hand go to both.
383
+ */
384
+ export function jobPermissions(extra, base, job, indent = " ") {
385
+ const scopes = { ...base };
386
+ if (job === "cut" || job === "publish") {
387
+ for (const [k, v] of extra.permissions) {
388
+ if (job === "cut" && k === "packages")
389
+ continue;
390
+ scopes[k] = v;
391
+ }
392
+ }
393
+ return [`${indent}permissions:`, ...Object.entries(scopes).map(([k, v]) => `${indent} ${k}: ${v}`)];
394
+ }
371
395
  /** `release.workflow`'s `permissions`, `env` and `setup` (#4751) as lines of the forge's file. Empty for a config without them, so its file is what it was. */
372
396
  export function jobExtras(p, forge) {
373
397
  const permissions = Object.entries(p.permissions ?? {});
@@ -408,7 +432,7 @@ export function jobExtras(p, forge) {
408
432
  ...(s.env && Object.keys(s.env).length > 0 ? [" env:", ...map(" ", Object.entries(s.env))] : []),
409
433
  ]);
410
434
  return {
411
- permissions: permissions.map(([k, v]) => ` ${k}: ${v}`),
435
+ permissions,
412
436
  githubEnv: (base) => (base.length + env.length > 0 ? [" env:", ...base, ...map(" ", env)] : []),
413
437
  githubSteps,
414
438
  gitlabVariables: map(" ", env),
@@ -556,9 +580,7 @@ function renderGithubDispatch(o) {
556
580
  " required: true",
557
581
  " type: string",
558
582
  "permissions:",
559
- " contents: write",
560
- " id-token: write",
561
- ...o.extra.permissions,
583
+ " contents: read",
562
584
  "concurrency:",
563
585
  " group: chant-release",
564
586
  " cancel-in-progress: false",
@@ -567,6 +589,7 @@ function renderGithubDispatch(o) {
567
589
  "jobs:",
568
590
  " gate:",
569
591
  " runs-on: ubuntu-latest",
592
+ ...jobPermissions(o.extra, { contents: "read" }, "gate"),
570
593
  ...defaults,
571
594
  " outputs:",
572
595
  " commit: ${{ steps.green.outputs.commit }}",
@@ -582,6 +605,7 @@ function renderGithubDispatch(o) {
582
605
  " cut:",
583
606
  ` needs: ${built.length > 0 ? `[gate, ${built.join(", ")}]` : "gate"}`,
584
607
  " runs-on: ubuntu-latest",
608
+ ...jobPermissions(o.extra, { contents: "write", ...(o.context.signing && o.context.doctor ? { "id-token": "write" } : {}) }, "cut"),
585
609
  ...defaults,
586
610
  ...o.extra.githubEnv([` CHANT_RELEASE_COMMIT: ${commit}`, ` CHANT_RELEASE_LABEL: ${GATE_LABEL}`, ...cutEnvToken(o)]),
587
611
  " steps:",
@@ -597,6 +621,7 @@ function renderGithubDispatch(o) {
597
621
  " publish:",
598
622
  ` needs: [gate, cut${built.map((b) => `, ${b}`).join("")}]`,
599
623
  " runs-on: ubuntu-latest",
624
+ ...jobPermissions(o.extra, { contents: "write", "id-token": "write" }, "publish"),
600
625
  ...defaults,
601
626
  ...o.extra.githubEnv([` CHANT_RELEASE_LABEL: ${GATE_LABEL}`, ...o.forgeToken]),
602
627
  " steps:",
@@ -612,7 +637,7 @@ function renderGithubDispatch(o) {
612
637
  ` - run: ${o.chant} release publish "$CHANT_RELEASE_LABEL" ${o.flags}`,
613
638
  ];
614
639
  if (o.after.length > 0) {
615
- lines.push(" after-release:", " needs: [gate, publish]", " runs-on: ubuntu-latest", ...defaults, " env:", ` CHANT_RELEASE_LABEL: ${GATE_LABEL}`, " steps:", ...githubSetup(commit, o.fullSetup), ...installLines, ...o.after.map((l) => ` - run: ${l}`));
640
+ lines.push(" after-release:", " needs: [gate, publish]", " runs-on: ubuntu-latest", ...jobPermissions(o.extra, { contents: "read" }, "after"), ...defaults, " env:", ` CHANT_RELEASE_LABEL: ${GATE_LABEL}`, " steps:", ...githubSetup(commit, o.fullSetup), ...installLines, ...o.after.map((l) => ` - run: ${l}`));
616
641
  }
617
642
  return tagComments(`${lines.join("\n")}\n`);
618
643
  }
@@ -740,7 +765,7 @@ export async function runReleaseWorkflow(ctx) {
740
765
  const { gitTop } = await import("./tree.js");
741
766
  const { securityGroupsAt } = await import("./security.js");
742
767
  const { shellArg } = await import("./member-pipeline.js");
743
- const usage = "chant release workflow [--forge github|gitlab|forgejo] [--install <command>] [--build <command>] [--chant <command>] [--output <file>]";
768
+ const usage = "chant release workflow [--forge github|gitlab|forgejo] [--install <command>] [--build <command>] [--chant <command>] [--output <file>] [--force]";
744
769
  const { args } = ctx;
745
770
  // #5149: a project with only a chant.config.ts, and no chant.workspace.json, renders its release workflow too.
746
771
  const found = findWorkspaceRoot(process.cwd());
@@ -783,6 +808,7 @@ export async function runReleaseWorkflow(ctx) {
783
808
  }
784
809
  // #5154: a train publishes its members' targets, so their credentials, tools and signing are the workflow's.
785
810
  const memberReleases = [];
811
+ let goreleaserDir;
786
812
  if (release?.train) {
787
813
  const { locateWorkspace } = await import("./which-chant.js");
788
814
  const { readDeclaration } = await import("./declaration.js");
@@ -793,18 +819,32 @@ export async function runReleaseWorkflow(ctx) {
793
819
  const r = (await loadChantConfig(join(root, m.dir))).config.release;
794
820
  if (r)
795
821
  memberReleases.push(r);
822
+ if (r?.artifacts && goreleaserDir === undefined && (await import("../lifecycle/release-artifacts.js")).usesGoreleaser(r.artifacts))
823
+ goreleaserDir = m.dir.split(sep).join("/");
796
824
  }
797
825
  catch (err) {
798
826
  console.error(formatError({ message: `member ${m.name}'s chant.config.ts could not be read: ${err instanceof Error ? err.message : String(err)}`, hint: usage }));
799
827
  return 1;
800
828
  }
801
829
  }
802
- const shipped = memberReleases.find((r) => (r.images?.length ?? 0) > 0 || (r.artifacts?.length ?? 0) > 0);
803
- if (shipped) {
804
- console.error(formatError({ message: "release.train: a member declares release.images or release.artifacts, and the train workflow hands no image or file from its cut job to its publish job", hint: "Release that member with its own workflow, or publish its images and files from its npm package." }));
805
- return 1;
830
+ // #5216: a member's files are built by its cut, in the train's cut job; a train has no per-platform build jobs for builtBy to name.
831
+ const { checkReleaseArtifacts, ReleaseArtifactError } = await import("../lifecycle/release-artifacts.js");
832
+ for (const r of memberReleases) {
833
+ if ((r.artifacts?.length ?? 0) === 0)
834
+ continue;
835
+ try {
836
+ checkReleaseArtifacts(r.artifacts, { builds: [] });
837
+ }
838
+ catch (err) {
839
+ if (!(err instanceof ReleaseArtifactError))
840
+ throw err;
841
+ console.error(formatError({ message: `release.train: a member's ${err.message} [${err.code}]`, hint: "A train's members build their files in the train's cut job: build them there rather than in release.workflow.builds." }));
842
+ return 1;
843
+ }
806
844
  }
807
845
  }
846
+ const memberImages = memberReleases.flatMap((r) => r.images ?? []);
847
+ const memberArtifacts = memberReleases.flatMap((r) => r.artifacts ?? []);
808
848
  const allTargets = [...(release?.publish ?? []), ...memberReleases.flatMap((r) => r.publish ?? [])];
809
849
  const { resolveSigning } = await import("../lifecycle/publish-signing.js");
810
850
  const signs = [release, ...memberReleases].some((r) => resolveSigning(r?.signing, groups).on && (r?.publish ?? []).some((t) => t.type === "oci" || t.type === "forge" || t.type === "pypi"));
@@ -838,7 +878,7 @@ export async function runReleaseWorkflow(ctx) {
838
878
  tags,
839
879
  ...(release?.workflow ? { pipeline: release.workflow } : {}),
840
880
  ...((release?.images?.length ?? 0) > 0 ? { images: true, imageArchives: resolveReleaseImages(release.images).map((i) => i.archive), imagePlatforms: releaseImagePlatforms(release.images) } : {}),
841
- ...((release?.artifacts?.length ?? 0) > 0 ? { artifacts: true, ...((await import("../lifecycle/release-artifacts.js")).usesGoreleaser(release.artifacts) ? { goreleaser: true } : {}) } : {}),
881
+ ...((release?.artifacts?.length ?? 0) > 0 ? { artifacts: true, ...((await import("../lifecycle/release-artifacts.js")).usesGoreleaser(release.artifacts) ? { goreleaser: true } : {}), ...((await import("../lifecycle/release-artifacts.js")).usesNfpm(release.artifacts) ? { nfpm: true } : {}) } : {}),
842
882
  ...(release?.lane ? { lane: release.lane } : {}),
843
883
  green: await (async () => {
844
884
  const { resolveGreenSource } = await import("../lifecycle/release-green.js");
@@ -856,7 +896,15 @@ export async function runReleaseWorkflow(ctx) {
856
896
  ...(release?.version ? { version: true } : {}),
857
897
  ...(signs ? { signing: true } : {}),
858
898
  ...(allTargets.length > 0 ? { publish: allTargets } : {}),
859
- ...(release?.train ? { train: { env: release.train.env } } : {}),
899
+ ...(release?.train
900
+ ? {
901
+ train: {
902
+ env: release.train.env,
903
+ ...(memberImages.length > 0 ? { images: true, imagePlatforms: releaseImagePlatforms(memberImages) } : {}),
904
+ ...(memberArtifacts.length > 0 ? { artifacts: true, ...((await import("../lifecycle/release-artifacts.js")).usesGoreleaser(memberArtifacts) ? { goreleaser: true, ...(goreleaserDir ? { goreleaserDir } : {}) } : {}) } : {}),
905
+ },
906
+ }
907
+ : {}),
860
908
  ...(args.ciInstall ? { install: args.ciInstall } : {}),
861
909
  ...(args.buildCommand ? { build: args.buildCommand } : !hasBuildScript(root) && release?.workflow?.build === undefined ? { build: null } : {}),
862
910
  ...(args.ciChant ? { chant: args.ciChant } : {}),
@@ -881,6 +929,12 @@ export async function runReleaseWorkflow(ctx) {
881
929
  parts.push("--chant", args.ciChant);
882
930
  if (args.output && !(isRenderPath(target) && asCommitted === defaultTarget))
883
931
  parts.push("--output", relative(root, asCommitted).split(sep).join("/"));
932
+ // A file a person wrote, such as the npm publish workflow release.workflow.file names, is replaced only with --force.
933
+ if (args.force !== true && existsSync(target) && !readFileSync(target, "utf-8").includes(GENERATED_MARKER)) {
934
+ const shownTarget = relative(process.cwd(), target).split(sep).join("/") || target;
935
+ console.error(formatError({ message: `${shownTarget} exists and chant did not write it [release-workflow-exists]`, hint: "Run again with --force to replace it." }));
936
+ return 1;
937
+ }
884
938
  mkdirSync(dirname(target), { recursive: true });
885
939
  writeFileSync(target, releaseWorkflowHeader(parts.map(shellArg).join(" ")) + text);
886
940
  const shown = relative(process.cwd(), target).split(sep).join("/") || target;
@@ -908,5 +962,7 @@ export async function runReleaseWorkflow(ctx) {
908
962
  console.log("The job that builds release.artifacts runs goreleaser with the Go of the job's image: give it an image with the Go your go.mod names.");
909
963
  if (forge === "gitlab" && release?.workflow?.trigger === "dispatch")
910
964
  console.log("The cut and publish jobs push with CHANT_RELEASE_TOKEN: a project access token with write_repository, as a masked CI/CD variable.");
965
+ if (forge === "gitlab" && release?.train && release.workflow?.trigger === "dispatch")
966
+ console.log(`Start a train by running a pipeline with CHANT_RELEASE_LEVELS=auto (or the levels), and publish a recorded one with CHANT_RELEASE_TRAIN=<id>. A release-train/${release.train.env}/* tag pushed from a workstation starts nothing in this file: publish it with CHANT_RELEASE_TRAIN.`);
911
967
  return 0;
912
968
  }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * The files a release train's members build at the cut, carried from the job
3
+ * that cut them to the job that publishes them (#5216), and the signature
4
+ * check of each member before the publish.
5
+ *
6
+ * `chant workspace train artifacts <env> [<train>] [--from <dir>] [-o <dir>]
7
+ * [--no-build] [--json]`, in a checkout of the train's commit: for each member
8
+ * the train cut from this commit that declares `release.images` or
9
+ * `release.artifacts`, the image archives and files the release records are
10
+ * checked against their recorded digests, as `chant release images` and
11
+ * `chant release artifacts` check one member's:
12
+ *
13
+ * - `--from <dir>` first copies each member's files from `<dir>/<member
14
+ * directory>/`, where an earlier job staged them;
15
+ * - a member whose files are all here is checked as they are; a member with
16
+ * one missing builds its images, or its files, again (`--no-build` refuses
17
+ * instead), and what it builds must have the recorded digests;
18
+ * - `-o <dir>` stages every member's checked files at `<dir>/<member
19
+ * directory>/<path>`, with `chant-train-artifacts.json` naming the members,
20
+ * for the next job's `--from`.
21
+ *
22
+ * `chant workspace train verify <env> [<train>] [--json]` runs `chant release
23
+ * verify` for each member the train cut from this commit, so a cut whose
24
+ * signature does not verify stops the publish (the `verified-releases`
25
+ * group).
26
+ */
27
+ import { type ReadTrain } from "./release-train.js";
28
+ /** The first chant with `chant workspace train artifacts`, `train verify` and `train cut --doctor`, and a train publish that gives a member with images its digests in `CHANT_RELEASE_DIGESTS` (#5216): what the train workflow's cut and publish jobs run. */
29
+ export declare const TRAIN_ARTIFACTS_FLOOR = "0.124.103";
30
+ /** The file `-o` writes beside the staged files, naming the members staged. */
31
+ export declare const TRAIN_ARTIFACTS_INDEX = "chant-train-artifacts.json";
32
+ /** A member the train cut from this checkout's commit. */
33
+ export interface TrainMemberHere {
34
+ member: string;
35
+ /** The member's directory on disk. */
36
+ dir: string;
37
+ /** The member's directory from the workspace root, with `/`. */
38
+ rel: string;
39
+ /** The label, or the release digest for a release with none: what `chant release <command>` takes. */
40
+ ref: string;
41
+ releaseDigest: string;
42
+ }
43
+ /** The train, and its members cut from the commit checked out at the workspace root. */
44
+ export declare function trainMembersHere(cwd: string, env: string, ref?: string): Promise<{
45
+ root: string;
46
+ train: ReadTrain;
47
+ members: TrainMemberHere[];
48
+ }>;
49
+ /** Runs this chant with `args` in `cwd` and returns its exit code; its stdout goes to this process's stderr. */
50
+ export type MemberChant = (args: string[], cwd: string) => number;
51
+ /** The default {@link MemberChant}: this chant, its stdout on stderr so a `--json` caller's stdout stays one document. */
52
+ export declare const spawnMemberChant: MemberChant;
53
+ export interface TrainArtifactsQuery {
54
+ cwd: string;
55
+ env: string;
56
+ train?: string;
57
+ /** Copy each member's files from `<from>/<member directory>/` first. */
58
+ from?: string;
59
+ /** Stage each member's checked files at `<output>/<member directory>/`. */
60
+ output?: string;
61
+ /** Refuse a member with a file missing rather than build it again. */
62
+ noBuild?: boolean;
63
+ chant?: MemberChant;
64
+ say?: (line: string) => void;
65
+ }
66
+ /** One member's files, as checked. */
67
+ export interface TrainArtifactsMember {
68
+ member: string;
69
+ ref: string;
70
+ /** The image archives the release records, from the member's directory. */
71
+ images: string[];
72
+ /** The `release.artifacts` files the release records, from the member's directory. */
73
+ files: string[];
74
+ /** Whether the images, and the files, were built again here rather than checked as they were. */
75
+ built: {
76
+ images: boolean;
77
+ files: boolean;
78
+ };
79
+ /** How many of the paths `--from` copied. */
80
+ copied: number;
81
+ }
82
+ export interface TrainArtifactsOutcome {
83
+ train: ReadTrain;
84
+ members: TrainArtifactsMember[];
85
+ staged: string | null;
86
+ }
87
+ /** Check, build again where missing, and stage the images and files of every member the train cut here (#5216). */
88
+ export declare function trainArtifacts(q: TrainArtifactsQuery): Promise<TrainArtifactsOutcome>;
89
+ /** Run `chant release verify` for each member the train cut here (#5216); every failure is reported before the exit. */
90
+ export declare function trainVerify(q: {
91
+ cwd: string;
92
+ env: string;
93
+ train?: string;
94
+ chant?: MemberChant;
95
+ say?: (line: string) => void;
96
+ }): Promise<{
97
+ train: ReadTrain;
98
+ members: Array<{
99
+ member: string;
100
+ ref: string;
101
+ ok: boolean;
102
+ }>;
103
+ }>;
104
+ /** `chant workspace train artifacts <env> [<train>]` (#5216). */
105
+ export declare function runTrainArtifacts(ctx: import("../cli/registry.js").CommandContext, words: string[]): Promise<number>;
106
+ /** `chant workspace train verify <env> [<train>]` (#5216). */
107
+ export declare function runTrainVerify(ctx: import("../cli/registry.js").CommandContext, words: string[]): Promise<number>;
@@ -0,0 +1,239 @@
1
+ /**
2
+ * The files a release train's members build at the cut, carried from the job
3
+ * that cut them to the job that publishes them (#5216), and the signature
4
+ * check of each member before the publish.
5
+ *
6
+ * `chant workspace train artifacts <env> [<train>] [--from <dir>] [-o <dir>]
7
+ * [--no-build] [--json]`, in a checkout of the train's commit: for each member
8
+ * the train cut from this commit that declares `release.images` or
9
+ * `release.artifacts`, the image archives and files the release records are
10
+ * checked against their recorded digests, as `chant release images` and
11
+ * `chant release artifacts` check one member's:
12
+ *
13
+ * - `--from <dir>` first copies each member's files from `<dir>/<member
14
+ * directory>/`, where an earlier job staged them;
15
+ * - a member whose files are all here is checked as they are; a member with
16
+ * one missing builds its images, or its files, again (`--no-build` refuses
17
+ * instead), and what it builds must have the recorded digests;
18
+ * - `-o <dir>` stages every member's checked files at `<dir>/<member
19
+ * directory>/<path>`, with `chant-train-artifacts.json` naming the members,
20
+ * for the next job's `--from`.
21
+ *
22
+ * `chant workspace train verify <env> [<train>] [--json]` runs `chant release
23
+ * verify` for each member the train cut from this commit, so a cut whose
24
+ * signature does not verify stops the publish (the `verified-releases`
25
+ * group).
26
+ */
27
+ import { spawnSync } from "node:child_process";
28
+ import { cpSync, existsSync, mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
29
+ import { tmpdir } from "node:os";
30
+ import { join, relative, resolve, sep } from "node:path";
31
+ import { readDeclaration } from "./declaration.js";
32
+ import { findTrain, readReleaseTrains } from "./release-train.js";
33
+ import { ownChant, TrainCutError } from "./train-cut.js";
34
+ import { locateWorkspace } from "./which-chant.js";
35
+ import { NEXT_RELEASE } from "../release-floors.js";
36
+ /** The first chant with `chant workspace train artifacts`, `train verify` and `train cut --doctor`, and a train publish that gives a member with images its digests in `CHANT_RELEASE_DIGESTS` (#5216): what the train workflow's cut and publish jobs run. */
37
+ export const TRAIN_ARTIFACTS_FLOOR = NEXT_RELEASE;
38
+ /** The file `-o` writes beside the staged files, naming the members staged. */
39
+ export const TRAIN_ARTIFACTS_INDEX = "chant-train-artifacts.json";
40
+ /** The train, and its members cut from the commit checked out at the workspace root. */
41
+ export async function trainMembersHere(cwd, env, ref) {
42
+ const located = locateWorkspace(cwd);
43
+ const root = located.rootOnDisk;
44
+ const train = findTrain((await readReleaseTrains(root, env)).records, ref);
45
+ if (!train)
46
+ throw new TrainCutError("train-unknown", ref ? `no release train ${ref} is recorded for ${env}` : `no release train is recorded for ${env}`, `List them with chant workspace train list ${env}.`);
47
+ let head;
48
+ try {
49
+ head = spawnSync("git", ["rev-parse", "HEAD"], { cwd: root, encoding: "utf-8" }).stdout.trim();
50
+ }
51
+ catch {
52
+ head = "";
53
+ }
54
+ if (!head)
55
+ throw new TrainCutError("not-a-git-repository", "a train's files are checked in a checkout of its commit, and this directory is not in a git repository");
56
+ const dirs = new Map(readDeclaration(located.tree, "", { rootChant: true }).members.map((m) => [m.name, m.dir]));
57
+ const members = [];
58
+ for (const m of train.members.filter((x) => x.commit === head)) {
59
+ const rel = dirs.get(m.member);
60
+ if (rel === undefined)
61
+ throw new TrainCutError("train-member-unknown", `release train ${train.id} pins ${m.member}, which the declaration does not list`);
62
+ members.push({ member: m.member, dir: resolve(root, rel), rel: rel.split(sep).join("/"), ref: m.label ?? m.releaseDigest, releaseDigest: m.releaseDigest });
63
+ }
64
+ if (members.length === 0)
65
+ throw new TrainCutError("train-nothing-cut-here", `release train ${train.id} has no release cut from this checkout's commit ${head.slice(0, 12)}`, "Check out the commit the train's release-train tag names.");
66
+ return { root, train, members };
67
+ }
68
+ /** The default {@link MemberChant}: this chant, its stdout on stderr so a `--json` caller's stdout stays one document. */
69
+ export const spawnMemberChant = (args, cwd) => {
70
+ const [bin, ...pre] = ownChant();
71
+ const r = spawnSync(bin, [...pre, ...args], { cwd, stdio: ["ignore", 2, 2] });
72
+ return r.status ?? 1;
73
+ };
74
+ /** Check, build again where missing, and stage the images and files of every member the train cut here (#5216). */
75
+ export async function trainArtifacts(q) {
76
+ const { train, members } = await trainMembersHere(q.cwd, q.env, q.train);
77
+ const { loadChantConfig } = await import("../config.js");
78
+ const { resolveRelease } = await import("../lifecycle/release-store.js");
79
+ const { releaseArtifactFiles } = await import("../lifecycle/release-artifacts.js");
80
+ const { resolveReleaseImages } = await import("../lifecycle/release-images.js");
81
+ const chant = q.chant ?? spawnMemberChant;
82
+ const say = q.say ?? (() => undefined);
83
+ const out = [];
84
+ const scratch = mkdtempSync(join(tmpdir(), "chant-train-artifacts-"));
85
+ for (const m of members) {
86
+ const release = (await loadChantConfig(m.dir)).config.release;
87
+ const declaredImages = release?.images ?? [];
88
+ const declaredFiles = release?.artifacts ?? [];
89
+ if (declaredImages.length === 0 && declaredFiles.length === 0)
90
+ continue;
91
+ const found = await resolveRelease(m.releaseDigest, { cwd: m.dir });
92
+ if (!found)
93
+ throw new TrainCutError("release-not-found", `${m.member}: the train pins release ${m.releaseDigest}, which no cut in the member names`, `Fetch chant/lifecycle (git fetch origin chant/lifecycle:chant/lifecycle) in the train's checkout.`);
94
+ const images = resolveReleaseImages(declaredImages).map((i) => i.archive.replace(/^\.\//, ""));
95
+ const files = releaseArtifactFiles(found.release, declaredFiles.map((d) => d.name)).map((f) => f.path);
96
+ let copied = 0;
97
+ if (q.from !== undefined) {
98
+ for (const p of [...images, ...files]) {
99
+ const src = resolve(q.from, m.rel, p);
100
+ if (!existsSync(src))
101
+ continue;
102
+ const dest = resolve(m.dir, p);
103
+ mkdirSync(resolve(dest, ".."), { recursive: true });
104
+ cpSync(src, dest, { recursive: true, force: true });
105
+ copied++;
106
+ }
107
+ }
108
+ const here = (paths) => paths.length > 0 && paths.every((p) => existsSync(resolve(m.dir, p)));
109
+ const built = { images: false, files: false };
110
+ const step = (what, paths) => {
111
+ const present = here(paths);
112
+ if (!present && q.noBuild) {
113
+ const absent = paths.filter((p) => !existsSync(resolve(m.dir, p)));
114
+ throw new TrainCutError("train-artifact-missing", `${m.member} ${m.ref}: ${absent.length > 0 ? absent.join(", ") : `its release.${what}`} ${absent.length === 1 ? "is" : "are"} not here`, "Hand this job the files the cut staged (--from <dir>), or run without --no-build to build them again.");
115
+ }
116
+ if (!present)
117
+ built[what === "images" ? "images" : "files"] = true;
118
+ const args = what === "images" ? ["release", "images", m.ref, ...(present ? ["--no-build"] : []), "-o", join(scratch, `${m.member}-digests.json`)] : ["release", "artifacts", m.ref, ...(present ? ["--no-build"] : [])];
119
+ say(`${m.member} ${m.ref}: ${present ? "check" : "build again and check"} its ${what === "images" ? `image archive(s) ${paths.join(", ")}` : `file(s)${paths.length > 0 ? ` ${paths.join(", ")}` : ""}`}`);
120
+ const code = chant(args, m.dir);
121
+ if (code !== 0)
122
+ throw new TrainCutError(`train-${what === "images" ? "image" : "artifact"}-check-failed`, `${m.member} ${m.ref}: chant ${args.slice(0, 3).join(" ")}${present ? " --no-build" : ""} failed (exit ${code})`, "Its output above says which file differs from the release. Publish the files the cut built, or cut a new train.");
123
+ };
124
+ if (declaredImages.length > 0)
125
+ step("images", images);
126
+ if (declaredFiles.length > 0)
127
+ step("artifacts", files);
128
+ if (q.output !== undefined) {
129
+ for (const p of [...images, ...files]) {
130
+ const dest = resolve(q.output, m.rel, p);
131
+ mkdirSync(resolve(dest, ".."), { recursive: true });
132
+ cpSync(resolve(m.dir, p), dest, { recursive: true, force: true });
133
+ }
134
+ }
135
+ out.push({ member: m.member, ref: m.ref, images, files, built, copied });
136
+ }
137
+ let staged = null;
138
+ if (q.output !== undefined) {
139
+ staged = resolve(q.output);
140
+ mkdirSync(staged, { recursive: true });
141
+ // Always written, so the next job finds a staged directory even when no member of this train builds files.
142
+ writeFileSync(join(staged, TRAIN_ARTIFACTS_INDEX), `${JSON.stringify({ train: train.id, members: out.map((m) => ({ member: m.member, ref: m.ref, images: m.images, files: m.files })) }, null, 2)}\n`);
143
+ }
144
+ return { train, members: out, staged };
145
+ }
146
+ /** Run `chant release verify` for each member the train cut here (#5216); every failure is reported before the exit. */
147
+ export async function trainVerify(q) {
148
+ const { train, members } = await trainMembersHere(q.cwd, q.env, q.train);
149
+ const chant = q.chant ?? spawnMemberChant;
150
+ const say = q.say ?? (() => undefined);
151
+ const out = members.map((m) => {
152
+ say(`${m.member} ${m.ref}: chant release verify ${m.ref}`);
153
+ return { member: m.member, ref: m.ref, ok: chant(["release", "verify", m.ref], m.dir) === 0 };
154
+ });
155
+ const failed = out.filter((m) => !m.ok);
156
+ if (failed.length > 0) {
157
+ throw new TrainCutError("train-verify-failed", `release verify failed for ${failed.map((m) => `${m.member} ${m.ref}`).join(", ")}, so nothing of train ${train.id} is published`, "Its output above says why. A cut whose signature does not verify is cut again by a signer .chant/allowed_signers lists.");
158
+ }
159
+ return { train, members: out };
160
+ }
161
+ const ARTIFACTS_USAGE = "chant workspace train artifacts <env> [<train id|digest>] [--from <dir>] [-o <dir>] [--no-build] [--json]";
162
+ const VERIFY_USAGE = "chant workspace train verify <env> [<train id|digest>] [--json]";
163
+ async function report(err, json, usage) {
164
+ const { formatError } = await import("../cli/format.js");
165
+ const { WorkspaceReadError } = await import("./declaration.js");
166
+ if (err instanceof TrainCutError) {
167
+ if (json)
168
+ console.log(JSON.stringify({ status: "refused", code: err.code, message: err.message }, null, 2));
169
+ console.error(formatError({ message: `${err.message} [${err.code}]`, hint: err.fix ?? usage }));
170
+ return 1;
171
+ }
172
+ if (err instanceof WorkspaceReadError) {
173
+ console.error(formatError({ message: `${err.code}: ${err.describe()}`, hint: usage }));
174
+ return 1;
175
+ }
176
+ throw err;
177
+ }
178
+ /** `chant workspace train artifacts <env> [<train>]` (#5216). */
179
+ export async function runTrainArtifacts(ctx, words) {
180
+ const { formatError, formatSuccess } = await import("../cli/format.js");
181
+ const [env, ref] = words;
182
+ if (!env || words.length > 2) {
183
+ console.error(formatError({ message: env ? `chant workspace train artifacts takes an environment and a train, not ${words.join(" ")}` : "chant workspace train artifacts needs an environment", hint: ARTIFACTS_USAGE }));
184
+ return 1;
185
+ }
186
+ const json = ctx.args.json === true;
187
+ const cwd = resolve(".");
188
+ const { fetchLifecycle } = await import("../lifecycle/git.js");
189
+ await fetchLifecycle({ cwd }).catch(() => false);
190
+ let outcome;
191
+ try {
192
+ outcome = await trainArtifacts({
193
+ cwd,
194
+ env,
195
+ ...(ref !== undefined ? { train: ref } : {}),
196
+ ...(ctx.args.migrateFrom !== undefined ? { from: resolve(ctx.args.migrateFrom) } : {}),
197
+ ...(ctx.args.output !== undefined ? { output: resolve(ctx.args.output) } : {}),
198
+ ...(ctx.args.noBuild ? { noBuild: true } : {}),
199
+ say: (line) => console.error(line),
200
+ });
201
+ }
202
+ catch (err) {
203
+ return report(err, json, ARTIFACTS_USAGE);
204
+ }
205
+ if (json) {
206
+ console.log(JSON.stringify({ train: outcome.train.id, env, members: outcome.members, staged: outcome.staged }, null, 2));
207
+ return 0;
208
+ }
209
+ const n = outcome.members.length;
210
+ const where = outcome.staged ? `, staged in ${relative(cwd, outcome.staged) || outcome.staged}` : "";
211
+ console.error(formatSuccess(n === 0 ? `No member release train ${outcome.train.id} cut here declares release.images or release.artifacts${where}` : `Checked the images and files of ${n} member(s) of release train ${outcome.train.id} against their releases${where}`));
212
+ return 0;
213
+ }
214
+ /** `chant workspace train verify <env> [<train>]` (#5216). */
215
+ export async function runTrainVerify(ctx, words) {
216
+ const { formatError, formatSuccess } = await import("../cli/format.js");
217
+ const [env, ref] = words;
218
+ if (!env || words.length > 2) {
219
+ console.error(formatError({ message: env ? `chant workspace train verify takes an environment and a train, not ${words.join(" ")}` : "chant workspace train verify needs an environment", hint: VERIFY_USAGE }));
220
+ return 1;
221
+ }
222
+ const json = ctx.args.json === true;
223
+ const cwd = resolve(".");
224
+ const { fetchLifecycle } = await import("../lifecycle/git.js");
225
+ await fetchLifecycle({ cwd }).catch(() => false);
226
+ let outcome;
227
+ try {
228
+ outcome = await trainVerify({ cwd, env, ...(ref !== undefined ? { train: ref } : {}), say: (line) => console.error(line) });
229
+ }
230
+ catch (err) {
231
+ return report(err, json, VERIFY_USAGE);
232
+ }
233
+ if (json) {
234
+ console.log(JSON.stringify({ train: outcome.train.id, env, members: outcome.members }, null, 2));
235
+ return 0;
236
+ }
237
+ console.error(formatSuccess(`Verified ${outcome.members.length} member(s) of release train ${outcome.train.id}`));
238
+ return 0;
239
+ }