@intentius/chant 0.124.103 → 0.124.104

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 (67) hide show
  1. package/dist/audit/secrets.d.ts +6 -0
  2. package/dist/audit/secrets.js +9 -2
  3. package/dist/cli/commands/import-index.d.ts +15 -0
  4. package/dist/cli/commands/import-index.js +37 -3
  5. package/dist/cli/handlers/lifecycle.js +6 -0
  6. package/dist/cli/handlers/release-config.d.ts +15 -0
  7. package/dist/cli/handlers/release-config.js +58 -0
  8. package/dist/cli/handlers/release.js +36 -3
  9. package/dist/cli/main.js +12 -2
  10. package/dist/cli/parse-args.js +7 -0
  11. package/dist/cli/registry.d.ts +2 -0
  12. package/dist/cli/release-commands/cut.js +3 -0
  13. package/dist/config-import.js +26 -4
  14. package/dist/config.d.ts +14 -0
  15. package/dist/config.js +4 -0
  16. package/dist/floor-table.data.js +7 -6
  17. package/dist/floor-table.js +3 -1
  18. package/dist/graph-refs.d.ts +9 -0
  19. package/dist/graph-refs.js +9 -7
  20. package/dist/lifecycle/cloud-index.d.ts +6 -0
  21. package/dist/lifecycle/cloud-index.js +32 -5
  22. package/dist/lifecycle/identity-match.d.ts +18 -2
  23. package/dist/lifecycle/identity-match.js +10 -5
  24. package/dist/lifecycle/index-drift.d.ts +13 -0
  25. package/dist/lifecycle/index-drift.js +21 -3
  26. package/dist/lifecycle/index-import.d.ts +15 -0
  27. package/dist/lifecycle/index-import.js +25 -2
  28. package/dist/lifecycle/index-join.d.ts +1 -1
  29. package/dist/lifecycle/index-join.js +1 -1
  30. package/dist/lifecycle/publish-declaration.d.ts +6 -0
  31. package/dist/lifecycle/publish-declaration.js +18 -1
  32. package/dist/lifecycle/publish-forge.d.ts +2 -0
  33. package/dist/lifecycle/publish-forge.js +3 -1
  34. package/dist/lifecycle/publish-oci.d.ts +27 -0
  35. package/dist/lifecycle/publish-oci.js +63 -8
  36. package/dist/lifecycle/release-changelog.d.ts +18 -5
  37. package/dist/lifecycle/release-changelog.js +22 -10
  38. package/dist/lifecycle/release-cut.d.ts +13 -1
  39. package/dist/lifecycle/release-cut.js +3 -0
  40. package/dist/lifecycle/release-images.d.ts +32 -2
  41. package/dist/lifecycle/release-images.js +70 -2
  42. package/dist/lifecycle/release-init-goreleaser-images.d.ts +21 -0
  43. package/dist/lifecycle/release-init-goreleaser-images.js +160 -0
  44. package/dist/lifecycle/release-init.d.ts +22 -0
  45. package/dist/lifecycle/release-init.js +86 -7
  46. package/dist/local-chant.d.ts +3 -0
  47. package/dist/local-chant.js +28 -2
  48. package/dist/release-floors.d.ts +10 -6
  49. package/dist/release-floors.js +10 -6
  50. package/dist/ts-loader.d.ts +12 -3
  51. package/dist/ts-loader.js +27 -11
  52. package/dist/wave-runtime.mjs +291 -290
  53. package/dist/workspace/catalog-edges.d.ts +22 -0
  54. package/dist/workspace/catalog-edges.js +23 -0
  55. package/dist/workspace/release-steps/goreleaser.d.ts +6 -3
  56. package/dist/workspace/release-steps/goreleaser.js +12 -6
  57. package/dist/workspace/release-toolchains.d.ts +6 -0
  58. package/dist/workspace/release-toolchains.js +8 -0
  59. package/dist/workspace/release-train-workflow.d.ts +18 -0
  60. package/dist/workspace/release-train-workflow.js +135 -7
  61. package/dist/workspace/release-train.js +1 -1
  62. package/dist/workspace/release-workflow.d.ts +26 -0
  63. package/dist/workspace/release-workflow.js +60 -12
  64. package/dist/workspace/train-artifacts.js +3 -4
  65. package/dist/workspace/train-cut.d.ts +22 -1
  66. package/dist/workspace/train-cut.js +78 -14
  67. package/package.json +2 -2
@@ -33,6 +33,21 @@
33
33
  * where it will be applied, and the objects one member applies together go to
34
34
  * one namespace far more often than not.
35
35
  *
36
+ * ## A cloud index beside the workspace (#5245)
37
+ *
38
+ * A caller that reads a cluster and a cloud index together (behold's joined
39
+ * read) hands the index's nodes to {@link runCatalogPass} as one more member,
40
+ * through {@link indexedMemberNodes}: the member is the index document's
41
+ * scope key. The cloud kinds are scoped by no catalog, so they sit in the
42
+ * workspace scope with no namespace, which every namespaced holder reaches
43
+ * (`scopeOf` below, and the account-only key `reconstructIndexedEdges`
44
+ * looks a holder's value up under). The index's own account and region are
45
+ * not part of that scope, so a rule that joins a cluster object to an
46
+ * indexed node checks them itself: the IRSA rule keeps a role of the
47
+ * annotation's account, the ExternalSecret rule a secret of the store's
48
+ * region. `deriveEdgesAcross` (../lifecycle/derive-edges.ts) does not join
49
+ * the two: it reads one cloud account, and refuses a cluster source.
50
+ *
36
51
  * ## Declared nodes the rules are not written against
37
52
  *
38
53
  * A catalog's `declaredNode` gives the node the rules read, for a lexicon
@@ -80,6 +95,7 @@
80
95
  import { type ContainmentPair, type RepoPathRef, type NamedCatalog } from "../graph-refs.js";
81
96
  import { type DetailLevel } from "../graph-detail.js";
82
97
  import type { CatalogRuleEntry, ComposedAmbiguous, ComposedDangling, ComposedEdge, ComposedNode, NodeExpansion, WorkspaceGraph } from "./compose-graph.js";
98
+ import type { IndexDocument } from "../lifecycle/index-document.js";
83
99
  /** The scope every node of a declared workspace graph sits in. */
84
100
  export declare const WORKSPACE_SCOPE = "workspace";
85
101
  /** What the catalog pass found, on the ids of the nodes it read. */
@@ -116,6 +132,12 @@ export declare function catalogRules(catalogs: readonly NamedCatalog[]): Record<
116
132
  * it no such file is read.
117
133
  */
118
134
  export declare function runCatalogPass(nodes: readonly ComposedNode[], catalogs: readonly NamedCatalog[], members?: readonly string[], lookPath?: LookPath, readFile?: ReadFile): CatalogPass;
135
+ /**
136
+ * An index document's nodes as members of a catalog pass (#5245): each in the
137
+ * member the document's scope key names, so they sit beside a cluster's
138
+ * objects or a workspace's members in one {@link runCatalogPass}.
139
+ */
140
+ export declare function indexedMemberNodes(doc: IndexDocument): ComposedNode[];
119
141
  /**
120
142
  * Write a pass into the document. `placed` maps an id the pass read to the
121
143
  * id of the node the document draws it as at its detail tier; an id it does
@@ -33,6 +33,21 @@
33
33
  * where it will be applied, and the objects one member applies together go to
34
34
  * one namespace far more often than not.
35
35
  *
36
+ * ## A cloud index beside the workspace (#5245)
37
+ *
38
+ * A caller that reads a cluster and a cloud index together (behold's joined
39
+ * read) hands the index's nodes to {@link runCatalogPass} as one more member,
40
+ * through {@link indexedMemberNodes}: the member is the index document's
41
+ * scope key. The cloud kinds are scoped by no catalog, so they sit in the
42
+ * workspace scope with no namespace, which every namespaced holder reaches
43
+ * (`scopeOf` below, and the account-only key `reconstructIndexedEdges`
44
+ * looks a holder's value up under). The index's own account and region are
45
+ * not part of that scope, so a rule that joins a cluster object to an
46
+ * indexed node checks them itself: the IRSA rule keeps a role of the
47
+ * annotation's account, the ExternalSecret rule a secret of the store's
48
+ * region. `deriveEdgesAcross` (../lifecycle/derive-edges.ts) does not join
49
+ * the two: it reads one cloud account, and refuses a cluster source.
50
+ *
36
51
  * ## Declared nodes the rules are not written against
37
52
  *
38
53
  * A catalog's `declaredNode` gives the node the rules read, for a lexicon
@@ -274,6 +289,14 @@ export function runCatalogPass(nodes, catalogs, members, lookPath, readFile) {
274
289
  expansions,
275
290
  };
276
291
  }
292
+ /**
293
+ * An index document's nodes as members of a catalog pass (#5245): each in the
294
+ * member the document's scope key names, so they sit beside a cluster's
295
+ * objects or a workspace's members in one {@link runCatalogPass}.
296
+ */
297
+ export function indexedMemberNodes(doc) {
298
+ return doc.graph.nodes.map((n) => ({ ...n, member: doc.stamp.scopeKey }));
299
+ }
277
300
  /** A rule path's first step, the `viaAttr` an edge it draws carries, as the pass's own rules do. */
278
301
  const refViaAttr = (path) => path.split(/[.[]/)[0] || path;
279
302
  /** The repository paths the nodes name that `lookPath` does not find (#5102). */
@@ -2,15 +2,18 @@ import type { ReleasePipelineConfig, ReleaseWorkflowForge } from "../release-wor
2
2
  import { type ReleaseWorkflowFeature } from "./types.js";
3
3
  /**
4
4
  * What a job that builds goreleaser entries runs first (#5151): Go from the
5
- * member's `go.mod` (GitHub and Forgejo, unless `release.workflow.setup`
6
- * names `actions/setup-go`), then the pinned goreleaser, downloaded, checked
5
+ * member's `go.mod` (GitHub and Forgejo, unless the job's toolchains set Go
6
+ * up already or `release.workflow.setup` names `actions/setup-go`), without
7
+ * a cache like every other setup step, then the pinned goreleaser, downloaded, checked
7
8
  * by SHA-256 and named by `CHANT_GORELEASER`. A config that sets
8
9
  * `CHANT_GORELEASER` in `release.workflow.env` gets no install. GitLab
9
10
  * jobs run in the project's image, which brings its own Go.
10
11
  */
11
- export declare function goreleaserSetup(forge: ReleaseWorkflowForge, root: string | null, p: ReleasePipelineConfig): {
12
+ export declare function goreleaserSetup(forge: ReleaseWorkflowForge, root: string | null, p: ReleasePipelineConfig, goSetUp?: boolean): {
12
13
  github: string[];
13
14
  gitlab: string[];
14
15
  };
16
+ /** The job's toolchains (#5152) set Go up already, from `release.workflow.toolchains` or a `go.mod` at the project's root (#5268). */
17
+ export declare function setsUpGo(p: ReleasePipelineConfig, projectFiles: readonly string[] | undefined, root: string | null): boolean;
15
18
  /** In the job that builds the files: a dispatched release's cut, or a tag's publish. */
16
19
  export declare const goreleaserFeature: ReleaseWorkflowFeature;
@@ -1,26 +1,32 @@
1
1
  /** goreleaser for the `release.artifacts` entries it builds (#5151). */
2
2
  import { ACTION_PINS, usesRef } from "../../action-pins.js";
3
3
  import { TOOL_PINS, toolInstallLine } from "../../tool-pins.js";
4
+ import { buildJobToolchains } from "../release-toolchains.js";
4
5
  import { RELEASE_RUNNER_PLATFORM } from "./types.js";
5
6
  /**
6
7
  * What a job that builds goreleaser entries runs first (#5151): Go from the
7
- * member's `go.mod` (GitHub and Forgejo, unless `release.workflow.setup`
8
- * names `actions/setup-go`), then the pinned goreleaser, downloaded, checked
8
+ * member's `go.mod` (GitHub and Forgejo, unless the job's toolchains set Go
9
+ * up already or `release.workflow.setup` names `actions/setup-go`), without
10
+ * a cache like every other setup step, then the pinned goreleaser, downloaded, checked
9
11
  * by SHA-256 and named by `CHANT_GORELEASER`. A config that sets
10
12
  * `CHANT_GORELEASER` in `release.workflow.env` gets no install. GitLab
11
13
  * jobs run in the project's image, which brings its own Go.
12
14
  */
13
- export function goreleaserSetup(forge, root, p) {
15
+ export function goreleaserSetup(forge, root, p, goSetUp = false) {
14
16
  const install = p.env?.CHANT_GORELEASER === undefined;
15
17
  if (forge === "gitlab") {
16
18
  return { github: [], gitlab: install ? [`${toolInstallLine(TOOL_PINS.goreleaser, RELEASE_RUNNER_PLATFORM, "/tmp/goreleaser")} && export CHANT_GORELEASER=/tmp/goreleaser/goreleaser`] : [] };
17
19
  }
18
- const go = (p.setup ?? []).some((s) => "uses" in s && /^actions\/setup-go@/.test(s.uses))
20
+ const go = goSetUp || (p.setup ?? []).some((s) => "uses" in s && /^actions\/setup-go@/.test(s.uses))
19
21
  ? []
20
- : [` - uses: ${usesRef(ACTION_PINS.setupGo7)}`, " with:", ` go-version-file: ${root ? `${root}/` : ""}go.mod`];
22
+ : [` - uses: ${usesRef(ACTION_PINS.setupGo7)}`, " with:", ` go-version-file: ${root ? `${root}/` : ""}go.mod`, " cache: false"];
21
23
  const line = `${toolInstallLine(TOOL_PINS.goreleaser, RELEASE_RUNNER_PLATFORM, "$RUNNER_TEMP/goreleaser")} && echo "CHANT_GORELEASER=$RUNNER_TEMP/goreleaser/goreleaser" >> "$GITHUB_ENV"`;
22
24
  return { github: [...go, ...(install ? [` - name: goreleaser ${TOOL_PINS.goreleaser.version}`, ` run: ${JSON.stringify(line)}`] : [])], gitlab: [] };
23
25
  }
26
+ /** The job's toolchains (#5152) set Go up already, from `release.workflow.toolchains` or a `go.mod` at the project's root (#5268). */
27
+ export function setsUpGo(p, projectFiles, root) {
28
+ return buildJobToolchains(p.toolchains, projectFiles, root).some((t) => t.name === "go");
29
+ }
24
30
  /** In the job that builds the files: a dispatched release's cut, or a tag's publish. */
25
31
  export const goreleaserFeature = {
26
32
  name: "goreleaser",
@@ -29,7 +35,7 @@ export const goreleaserFeature = {
29
35
  return [];
30
36
  if (c.job !== (c.shape === "dispatch" ? "cut" : "publish"))
31
37
  return [];
32
- const g = goreleaserSetup(c.forge, c.root, c.pipeline);
38
+ const g = goreleaserSetup(c.forge, c.root, c.pipeline, setsUpGo(c.pipeline, c.input.projectFiles, c.root));
33
39
  const items = c.forge !== "gitlab" ? [{ lines: g.github }] : c.shape === "dispatch" ? g.gitlab : [{ lines: g.gitlab.map((l) => ` - ${JSON.stringify(l)}`) }];
34
40
  return [{ slot: "prepare", order: 20, items }];
35
41
  },
@@ -30,6 +30,12 @@ export declare function toolchainStep(decl: ReleaseToolchainDecl, files: Readonl
30
30
  * first for a job that runs chant, at the declared version when there is one.
31
31
  */
32
32
  export declare function resolveToolchains(decl: readonly ReleaseToolchainDecl[] | false | undefined, files: ReadonlySet<string>, root: string | null, withNode: boolean): ToolchainStep[];
33
+ /**
34
+ * The toolchains a job that builds sets up (#5152): `release.workflow.toolchains`,
35
+ * or those the project's root files name, with Node first. A caller that
36
+ * knows no project files sets up Node alone.
37
+ */
38
+ export declare function buildJobToolchains(decl: readonly ReleaseToolchainDecl[] | false | undefined, projectFiles: readonly string[] | undefined, root: string | null): ToolchainStep[];
33
39
  /** A step's lines in a GitHub or Forgejo job. Node renders as it always has: its inputs unquoted. */
34
40
  export declare function toolchainLines(steps: readonly ToolchainStep[]): string[];
35
41
  /**
@@ -96,6 +96,14 @@ export function resolveToolchains(decl, files, root, withNode) {
96
96
  list.sort((a, b) => (named(a) === "node" ? -1 : named(b) === "node" ? 1 : 0));
97
97
  return list.map((d) => toolchainStep(d, files, root));
98
98
  }
99
+ /**
100
+ * The toolchains a job that builds sets up (#5152): `release.workflow.toolchains`,
101
+ * or those the project's root files name, with Node first. A caller that
102
+ * knows no project files sets up Node alone.
103
+ */
104
+ export function buildJobToolchains(decl, projectFiles, root) {
105
+ return resolveToolchains(decl, new Set(projectFiles ?? (decl === undefined ? ["package.json"] : [])), root, true);
106
+ }
99
107
  /** A step's lines in a GitHub or Forgejo job. Node renders as it always has: its inputs unquoted. */
100
108
  export function toolchainLines(steps) {
101
109
  return steps.flatMap((s) => [
@@ -1,5 +1,6 @@
1
1
  import type { ReleaseGreenSource } from "../lifecycle/release-green.js";
2
2
  import { type JobExtras, type ReleaseWorkflowForge } from "./release-workflow.js";
3
+ import { type ReleaseBuildConfig } from "./release-toolchains.js";
3
4
  export interface TrainWorkflowInput {
4
5
  forge: ReleaseWorkflowForge;
5
6
  env: string;
@@ -40,7 +41,24 @@ export interface TrainWorkflowInput {
40
41
  doctor?: boolean;
41
42
  /** `verified-releases`: `chant workspace train verify` before the publish (#5216). */
42
43
  verify?: boolean;
44
+ /**
45
+ * The members' per-platform builds (#5237), with `trigger: "dispatch"`
46
+ * only. The gate plans the train (`train cut --plan-only`) and gives each
47
+ * build job the label its member is planned at; a member not in the train
48
+ * builds nothing. The cut job unpacks each archive into its member and
49
+ * cuts with `--planned`, so a train labelled otherwise than the builds
50
+ * were is refused with nothing cut. The publish job of the same run
51
+ * unpacks them again.
52
+ */
53
+ builds?: TrainBuild[];
43
54
  }
55
+ /** A member's build job (#5237): the member, its directory from the workspace root, the directory it runs in from the checkout, and its toolchain steps. */
56
+ export type TrainBuild = ReleaseBuildConfig & {
57
+ member: string;
58
+ memberDir: string;
59
+ path: string;
60
+ setup: string[];
61
+ };
44
62
  /** The tag a train's cut pushes, as a GitHub tag filter: `*` stops at `/`, so a member's own tag starts nothing. */
45
63
  export declare function trainTagFilter(env: string): string;
46
64
  /**
@@ -34,8 +34,19 @@
34
34
  * dispatched run publishes in its own publish job.
35
35
  */
36
36
  import { ACTION_PINS, tagComments, usesRef } from "../action-pins.js";
37
- import { gateScript, githubSetup, jobPermissions, LEDGER_FETCH_FIRST } from "./release-workflow.js";
37
+ import { field, gateScript, GIT_TOKEN_ENV, githubSetup, jobPermissions, LEDGER_FETCH_FIRST } from "./release-workflow.js";
38
38
  import { RELEASE_ARTIFACTS_ARTIFACT } from "./release-steps/artifacts.js";
39
+ import { packLine, unpackLine } from "./release-steps/builds.js";
40
+ import { releaseBuildArchive, releaseBuildArtifact } from "./release-toolchains.js";
41
+ /** The gate's output, and GitLab variable, that carries the label a build job's member is planned at. */
42
+ const labelOutput = (b) => `label-${b.name}`;
43
+ const labelVariable = (b) => `CHANT_TRAIN_LABEL_${b.name.toUpperCase().replaceAll("-", "_")}`;
44
+ /** The plan's label of a build's member, read from the plan file: empty when the member is not in the train. */
45
+ const plannedLabel = (b, file) => `${field(`d.members.find((m)=>m.member===${JSON.stringify(b.member)})?.label`)} ${file}`;
46
+ /** The gate's plan (#5237): the train's members and labels at the gate's commit, with no member's dry run. */
47
+ const planLine = (o, file) => `${o.chant} workspace train cut ${o.env} --at "$commit" --levels "\${CHANT_RELEASE_LEVELS:-auto}" --plan-only --json > ${file}`;
48
+ /** A shell word for a directory. */
49
+ const sq = (s) => (/^[A-Za-z0-9_./@+-]+$/.test(s) ? s : `'${s.replaceAll("'", "'\\''")}'`);
39
50
  /** Where the cut job stages the members' images and files, and the publish job finds them (#5216): outside the checkout. */
40
51
  const TRAIN_STAGE = "$RUNNER_TEMP/chant-release-artifacts";
41
52
  /** The tag a train's cut pushes, as a GitHub tag filter: `*` stops at `/`, so a member's own tag starts nothing. */
@@ -78,6 +89,54 @@ export function renderTrainWorkflow(o) {
78
89
  const ledgerFetch = run("git fetch origin chant/lifecycle:chant/lifecycle");
79
90
  const dispatch = o.trigger === "dispatch";
80
91
  const env = o.env;
92
+ const builds = dispatch ? (o.builds ?? []) : [];
93
+ const download = usesRef(o.forge === "forgejo" ? ACTION_PINS.downloadArtifact3 : ACTION_PINS.downloadArtifact4);
94
+ const built = (b) => `needs.build-${b.name}.result == 'success'`;
95
+ // #5237: each build's archive, from the run's build job, unpacked into its member: in the cut with -k, so it replaces no file of the commit.
96
+ const unpackSteps = (cut) => builds.flatMap((b) => [
97
+ ` - if: ${built(b)}`,
98
+ ` uses: ${download}`,
99
+ " with:",
100
+ ` name: ${releaseBuildArtifact(b.name)}`,
101
+ " path: ${{ runner.temp }}/chant-release-builds",
102
+ ` - if: ${built(b)}`,
103
+ ` run: ${unpackLine(`"$RUNNER_TEMP/chant-release-builds/${releaseBuildArchive(b.name)}"`, cut)} -C ${sq(b.memberDir)}`,
104
+ ]);
105
+ const q = (v) => JSON.stringify(v);
106
+ const buildJobs = builds.flatMap((b) => {
107
+ const install = b.install === false ? [] : b.install !== undefined ? [run(b.install)] : o.install ? [run(o.install), ` working-directory: ${o.root ?? "."}`] : [];
108
+ const runner = Array.isArray(b.runner) ? `[${b.runner.map(q).join(", ")}]` : q(b.runner);
109
+ const vars = Object.entries(b.env ?? {});
110
+ for (const [k] of vars)
111
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(k))
112
+ throw new Error(`release.workflow.builds.${b.name}.env: ${JSON.stringify(k)} is not a variable name`);
113
+ return [
114
+ ` build-${b.name}:`,
115
+ " needs: gate",
116
+ ` if: needs.gate.outputs.${labelOutput(b)} != ''`,
117
+ ` runs-on: ${runner}`,
118
+ " permissions:",
119
+ " contents: read",
120
+ " defaults:",
121
+ " run:",
122
+ " shell: bash",
123
+ ` working-directory: ${b.path}`,
124
+ " env:",
125
+ ` CHANT_RELEASE_LABEL: \${{ needs.gate.outputs.${labelOutput(b)} }}`,
126
+ ...vars.map(([k, v]) => ` ${k}: ${q(v)}`),
127
+ " steps:",
128
+ ...githubSetup("${{ needs.gate.outputs.commit }}", b.setup, false),
129
+ ...install,
130
+ ` - run: ${q(b.build)}`,
131
+ ` - run: ${q(packLine(b))}`,
132
+ ` - uses: ${usesRef(o.forge === "forgejo" ? ACTION_PINS.uploadArtifact3 : ACTION_PINS.uploadArtifact4)}`,
133
+ " with:",
134
+ ` name: ${releaseBuildArtifact(b.name)}`,
135
+ ` path: ${b.path === "." ? "" : `${b.path}/`}${releaseBuildArchive(b.name)}`,
136
+ " if-no-files-found: error",
137
+ " retention-days: 1",
138
+ ];
139
+ });
81
140
  const lines = [
82
141
  "name: chant release train",
83
142
  "on:",
@@ -107,10 +166,23 @@ export function renderTrainWorkflow(o) {
107
166
  "jobs:",
108
167
  ];
109
168
  if (dispatch) {
110
- lines.push(" gate:", " if: github.event_name == 'workflow_dispatch' && inputs.train == ''", " runs-on: ubuntu-latest", ...jobPermissions(o.extra, { contents: "read" }, "gate"), ...defaults, " outputs:", " commit: ${{ steps.green.outputs.commit }}", " steps:", ...githubSetup(undefined, o.chantSetup), ...installLines, ciFetch, " - id: green", ...block([...gateScript(o, "$GITHUB_SHA"), 'echo "commit=$commit" >> "$GITHUB_OUTPUT"']), " cut:", " needs: gate", " runs-on: ubuntu-latest", ...jobPermissions(o.extra, { contents: "write" }, "cut"), ...defaults, " outputs:", " train: ${{ steps.cut.outputs.train }}", ...o.extra.githubEnv([" CHANT_RELEASE_COMMIT: ${{ needs.gate.outputs.commit }}", " CHANT_RELEASE_LEVELS: ${{ inputs.levels }}", ...new Set([...(o.cutToken ?? []), ...(o.doctor ? o.forgeToken : [])])]), " steps:", ...githubSetup("${{ needs.gate.outputs.commit }}", o.fullSetup), ...installLines, ...o.extra.githubSteps, ...(o.goreleaser ?? []), ciFetch, run(LEDGER_FETCH_FIRST), " - id: cut", ...block([
169
+ lines.push(" gate:", " if: github.event_name == 'workflow_dispatch' && inputs.train == ''", " runs-on: ubuntu-latest", ...jobPermissions(o.extra, { contents: "read" }, "gate"), ...defaults, " outputs:", " commit: ${{ steps.green.outputs.commit }}", ...(builds.length > 0 ? [" planned: ${{ steps.green.outputs.planned }}", ...builds.map((b) => ` ${labelOutput(b)}: \${{ steps.green.outputs.${labelOutput(b)} }}`)] : []), ...(builds.length > 0 ? [" env:", " CHANT_RELEASE_LEVELS: ${{ inputs.levels }}"] : []), " steps:", ...githubSetup(undefined, o.chantSetup), ...installLines, ciFetch, " - id: green", ...block([
170
+ ...gateScript(o, "$GITHUB_SHA"),
171
+ 'echo "commit=$commit" >> "$GITHUB_OUTPUT"',
172
+ // #5237: the plan, so each build job builds with the label its member is cut at.
173
+ ...(builds.length > 0
174
+ ? [
175
+ planLine(o, '"$RUNNER_TEMP/chant-train-plan.json"'),
176
+ `echo "planned=$(${field("d.planned")} "$RUNNER_TEMP/chant-train-plan.json")" >> "$GITHUB_OUTPUT"`,
177
+ ...builds.map((b) => `echo "${labelOutput(b)}=$(${plannedLabel(b, '"$RUNNER_TEMP/chant-train-plan.json"')})" >> "$GITHUB_OUTPUT"`),
178
+ ]
179
+ : []),
180
+ ]), ...buildJobs, " cut:", ...(builds.length > 0 ? [` needs: [gate, ${builds.map((b) => `build-${b.name}`).join(", ")}]`, " if: ${{ !cancelled() && needs.gate.result == 'success' && !contains(needs.*.result, 'failure') }}"] : [" needs: gate"]), " runs-on: ubuntu-latest", ...jobPermissions(o.extra, { contents: "write" }, "cut"), ...defaults, " outputs:", " train: ${{ steps.cut.outputs.train }}", ...o.extra.githubEnv([" CHANT_RELEASE_COMMIT: ${{ needs.gate.outputs.commit }}", " CHANT_RELEASE_LEVELS: ${{ inputs.levels }}", ...(builds.length > 0 ? [" CHANT_TRAIN_PLANNED: ${{ needs.gate.outputs.planned }}"] : []), ...new Set([...(o.cutToken ?? []), ...(o.doctor ? o.forgeToken : [])]), ...(o.files ? GIT_TOKEN_ENV : [])]), " steps:",
181
+ // #5268: a cut that hands files on keeps no token in .git/config.
182
+ ...githubSetup("${{ needs.gate.outputs.commit }}", o.fullSetup, !o.files), ...installLines, ...o.extra.githubSteps, ...(o.goreleaser ?? []), ciFetch, run(LEDGER_FETCH_FIRST), ...unpackSteps(true), " - id: cut", ...block([
111
183
  'git config user.name "chant release"',
112
184
  'git config user.email "chant-release@localhost"',
113
- `${o.chant} workspace train cut ${env} --at "$CHANT_RELEASE_COMMIT" --levels "\${CHANT_RELEASE_LEVELS:-auto}"${o.doctor ? " --doctor" : ""} --yes --json > "$RUNNER_TEMP/chant-train.json"`,
185
+ `${o.chant} workspace train cut ${env} --at "$CHANT_RELEASE_COMMIT" --levels "\${CHANT_RELEASE_LEVELS:-auto}"${builds.length > 0 ? ' --planned "$CHANT_TRAIN_PLANNED"' : ""}${o.doctor ? " --doctor" : ""} --yes --json > "$RUNNER_TEMP/chant-train.json"`,
114
186
  `train="$(${trainIdScript("$RUNNER_TEMP/chant-train.json")})" || exit 1`,
115
187
  'echo "train=$train" >> "$GITHUB_OUTPUT"',
116
188
  ]), ...(o.files
@@ -132,7 +204,7 @@ export function renderTrainWorkflow(o) {
132
204
  const dispatchedTrain = "${{ inputs.train || needs.cut.outputs.train }}";
133
205
  const checkoutRef = `\${{ needs.gate.outputs.commit || (inputs.train != '' && ${dispatchedTrainRef(env)}) || github.sha }}`;
134
206
  const trainFromRef = `echo "CHANT_RELEASE_TRAIN=\${CHANT_RELEASE_TRAIN:-\${GITHUB_REF_NAME#release-train/${env}/}}" >> "$GITHUB_ENV"`;
135
- lines.push(" publish:", ...(dispatch ? [" needs: [gate, cut]", publishIf] : []), " runs-on: ubuntu-latest", ...jobPermissions(o.extra, { contents: "write", "id-token": "write" }, "publish"), ...defaults, ...o.extra.githubEnv([...(dispatch ? [` CHANT_RELEASE_TRAIN: ${dispatchedTrain}`] : []), ...o.forgeToken]), " steps:", ...githubSetup(dispatch ? checkoutRef : undefined, o.fullSetup), ...installLines, ...o.extra.githubSteps, ...(o.goreleaser ?? []), ciFetch, ledgerFetch, run(trainFromRef), run(`${o.chant} workspace train prepare ${env} "$CHANT_RELEASE_TRAIN"`), ...(o.build ? [run(o.build)] : []), ...(o.files
207
+ lines.push(" publish:", ...(dispatch ? [` needs: [gate, cut${builds.map((b) => `, build-${b.name}`).join("")}]`, publishIf] : []), " runs-on: ubuntu-latest", ...jobPermissions(o.extra, { contents: "write", "id-token": "write" }, "publish"), ...defaults, ...o.extra.githubEnv([...(dispatch ? [` CHANT_RELEASE_TRAIN: ${dispatchedTrain}`] : []), ...o.forgeToken]), " steps:", ...githubSetup(dispatch ? checkoutRef : undefined, o.fullSetup), ...installLines, ...o.extra.githubSteps, ...(o.goreleaser ?? []), ciFetch, ledgerFetch, run(trainFromRef), ...unpackSteps(false), run(`${o.chant} workspace train prepare ${env} "$CHANT_RELEASE_TRAIN"`), ...(o.build ? [run(o.build)] : []), ...(o.files
136
208
  ? dispatch
137
209
  ? [
138
210
  " - if: needs.cut.outputs.train != ''",
@@ -195,8 +267,62 @@ function renderGitlabTrainWorkflow(o) {
195
267
  "git checkout --detach FETCH_HEAD",
196
268
  ];
197
269
  const lines = [];
270
+ const builds = dispatch ? (o.builds ?? []) : [];
271
+ const archiveIn = (b) => `${b.memberDir === "." ? "" : `${b.memberDir}/`}${releaseBuildArchive(b.name)}`;
272
+ // #5237: GitLab hands each build's archive into the project directory, in its member; it is unpacked there and moved out, from the workspace root.
273
+ const unpack = (b, cut) => `if [ ${cut ? `-n "$${labelVariable(b)}"` : `-f ${sq(archiveIn(b))}`} ]; then ${unpackLine(sq(archiveIn(b)), cut)} -C ${sq(b.memberDir)}; mv ${sq(archiveIn(b))} /tmp/; fi`;
274
+ const buildJobs = builds.flatMap((b) => {
275
+ const install = b.install === false ? [] : b.install !== undefined ? [b.install] : o.install ? [o.install] : [];
276
+ const vars = Object.entries(b.env ?? {});
277
+ for (const [k] of vars)
278
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(k))
279
+ throw new Error(`release.workflow.builds.${b.name}.env: ${JSON.stringify(k)} is not a variable name`);
280
+ const tags = Array.isArray(b.runner) ? b.runner : [b.runner];
281
+ const cdMember = b.memberDir === "." ? [] : [`cd ${sq(b.memberDir)}`];
282
+ return [
283
+ `chant-release-build-${b.name}:`,
284
+ " rules:",
285
+ ` - if: ${cutRule}`,
286
+ ...variables(vars.map(([k, v]) => ` ${k}: ${JSON.stringify(v)}`)),
287
+ " needs: [chant-release-gate]",
288
+ ` tags: [${tags.map((t) => JSON.stringify(t)).join(", ")}]`,
289
+ " artifacts:",
290
+ " paths:",
291
+ ` - ${JSON.stringify(`${b.path === "." ? "" : `${b.path}/`}${releaseBuildArchive(b.name)}`)}`,
292
+ " expire_in: 1 day",
293
+ " script:",
294
+ ...[
295
+ `export CHANT_RELEASE_LABEL="$${labelVariable(b)}"`,
296
+ `if [ -z "$CHANT_RELEASE_LABEL" ]; then echo "${b.member} is not in this train, so build-${b.name} builds nothing"; exit 0; fi`,
297
+ 'git checkout --detach "$CHANT_RELEASE_COMMIT"',
298
+ ...cd,
299
+ // The workflow's install runs at the workspace root, a build's own in its member.
300
+ ...(b.install === undefined ? install : []),
301
+ ...cdMember,
302
+ ...(b.install !== undefined ? install : []),
303
+ b.build,
304
+ packLine(b),
305
+ ].map(q),
306
+ "",
307
+ ];
308
+ });
198
309
  if (dispatch) {
199
- lines.push("chant-release-gate:", " rules:", ` - if: ${cutRule}`, ...variables([]), " artifacts:", " reports:", " dotenv: chant-release-gate.env", " script:", ...[...cd, ...install, ciFetch, ...gateScript(o, "$CI_COMMIT_SHA"), 'printf \'CHANT_RELEASE_COMMIT=%s\\n\' "$commit" > "$CI_PROJECT_DIR/chant-release-gate.env"'].map(q), "", "chant-release-cut:", " rules:", ` - if: ${cutRule}`, ...variables(o.extra.gitlabVariables), " needs: [chant-release-gate]", " artifacts:", ...(o.files ? [" paths:", ' - ".chant-release-artifacts/"', " expire_in: 1 day"] : []), " reports:", " dotenv: chant-release-train.env", ...(o.doctor && o.signing ? [" id_tokens:", " SIGSTORE_ID_TOKEN:", " aud: sigstore"] : []), " script:", ...[
310
+ const plan = "/tmp/chant-train-plan.json";
311
+ lines.push("chant-release-gate:", " rules:", ` - if: ${cutRule}`, ...variables([]), " artifacts:", " reports:", " dotenv: chant-release-gate.env", " script:", ...[
312
+ ...cd,
313
+ ...install,
314
+ ciFetch,
315
+ ...gateScript(o, "$CI_COMMIT_SHA"),
316
+ 'printf \'CHANT_RELEASE_COMMIT=%s\\n\' "$commit" > "$CI_PROJECT_DIR/chant-release-gate.env"',
317
+ // #5237: the plan, so each build job builds with the label its member is cut at.
318
+ ...(builds.length > 0
319
+ ? [
320
+ planLine(o, plan),
321
+ `printf 'CHANT_TRAIN_PLANNED=%s\\n' "$(${field("d.planned")} ${plan})" >> "$CI_PROJECT_DIR/chant-release-gate.env"`,
322
+ ...builds.map((b) => `printf '${labelVariable(b)}=%s\\n' "$(${plannedLabel(b, plan)})" >> "$CI_PROJECT_DIR/chant-release-gate.env"`),
323
+ ]
324
+ : []),
325
+ ].map(q), "", ...buildJobs, "chant-release-cut:", " rules:", ` - if: ${cutRule}`, ...variables(o.extra.gitlabVariables), ` needs: [chant-release-gate${builds.map((b) => `, chant-release-build-${b.name}`).join("")}]`, " artifacts:", ...(o.files ? [" paths:", ' - ".chant-release-artifacts/"', " expire_in: 1 day"] : []), " reports:", " dotenv: chant-release-train.env", ...(o.doctor && o.signing ? [" id_tokens:", " SIGSTORE_ID_TOKEN:", " aud: sigstore"] : []), " script:", ...[
200
326
  'git checkout --detach "$CHANT_RELEASE_COMMIT"',
201
327
  ...cd,
202
328
  ...install,
@@ -205,9 +331,10 @@ function renderGitlabTrainWorkflow(o) {
205
331
  ciFetch,
206
332
  ...auth,
207
333
  LEDGER_FETCH_FIRST,
334
+ ...builds.map((b) => unpack(b, true)),
208
335
  'git config user.name "chant release"',
209
336
  'git config user.email "chant-release@localhost"',
210
- `${o.chant} workspace train cut ${env} --at "$CHANT_RELEASE_COMMIT" --levels "\${CHANT_RELEASE_LEVELS:-auto}"${o.doctor ? " --doctor" : ""} --yes --json > /tmp/chant-train.json`,
337
+ `${o.chant} workspace train cut ${env} --at "$CHANT_RELEASE_COMMIT" --levels "\${CHANT_RELEASE_LEVELS:-auto}"${builds.length > 0 ? ' --planned "$CHANT_TRAIN_PLANNED"' : ""}${o.doctor ? " --doctor" : ""} --yes --json > /tmp/chant-train.json`,
211
338
  `train="$(${trainIdScript("/tmp/chant-train.json", "gitlab")})" || exit 1`,
212
339
  'printf \'CHANT_TRAIN_CUT=%s\\n\' "$train" > "$CI_PROJECT_DIR/chant-release-train.env"',
213
340
  ...(o.files ? [`if [ -n "$train" ]; then ${o.chant} workspace train artifacts ${env} "$train" -o "${GITLAB_TRAIN_STAGE}"; fi`] : []),
@@ -224,6 +351,7 @@ function renderGitlabTrainWorkflow(o) {
224
351
  ciFetch,
225
352
  ledgerFetch,
226
353
  ...(dispatch ? auth : []),
354
+ ...(handed ? builds.map((b) => unpack(b, false)) : []),
227
355
  `${o.chant} workspace train prepare ${env} "$CHANT_RELEASE_TRAIN"`,
228
356
  ...(o.build ? [o.build] : []),
229
357
  ...(o.files ? [`${o.chant} workspace train artifacts ${env} "$CHANT_RELEASE_TRAIN"${handed ? ` --from ${GITLAB_TRAIN_FROM}` : ""}`] : []),
@@ -233,7 +361,7 @@ function renderGitlabTrainWorkflow(o) {
233
361
  `${o.chant} workspace train publish ${env} "$CHANT_RELEASE_TRAIN" ${o.flags}`,
234
362
  ];
235
363
  const publishRules = dispatch ? [` - if: $CHANT_RELEASE_TRAIN && ${manual}`, ` - if: ${cutRule}`] : [` - if: ${tagRule}`];
236
- const publishNeeds = dispatch ? [" needs:", " - job: chant-release-cut", " optional: true"] : [];
364
+ const publishNeeds = dispatch ? [" needs:", " - job: chant-release-cut", " optional: true", ...builds.flatMap((b) => [` - job: chant-release-build-${b.name}`, " optional: true"])] : [];
237
365
  lines.push("chant-release-publish:", " rules:", ...publishRules, ...variables(o.extra.gitlabVariables), ...publishNeeds, " resource_group: chant-release", " id_tokens:", " SIGSTORE_ID_TOKEN:", " aud: sigstore", ...(o.idTokens ?? []), " script:", ...publishScript(dispatch).map(q));
238
366
  if (o.after.length > 0) {
239
367
  lines.push("", "chant-release-after:", " rules:", ...publishRules, ...variables([]), ...(dispatch ? [" needs:", " - job: chant-release-cut", " optional: true", " - job: chant-release-publish"] : [" needs: [chant-release-publish]"]), " script:", ...[...trainLines, ...cd, ...install].map(q), ...o.after.map((l) => ` - ${l}`));
@@ -494,7 +494,7 @@ async function promoteAcrossRepos(query, train, now) {
494
494
  }
495
495
  return { kind: "ran", train, record, pending: null, approved: null, ledgerError };
496
496
  }
497
- const USAGE = "chant workspace train <env> [--pin <member>=<label|digest>]... [--dry-run] [--json] | chant workspace train list <env> [--json] | chant workspace train promote <env> [<train id|digest>] [--gate <name>] [--continue] [--dry-run] [--json] | chant workspace train cut <env> [--at <sha>] [--levels <levels>] [--doctor] [--yes] [--no-push] [--json] | chant workspace train prepare <env> [<train id|digest>] [--json] | chant workspace train artifacts <env> [<train id|digest>] [--from <dir>] [-o <dir>] [--no-build] [--json] | chant workspace train verify <env> [<train id|digest>] [--json] | chant workspace train publish <env> [<train id|digest>] [--yes] [--json]";
497
+ const USAGE = "chant workspace train <env> [--pin <member>=<label|digest>]... [--dry-run] [--json] | chant workspace train list <env> [--json] | chant workspace train promote <env> [<train id|digest>] [--gate <name>] [--continue] [--dry-run] [--json] | chant workspace train cut <env> [--at <sha>] [--levels <levels>] [--plan-only] [--planned <member=label ...|none>] [--doctor] [--yes] [--no-push] [--json] | chant workspace train prepare <env> [<train id|digest>] [--json] | chant workspace train artifacts <env> [<train id|digest>] [--from <dir>] [-o <dir>] [--no-build] [--json] | chant workspace train verify <env> [<train id|digest>] [--json] | chant workspace train publish <env> [<train id|digest>] [--yes] [--json]";
498
498
  /** Each train with the runs that promoted it, oldest first. */
499
499
  export function trainsWithPromotions(trains, runs) {
500
500
  const latest = latestRuns(runs);
@@ -57,6 +57,9 @@ export interface ReleasePipelineConfig {
57
57
  * hands its `outputs` to the cut and publish jobs, where they land at the
58
58
  * same paths in the checkout before `chant release cut` runs. `dispatch`
59
59
  * only: with the tag trigger the release was cut before the workflow ran.
60
+ * In a train (#5237) each member declares its own, in its directory, and
61
+ * the root's train workflow runs them with the label the gate plans for
62
+ * that member; the root itself declares none.
60
63
  */
61
64
  builds?: ReleaseBuildConfig[];
62
65
  /** Where the workflow is written, from the repository root, such as `.github/workflows/publish.yml` for an npm trusted publisher that names that file. Default {@link RELEASE_WORKFLOW_FILES}. */
@@ -182,6 +185,19 @@ export interface ReleaseWorkflowInput {
182
185
  goreleaser?: boolean;
183
186
  /** The directory, from the workspace root, of the member whose goreleaser build Go is set up for: its `go.mod` names the Go. */
184
187
  goreleaserDir?: string;
188
+ /**
189
+ * The members' `release.workflow.builds` (#5237): each a per-platform
190
+ * build job of the member at `dir` (from the workspace root), run with
191
+ * the label the gate's plan gives that member. `files` are the toolchain
192
+ * marker files in the member's directory, which a build with no
193
+ * `toolchains` sets up from.
194
+ */
195
+ builds?: Array<{
196
+ member: string;
197
+ dir: string;
198
+ files?: string[];
199
+ build: ReleaseBuildConfig;
200
+ }>;
185
201
  };
186
202
  }
187
203
  /** What the generator reads of a `release.publish` target: enough to know which credentials and tools its job needs. */
@@ -253,6 +269,16 @@ export interface JobExtras {
253
269
  export declare function jobPermissions(extra: Pick<JobExtras, "permissions">, base: Record<string, string>, job: "gate" | "cut" | "publish" | "after", indent?: string): string[];
254
270
  /** `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. */
255
271
  export declare function jobExtras(p: ReleasePipelineConfig, forge: ReleaseWorkflowForge): JobExtras;
272
+ /**
273
+ * A job that uploads a workflow artifact checks out without persisting the
274
+ * token in `.git/config` (#5268), where the upload could sweep it up, and
275
+ * these lines give its git the job's token instead: a credential helper for
276
+ * the forge's own host only, read from the job's environment, which no
277
+ * upload carries. The cut's fetches, the ledger push and the tag push use it.
278
+ */
279
+ export declare const GIT_TOKEN_ENV: string[];
280
+ /** The job's steps upload a workflow artifact (#5268). */
281
+ export declare const uploadsArtifact: (steps: readonly string[]) => boolean;
256
282
  /** The checkout and toolchain setup a GitHub or Forgejo job starts with (#5152); `ref` checks out that commit. */
257
283
  export declare function githubSetup(ref: string | undefined, setup: readonly string[], persist?: boolean): string[];
258
284
  interface DispatchInput {