@intentius/chant 0.124.73 → 0.124.75

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.
@@ -58,6 +58,14 @@ export interface ReleaseWorkflowInput {
58
58
  pipeline?: ReleasePipelineConfig;
59
59
  /** The config declares `release.images` (#4657): the publish job builds them again first. */
60
60
  images?: boolean;
61
+ /**
62
+ * The archives `release.images` names, from the workspace root. In a
63
+ * dispatched release the cut job hands them to the publish job, which
64
+ * checks them against the recorded digests (`release images --no-build`)
65
+ * rather than building them again, so a moved package mirror between the
66
+ * two jobs cannot change what is published.
67
+ */
68
+ imageArchives?: string[];
61
69
  /** `release.lane` (#4692): the gate's green lane. */
62
70
  lane?: string;
63
71
  }
@@ -67,6 +75,8 @@ export declare function publishFlags(groups: ReadonlySet<SecurityGroup>): string
67
75
  export declare const RELEASE_DIGESTS_FILE = ".chant/release-digests.json";
68
76
  /** The workflow file's text, without the generated-by header. */
69
77
  export declare function renderReleaseWorkflow(input: ReleaseWorkflowInput): string;
78
+ /** The workflow artifact the cut job hands its image archives on in. */
79
+ export declare const RELEASE_IMAGES_ARTIFACT = "chant-release-images";
70
80
  /** The header that marks the file generated, naming the command that regenerates it. */
71
81
  export declare function releaseWorkflowHeader(command: string): string;
72
82
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"release-workflow.d.ts","sourceRoot":"","sources":["../../src/workspace/release-workflow.ts"],"names":[],"mappings":"AA+BA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,eAAO,MAAM,uBAAuB,YAAI,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAU,CAAC;AAChF,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE5E,uFAAuF;AACvF,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,oBA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OAAO,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,OAAO,iBAAiB,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CA4DvG"}
@@ -60,7 +60,8 @@ export function renderReleaseWorkflow(input) {
60
60
  const images = input.images === true;
61
61
  const extra = jobExtras(p, input.forge);
62
62
  if (p.trigger === "dispatch") {
63
- const o = { chant, install, build, root, verify, flags, after, images, extra, gate: p.gate ?? "last-green", ...(input.lane ? { lane: input.lane } : {}) };
63
+ const archives = images ? (input.imageArchives ?? []).map((a) => (root ? `${root}/${a.replace(/^\.\//, "")}` : a.replace(/^\.\//, ""))) : [];
64
+ const o = { chant, install, build, root, verify, flags, after, images, archives, forge: input.forge, extra, gate: p.gate ?? "last-green", ...(input.lane ? { lane: input.lane } : {}) };
64
65
  return input.forge === "gitlab" ? renderGitlabDispatch(o) : renderGithubDispatch(o);
65
66
  }
66
67
  // #4657: the images are built from the release, so chant/lifecycle is fetched before them and the build after.
@@ -177,6 +178,21 @@ function githubSetup(ref) {
177
178
  " registry-url: https://registry.npmjs.org",
178
179
  ];
179
180
  }
181
+ /** The workflow artifact the cut job hands its image archives on in. */
182
+ export const RELEASE_IMAGES_ARTIFACT = "chant-release-images";
183
+ /** The directory every path is under, which the artifact actions store the files relative to. */
184
+ function commonDir(paths) {
185
+ const dirs = paths.map((p) => p.split("/").slice(0, -1));
186
+ const first = dirs[0] ?? [];
187
+ let n = 0;
188
+ while (n < first.length && dirs.every((d) => d[n] === first[n]))
189
+ n++;
190
+ return first.slice(0, n).join("/") || ".";
191
+ }
192
+ /** The `release images` line of a publish job: checking the archives handed on, or building them again. */
193
+ function imagesLine(o) {
194
+ return `${o.chant} release images "$CHANT_RELEASE_LABEL"${o.archives.length > 0 ? " --no-build" : ""} -o ${RELEASE_DIGESTS_FILE}`;
195
+ }
180
196
  /** The node one-liner that prints a JSON document's field from stdin, or from the file its argument names. */
181
197
  const field = (path) => `node -e 'const f=process.argv[1];const t=f?require("fs").readFileSync(f,"utf8"):require("fs").readFileSync(0,"utf8");const d=JSON.parse(t);process.stdout.write(String(${path}??""))'`;
182
198
  /** The gate's shell: the commit to cut, from `ci last-green`, refused when there is none or, under `head`, when it is not the dispatched one. */
@@ -197,6 +213,13 @@ function cutScript(o, out) {
197
213
  'if [ -n "$tag" ]; then git push origin "refs/tags/$tag"; fi',
198
214
  ];
199
215
  }
216
+ /**
217
+ * The cut job's fetch of `chant/lifecycle`. A repository's first release has
218
+ * no ledger branch yet, and the cut is what creates it, so a remote without
219
+ * the branch is not an error here; any other failure of git still stops the
220
+ * job. The publish job runs after the cut has pushed it and fetches it plainly.
221
+ */
222
+ const LEDGER_FETCH_FIRST = 'rc=0; git ls-remote --exit-code --heads origin chant/lifecycle >/dev/null || rc=$?; if [ "$rc" = 0 ]; then git fetch origin chant/lifecycle:chant/lifecycle; elif [ "$rc" != 2 ]; then exit "$rc"; fi';
200
223
  /** GitHub and Forgejo: the release started by hand with a label (#4656). */
201
224
  function renderGithubDispatch(o) {
202
225
  const defaults = o.root ? [" defaults:", " run:", ` working-directory: ${o.root}`] : [];
@@ -243,8 +266,20 @@ function renderGithubDispatch(o) {
243
266
  ...githubSetup(commit),
244
267
  ` - run: ${o.install}`,
245
268
  ...o.extra.githubSteps,
246
- ...fetches,
269
+ fetches[0],
270
+ ` - run: ${LEDGER_FETCH_FIRST}`,
247
271
  ...block(cutScript(o, '"$RUNNER_TEMP/chant-cut.json"')),
272
+ ...(o.archives.length > 0
273
+ ? [
274
+ ` - uses: ${usesRef(o.forge === "forgejo" ? ACTION_PINS.uploadArtifact3 : ACTION_PINS.uploadArtifact4)}`,
275
+ " with:",
276
+ ` name: ${RELEASE_IMAGES_ARTIFACT}`,
277
+ " path: |",
278
+ ...o.archives.map((a) => ` ${a}`),
279
+ " if-no-files-found: error",
280
+ " retention-days: 1",
281
+ ]
282
+ : []),
248
283
  " publish:",
249
284
  " needs: [gate, cut]",
250
285
  " runs-on: ubuntu-latest",
@@ -255,7 +290,10 @@ function renderGithubDispatch(o) {
255
290
  ` - run: ${o.install}`,
256
291
  ...o.extra.githubSteps,
257
292
  ...fetches,
258
- ...(o.images ? [` - run: ${o.chant} release images "$CHANT_RELEASE_LABEL" -o ${RELEASE_DIGESTS_FILE}`, ` - run: echo "CHANT_RELEASE_DIGESTS=$PWD/${RELEASE_DIGESTS_FILE}" >> "$GITHUB_ENV"`] : []),
293
+ ...(o.archives.length > 0
294
+ ? [` - uses: ${usesRef(o.forge === "forgejo" ? ACTION_PINS.downloadArtifact3 : ACTION_PINS.downloadArtifact4)}`, " with:", ` name: ${RELEASE_IMAGES_ARTIFACT}`, ` path: ${commonDir(o.archives)}`]
295
+ : []),
296
+ ...(o.images ? [` - run: ${imagesLine(o)}`, ` - run: echo "CHANT_RELEASE_DIGESTS=$PWD/${RELEASE_DIGESTS_FILE}" >> "$GITHUB_ENV"`] : []),
259
297
  ...(o.build ? [` - run: ${o.build}`] : []),
260
298
  ...(o.verify ? [` - run: ${o.chant} release verify "$CHANT_RELEASE_LABEL"`] : []),
261
299
  ` - run: ${o.chant} release publish "$CHANT_RELEASE_LABEL" ${o.flags}`,
@@ -296,7 +334,7 @@ function renderGitlabDispatch(o) {
296
334
  const lines = [
297
335
  ...job("chant-release-gate", [], [...cd, o.install, fetches[0], ...gateScript(o, "$CI_COMMIT_SHA"), 'echo "CHANT_RELEASE_COMMIT=$commit" > "$CI_PROJECT_DIR/chant-release-gate.env"'], [" artifacts:", " reports:", " dotenv: chant-release-gate.env"]),
298
336
  "",
299
- ...job("chant-release-cut", ["chant-release-gate"], [...checkout, ...cd, o.install, ...o.extra.gitlabScript, ...fetches, ...auth, ...cutScript(o, "/tmp/chant-cut.json")], [], o.extra.gitlabVariables),
337
+ ...job("chant-release-cut", ["chant-release-gate"], [...checkout, ...cd, o.install, ...o.extra.gitlabScript, fetches[0], ...auth, LEDGER_FETCH_FIRST, ...cutScript(o, "/tmp/chant-cut.json")], o.archives.length > 0 ? [" artifacts:", " paths:", ...o.archives.map((a) => ` - ${JSON.stringify(a)}`), " expire_in: 1 day"] : [], o.extra.gitlabVariables),
300
338
  "",
301
339
  ...job("chant-release-publish", ["chant-release-gate", "chant-release-cut"], [
302
340
  ...checkout,
@@ -305,7 +343,7 @@ function renderGitlabDispatch(o) {
305
343
  ...o.extra.gitlabScript,
306
344
  ...fetches,
307
345
  ...auth,
308
- ...(o.images ? [`${o.chant} release images "$CHANT_RELEASE_LABEL" -o ${RELEASE_DIGESTS_FILE}`, `export CHANT_RELEASE_DIGESTS="$PWD/${RELEASE_DIGESTS_FILE}"`] : []),
346
+ ...(o.images ? [imagesLine(o), `export CHANT_RELEASE_DIGESTS="$PWD/${RELEASE_DIGESTS_FILE}"`] : []),
309
347
  ...(o.build ? [o.build] : []),
310
348
  ...(o.verify ? [`${o.chant} release verify "$CHANT_RELEASE_LABEL"`] : []),
311
349
  `${o.chant} release publish "$CHANT_RELEASE_LABEL" ${o.flags}`,
@@ -364,8 +402,7 @@ export async function runReleaseWorkflow(ctx) {
364
402
  groups,
365
403
  workspaceRoot,
366
404
  ...(release?.workflow ? { pipeline: release.workflow } : {}),
367
- // release.images (#4657) is read loosely, so this file renders with a config of either shape.
368
- ...((release?.images?.length ?? 0) > 0 ? { images: true } : {}),
405
+ ...((release?.images?.length ?? 0) > 0 ? { images: true, imageArchives: release.images.map((i) => i.archive) } : {}),
369
406
  ...(release?.lane ? { lane: release.lane } : {}),
370
407
  ...(args.ciInstall ? { install: args.ciInstall } : {}),
371
408
  ...(args.buildCommand ? { build: args.buildCommand } : {}),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intentius/chant",
3
- "version": "0.124.73",
3
+ "version": "0.124.75",
4
4
  "description": "Declarative infrastructure-as-code toolkit — TypeScript on Node.js",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://intentius.io/chant",
package/src/ci-commit.ts CHANGED
@@ -34,7 +34,6 @@ import { parseProductComment, type CiProductWords } from "./ci-product-words";
34
34
  import type { OpRunRecord, OpRunRecordInput } from "./op/runtime";
35
35
  import type { RunOrigin } from "./lifecycle/release-ledger";
36
36
  import type { PrForge } from "./pr-forge";
37
- import { NEXT_RELEASE } from "./release-floors";
38
37
 
39
38
  /** The first chant with the commit job and the scheduled Op spec's `commit` (#4722). Products feature-detect on it. */
40
39
  export const CI_COMMIT_FLOOR = "0.124.71";
@@ -42,7 +41,7 @@ export const CI_COMMIT_FLOOR = "0.124.71";
42
41
  /** The first chant with a commit job after a check that runs on push, `jobToken` and `after` (#4749). Products feature-detect on it. */
43
42
  export const CI_COMMIT_PUSH_FLOOR = "0.124.72";
44
43
  /** The first chant whose commit job takes `allowedFiles` (#4758). */
45
- export const CI_COMMIT_FILES_FLOOR = NEXT_RELEASE;
44
+ export const CI_COMMIT_FILES_FLOOR = "0.124.73";
46
45
 
47
46
  /** What starts a commit run: a person's comment, or a check job's finding. */
48
47
  export type CommitTrigger = "comment" | "check";
@@ -50,7 +50,7 @@ import { parseParamFlags } from "../build-params-cli";
50
50
  import type { CommandContext } from "../registry";
51
51
 
52
52
  const USAGE =
53
- "chant release cut [<label>] [--at <sha>] [--yes] [--build <command>] [--param <k=v>] [--image <component>=<repository>@sha256:<hex>] [--params-file <file>] [--src <dir>] [-o <file>] [--lexicon <name>] [--actor <name>] [--sign [<key file>]] [--channel <tag>] [--lane <name>] [--override-green] [--json] | release publish <label|digest> [--yes] [--allow-unsigned] [--require-provenance] [--json] | release verify <label|digest> [--json] | release images <label|digest> [-o <file>] [--json] | release candidates [--env <env>] [--lane <name>] [--forge-issues] [--json] | release compose <name> [--base <label|sha>] (--pr <n> | --work <id>)... [--yes] [--json] | release list [--json] | release export <label|digest> --env <env> [-o <dir>] [--json]";
53
+ "chant release cut [<label>] [--at <sha>] [--yes] [--build <command>] [--param <k=v>] [--image <component>=<repository>@sha256:<hex>] [--params-file <file>] [--src <dir>] [-o <file>] [--lexicon <name>] [--actor <name>] [--sign [<key file>]] [--channel <tag>] [--lane <name>] [--override-green] [--json] | release publish <label|digest> [--yes] [--allow-unsigned] [--require-provenance] [--json] | release verify <label|digest> [--json] | release images <label|digest> [--no-build] [-o <file>] [--json] | release candidates [--env <env>] [--lane <name>] [--forge-issues] [--json] | release compose <name> [--base <label|sha>] (--pr <n> | --work <id>)... [--yes] [--json] | release list [--json] | release export <label|digest> --env <env> [-o <dir>] [--json]";
54
54
 
55
55
  /** The build inputs `release cut` and `release compile` share. */
56
56
  function compileInputs(
@@ -126,7 +126,7 @@ function commitTime(cwd: string, commit: string): number {
126
126
  }
127
127
 
128
128
  /**
129
- * `release images <label|digest> [-o <file>] [--json]` (#4657): build the
129
+ * `release images <label|digest> [--no-build] [-o <file>] [--json]` (#4657): build the
130
130
  * images the release recorded again, from the release's commit checked out
131
131
  * here, refuse an archive whose digest is not the recorded one, and write the
132
132
  * recorded digests to the file the package build reads through
@@ -158,7 +158,14 @@ export async function runReleaseImages(ctx: CommandContext): Promise<number> {
158
158
  if (missing.length > 0) return fail("release-image-not-recorded", `release.images names ${missing.join(", ")}, which release ${release.releaseDigest} does not record`, "Cut a new release, so its cut builds every image the config declares.");
159
159
  let built: import("../../lifecycle/release-store").ReleaseArtifact[];
160
160
  try {
161
- built = buildReleaseImages({ images: declared, cwd, sourceDateEpoch: commitTime(cwd, release.commit), label, archiveDigest: ociArchiveDigest });
161
+ // --no-build: the archives the cut built were handed to this job, so they are read as they are.
162
+ built = args.noBuild
163
+ ? declared.map((d) => {
164
+ const abs = resolve(cwd, d.archive);
165
+ if (!existsSync(abs)) throw new ReleaseImageError("release-image-no-archive", `image "${d.name}" has no archive at ${d.archive}`, "Hand this job the archives the cut built, or run without --no-build to build them again.");
166
+ return { component: d.name, kind: "image" as const, path: d.archive, digest: ociArchiveDigest(abs) };
167
+ })
168
+ : buildReleaseImages({ images: declared, cwd, sourceDateEpoch: commitTime(cwd, release.commit), label, archiveDigest: ociArchiveDigest });
162
169
  } catch (err) {
163
170
  if (err instanceof ReleaseImageError) return fail(err.code, err.message, err.fix);
164
171
  throw err;
@@ -167,7 +174,7 @@ export async function runReleaseImages(ctx: CommandContext): Promise<number> {
167
174
  if (differ.length > 0) {
168
175
  return fail(
169
176
  "release-image-digest-mismatch",
170
- differ.map((a) => `image "${a.component}" built to ${a.digest}, and the release records ${recorded[a.component]}`).join("; "),
177
+ differ.map((a) => `image "${a.component}" ${args.noBuild ? "is" : "built to"} ${a.digest}, and the release records ${recorded[a.component]}`).join("; "),
171
178
  "An image build must write the same archive from the same commit: set SOURCE_DATE_EPOCH-aware timestamps (rewrite-timestamp=true), and remove logs and caches from its layers.",
172
179
  );
173
180
  }
@@ -176,7 +183,7 @@ export async function runReleaseImages(ctx: CommandContext): Promise<number> {
176
183
  if (args.json) console.log(JSON.stringify({ releaseDigest: release.releaseDigest, label, digests: recorded, file }, null, 2));
177
184
  else {
178
185
  for (const [name, digest] of Object.entries(recorded)) console.error(` ${name} ${digest}`);
179
- console.error(formatSuccess(`Built ${built.length} image(s) to the digests release ${label ?? release.releaseDigest} records, and wrote them to ${relative(cwd, file) || file}`));
186
+ console.error(formatSuccess(`${args.noBuild ? "Checked" : "Built"} ${built.length} image(s) to the digests release ${label ?? release.releaseDigest} records, and wrote them to ${relative(cwd, file) || file}`));
180
187
  console.log(`${RELEASE_DIGESTS_ENV}=${file}`);
181
188
  }
182
189
  return 0;
package/src/cli/main.ts CHANGED
@@ -526,7 +526,7 @@ Releases:
526
526
  release verify <label|digest> [--json]
527
527
  Check, offline, that the release was signed by a key
528
528
  .chant/allowed_signers lists at the release's commit.
529
- release images <label|digest> [-o <file>] [--json]
529
+ release images <label|digest> [--no-build] [-o <file>] [--json]
530
530
  Build the images release.images declares again from
531
531
  the release's commit, refuse one whose digest is not
532
532
  the recorded one, and write the recorded digests to
@@ -65,6 +65,7 @@ const BOOLEAN_FLAGS = new Set([
65
65
  "--fold",
66
66
  "--no-fold",
67
67
  "--no-cache",
68
+ "--no-build",
68
69
  "--sandbox",
69
70
  "--yes",
70
71
  "--confirm-prod",
@@ -1007,6 +1008,8 @@ export function parseArgs(args: string[]): ParsedArgs {
1007
1008
  result.noRecord = true;
1008
1009
  } else if (arg === "--fold") {
1009
1010
  result.fold = true;
1011
+ } else if (arg === "--no-build") {
1012
+ result.noBuild = true;
1010
1013
  } else if (arg === "--no-cache") {
1011
1014
  // `chant workspace graph --no-cache` (#2876): read every member.
1012
1015
  result.noCache = true;
@@ -593,6 +593,8 @@ export interface ParsedArgs {
593
593
  resource?: string;
594
594
  /** `chant workspace graph --no-cache` (#2876): read every member, bypassing the per-member cache. */
595
595
  noCache?: boolean;
596
+ /** `chant release images --no-build` (#4657): check the archives already on disk instead of building them. */
597
+ noBuild?: boolean;
596
598
  /** `chant workspace graph --composites` (#2662): print each composite instance with the components that can deploy it. */
597
599
  composites?: boolean;
598
600
  /** `chant workspace graph --intent <path[:start-end]|path#symbol|member/node|sha>` (#2651): the region the intent graph is over. Empty with `--record`. */
@@ -19,4 +19,4 @@
19
19
  * this constant to the next patch (#4501). The check fails while a floor
20
20
  * still names this constant after its version shipped.
21
21
  */
22
- export const NEXT_RELEASE = "0.124.73";
22
+ export const NEXT_RELEASE = "0.124.74";
@@ -1,8 +1,11 @@
1
1
  /** #4656: `chant release workflow` renders the release pipeline from the `release` block. */
2
2
  import { describe, expect, test } from "vitest";
3
- import { readFileSync } from "node:fs";
3
+ import { spawnSync } from "node:child_process";
4
+ import { mkdtempSync, readFileSync } from "node:fs";
5
+ import { tmpdir } from "node:os";
4
6
  import { join } from "node:path";
5
7
  import { parseYAML } from "../yaml";
8
+ import { ACTION_PINS } from "../action-pins";
6
9
  import { renderReleaseWorkflow, RELEASE_DIGESTS_FILE, type ReleaseWorkflowInput } from "./release-workflow";
7
10
  import type { SecurityGroup } from "./security";
8
11
 
@@ -197,3 +200,75 @@ describe("the release workflow's permissions, env and setup (#4751)", () => {
197
200
  expect(() => renderReleaseWorkflow({ forge: "github", groups: new Set(), pipeline: { env: { "BAD-NAME": "x" } } })).toThrow(/not a variable name/);
198
201
  });
199
202
  });
203
+
204
+ describe("a repository's first dispatched release (terragucci 0.4.50's cut)", () => {
205
+ const cutLedgerLine = (): string => {
206
+ const doc = parseYAML(renderReleaseWorkflow({ forge: "github", groups: new Set(), pipeline: { trigger: "dispatch" } })) as GhDoc;
207
+ const line = runs(doc.jobs.cut!).find((r) => r.includes("chant/lifecycle"));
208
+ expect(line).toBeDefined();
209
+ return line!;
210
+ };
211
+ const sh = (cmd: string, cwd: string) => spawnSync("bash", ["-c", cmd], { cwd, encoding: "utf8" });
212
+
213
+ test("the cut goes on when the remote has no chant/lifecycle yet, fetches it when it has one, and stops when the remote can't be read", () => {
214
+ const root = mkdtempSync(join(tmpdir(), "chant-first-ledger-"));
215
+ const origin = join(root, "origin.git");
216
+ const clone = join(root, "clone");
217
+ sh(`git init -q --bare -b main ${origin} && git clone -q ${origin} ${clone} && cd ${clone} && git -c user.name=t -c user.email=t@t commit -q --allow-empty -m init && git push -q origin main`, root);
218
+ const line = cutLedgerLine();
219
+
220
+ const first = sh(line, clone);
221
+ expect(first.status, first.stderr).toBe(0);
222
+ expect(sh("git rev-parse --verify -q refs/heads/chant/lifecycle", clone).status).not.toBe(0);
223
+
224
+ sh(`git push -q origin main:refs/heads/chant/lifecycle`, clone);
225
+ expect(sh(line, clone).status).toBe(0);
226
+ expect(sh("git rev-parse --verify -q refs/heads/chant/lifecycle", clone).status).toBe(0);
227
+
228
+ sh(`git remote set-url origin ${join(root, "gone.git")}`, clone);
229
+ expect(sh(line, clone).status).not.toBe(0);
230
+ });
231
+ });
232
+
233
+ describe("the cut hands its image archives to the publish job (#4657)", () => {
234
+ const archives = ["dist/images/tofu.tar", "dist/images/terraform.tar"];
235
+ type Step = { uses?: string; run?: string; with?: Record<string, unknown> };
236
+ const steps = (forge: "github" | "forgejo", root?: string) => {
237
+ const doc = parseYAML(renderReleaseWorkflow({ forge, groups: new Set(), images: true, imageArchives: archives, ...(root ? { workspaceRoot: root } : {}), pipeline: { trigger: "dispatch", build: "npm run build" } })) as { jobs: Record<string, { steps: Step[] }> };
238
+ return { cut: doc.jobs.cut!.steps, publish: doc.jobs.publish!.steps };
239
+ };
240
+
241
+ test("GitHub: the cut uploads the archives, the publish job downloads them and checks them without building", () => {
242
+ const { cut, publish } = steps("github");
243
+ const up = cut.at(-1)!;
244
+ expect(up.uses).toMatch(/^actions\/upload-artifact@/);
245
+ expect(up.with).toMatchObject({ name: "chant-release-images", "if-no-files-found": "error", "retention-days": 1 });
246
+ expect(String(up.with!.path).trim().split("\n")).toEqual(archives);
247
+ const down = publish.findIndex((s) => s.uses?.startsWith("actions/download-artifact@"));
248
+ const check = publish.findIndex((s) => s.run?.includes("release images"));
249
+ expect(down).toBeGreaterThan(-1);
250
+ expect(publish[down]!.with).toEqual({ name: "chant-release-images", path: "dist/images" });
251
+ expect(check).toBeGreaterThan(down);
252
+ expect(publish[check]!.run).toBe('npx chant release images "$CHANT_RELEASE_LABEL" --no-build -o .chant/release-digests.json');
253
+ });
254
+
255
+ test("Forgejo takes v3 of the artifact actions, and a workspace root prefixes the paths", () => {
256
+ const { cut, publish } = steps("forgejo", "packages/app");
257
+ expect(cut.at(-1)!.uses).toContain(ACTION_PINS.uploadArtifact3.sha);
258
+ expect(String(cut.at(-1)!.with!.path)).toContain("packages/app/dist/images/tofu.tar");
259
+ expect(publish.find((s) => s.uses?.includes("download-artifact"))!.uses).toContain(ACTION_PINS.downloadArtifact3.sha);
260
+ expect(publish.find((s) => s.uses?.includes("download-artifact"))!.with!.path).toBe("packages/app/dist/images");
261
+ });
262
+
263
+ test("GitLab: the cut keeps the archives as artifacts the publish job needs, and checks them without building", () => {
264
+ const doc = parseYAML(renderReleaseWorkflow({ forge: "gitlab", groups: new Set(), images: true, imageArchives: archives, pipeline: { trigger: "dispatch" } })) as Record<string, { artifacts?: unknown; script: string[] }>;
265
+ expect(doc["chant-release-cut"]!.artifacts).toEqual({ paths: archives, expire_in: "1 day" });
266
+ expect(doc["chant-release-publish"]!.script).toContain('npx chant release images "$CHANT_RELEASE_LABEL" --no-build -o .chant/release-digests.json');
267
+ });
268
+
269
+ test("without the archive paths the publish job builds the images again, as before", () => {
270
+ const doc = parseYAML(renderReleaseWorkflow({ forge: "github", groups: new Set(), images: true, pipeline: { trigger: "dispatch" } })) as { jobs: Record<string, { steps: Step[] }> };
271
+ expect(doc.jobs.publish!.steps.some((s) => s.uses?.includes("download-artifact"))).toBe(false);
272
+ expect(doc.jobs.publish!.steps.find((s) => s.run?.includes("release images"))!.run).not.toContain("--no-build");
273
+ });
274
+ });
@@ -98,6 +98,14 @@ export interface ReleaseWorkflowInput {
98
98
  pipeline?: ReleasePipelineConfig;
99
99
  /** The config declares `release.images` (#4657): the publish job builds them again first. */
100
100
  images?: boolean;
101
+ /**
102
+ * The archives `release.images` names, from the workspace root. In a
103
+ * dispatched release the cut job hands them to the publish job, which
104
+ * checks them against the recorded digests (`release images --no-build`)
105
+ * rather than building them again, so a moved package mirror between the
106
+ * two jobs cannot change what is published.
107
+ */
108
+ imageArchives?: string[];
101
109
  /** `release.lane` (#4692): the gate's green lane. */
102
110
  lane?: string;
103
111
  }
@@ -128,7 +136,8 @@ export function renderReleaseWorkflow(input: ReleaseWorkflowInput): string {
128
136
  const images = input.images === true;
129
137
  const extra = jobExtras(p, input.forge);
130
138
  if (p.trigger === "dispatch") {
131
- const o = { chant, install, build, root, verify, flags, after, images, extra, gate: p.gate ?? "last-green", ...(input.lane ? { lane: input.lane } : {}) };
139
+ const archives = images ? (input.imageArchives ?? []).map((a) => (root ? `${root}/${a.replace(/^\.\//, "")}` : a.replace(/^\.\//, ""))) : [];
140
+ const o = { chant, install, build, root, verify, flags, after, images, archives, forge: input.forge, extra, gate: p.gate ?? "last-green", ...(input.lane ? { lane: input.lane } : {}) };
132
141
  return input.forge === "gitlab" ? renderGitlabDispatch(o) : renderGithubDispatch(o);
133
142
  }
134
143
  // #4657: the images are built from the release, so chant/lifecycle is fetched before them and the build after.
@@ -282,11 +291,31 @@ interface DispatchInput {
282
291
  flags: string;
283
292
  after: string[];
284
293
  images: boolean;
294
+ /** The image archives the cut hands to the publish job, from the repository root. Empty: the publish job builds them again. */
295
+ archives: string[];
296
+ forge: ReleaseWorkflowForge;
285
297
  gate: "last-green" | "head";
286
298
  lane?: string;
287
299
  extra: JobExtras;
288
300
  }
289
301
 
302
+ /** The workflow artifact the cut job hands its image archives on in. */
303
+ export const RELEASE_IMAGES_ARTIFACT = "chant-release-images";
304
+
305
+ /** The directory every path is under, which the artifact actions store the files relative to. */
306
+ function commonDir(paths: readonly string[]): string {
307
+ const dirs = paths.map((p) => p.split("/").slice(0, -1));
308
+ const first = dirs[0] ?? [];
309
+ let n = 0;
310
+ while (n < first.length && dirs.every((d) => d[n] === first[n])) n++;
311
+ return first.slice(0, n).join("/") || ".";
312
+ }
313
+
314
+ /** The `release images` line of a publish job: checking the archives handed on, or building them again. */
315
+ function imagesLine(o: DispatchInput): string {
316
+ return `${o.chant} release images "$CHANT_RELEASE_LABEL"${o.archives.length > 0 ? " --no-build" : ""} -o ${RELEASE_DIGESTS_FILE}`;
317
+ }
318
+
290
319
  /** The node one-liner that prints a JSON document's field from stdin, or from the file its argument names. */
291
320
  const field = (path: string): string =>
292
321
  `node -e 'const f=process.argv[1];const t=f?require("fs").readFileSync(f,"utf8"):require("fs").readFileSync(0,"utf8");const d=JSON.parse(t);process.stdout.write(String(${path}??""))'`;
@@ -311,6 +340,15 @@ function cutScript(o: DispatchInput, out: string): string[] {
311
340
  ];
312
341
  }
313
342
 
343
+ /**
344
+ * The cut job's fetch of `chant/lifecycle`. A repository's first release has
345
+ * no ledger branch yet, and the cut is what creates it, so a remote without
346
+ * the branch is not an error here; any other failure of git still stops the
347
+ * job. The publish job runs after the cut has pushed it and fetches it plainly.
348
+ */
349
+ const LEDGER_FETCH_FIRST =
350
+ 'rc=0; git ls-remote --exit-code --heads origin chant/lifecycle >/dev/null || rc=$?; if [ "$rc" = 0 ]; then git fetch origin chant/lifecycle:chant/lifecycle; elif [ "$rc" != 2 ]; then exit "$rc"; fi';
351
+
314
352
  /** GitHub and Forgejo: the release started by hand with a label (#4656). */
315
353
  function renderGithubDispatch(o: DispatchInput): string {
316
354
  const defaults = o.root ? [" defaults:", " run:", ` working-directory: ${o.root}`] : [];
@@ -357,8 +395,20 @@ function renderGithubDispatch(o: DispatchInput): string {
357
395
  ...githubSetup(commit),
358
396
  ` - run: ${o.install}`,
359
397
  ...o.extra.githubSteps,
360
- ...fetches,
398
+ fetches[0]!,
399
+ ` - run: ${LEDGER_FETCH_FIRST}`,
361
400
  ...block(cutScript(o, '"$RUNNER_TEMP/chant-cut.json"')),
401
+ ...(o.archives.length > 0
402
+ ? [
403
+ ` - uses: ${usesRef(o.forge === "forgejo" ? ACTION_PINS.uploadArtifact3 : ACTION_PINS.uploadArtifact4)}`,
404
+ " with:",
405
+ ` name: ${RELEASE_IMAGES_ARTIFACT}`,
406
+ " path: |",
407
+ ...o.archives.map((a) => ` ${a}`),
408
+ " if-no-files-found: error",
409
+ " retention-days: 1",
410
+ ]
411
+ : []),
362
412
  " publish:",
363
413
  " needs: [gate, cut]",
364
414
  " runs-on: ubuntu-latest",
@@ -369,7 +419,10 @@ function renderGithubDispatch(o: DispatchInput): string {
369
419
  ` - run: ${o.install}`,
370
420
  ...o.extra.githubSteps,
371
421
  ...fetches,
372
- ...(o.images ? [` - run: ${o.chant} release images "$CHANT_RELEASE_LABEL" -o ${RELEASE_DIGESTS_FILE}`, ` - run: echo "CHANT_RELEASE_DIGESTS=$PWD/${RELEASE_DIGESTS_FILE}" >> "$GITHUB_ENV"`] : []),
422
+ ...(o.archives.length > 0
423
+ ? [` - uses: ${usesRef(o.forge === "forgejo" ? ACTION_PINS.downloadArtifact3 : ACTION_PINS.downloadArtifact4)}`, " with:", ` name: ${RELEASE_IMAGES_ARTIFACT}`, ` path: ${commonDir(o.archives)}`]
424
+ : []),
425
+ ...(o.images ? [` - run: ${imagesLine(o)}`, ` - run: echo "CHANT_RELEASE_DIGESTS=$PWD/${RELEASE_DIGESTS_FILE}" >> "$GITHUB_ENV"`] : []),
373
426
  ...(o.build ? [` - run: ${o.build}`] : []),
374
427
  ...(o.verify ? [` - run: ${o.chant} release verify "$CHANT_RELEASE_LABEL"`] : []),
375
428
  ` - run: ${o.chant} release publish "$CHANT_RELEASE_LABEL" ${o.flags}`,
@@ -411,7 +464,7 @@ function renderGitlabDispatch(o: DispatchInput): string {
411
464
  const lines = [
412
465
  ...job("chant-release-gate", [], [...cd, o.install, fetches[0]!, ...gateScript(o, "$CI_COMMIT_SHA"), 'echo "CHANT_RELEASE_COMMIT=$commit" > "$CI_PROJECT_DIR/chant-release-gate.env"'], [" artifacts:", " reports:", " dotenv: chant-release-gate.env"]),
413
466
  "",
414
- ...job("chant-release-cut", ["chant-release-gate"], [...checkout, ...cd, o.install, ...o.extra.gitlabScript, ...fetches, ...auth, ...cutScript(o, "/tmp/chant-cut.json")], [], o.extra.gitlabVariables),
467
+ ...job("chant-release-cut", ["chant-release-gate"], [...checkout, ...cd, o.install, ...o.extra.gitlabScript, fetches[0]!, ...auth, LEDGER_FETCH_FIRST, ...cutScript(o, "/tmp/chant-cut.json")], o.archives.length > 0 ? [" artifacts:", " paths:", ...o.archives.map((a) => ` - ${JSON.stringify(a)}`), " expire_in: 1 day"] : [], o.extra.gitlabVariables),
415
468
  "",
416
469
  ...job(
417
470
  "chant-release-publish",
@@ -423,7 +476,7 @@ function renderGitlabDispatch(o: DispatchInput): string {
423
476
  ...o.extra.gitlabScript,
424
477
  ...fetches,
425
478
  ...auth,
426
- ...(o.images ? [`${o.chant} release images "$CHANT_RELEASE_LABEL" -o ${RELEASE_DIGESTS_FILE}`, `export CHANT_RELEASE_DIGESTS="$PWD/${RELEASE_DIGESTS_FILE}"`] : []),
479
+ ...(o.images ? [imagesLine(o), `export CHANT_RELEASE_DIGESTS="$PWD/${RELEASE_DIGESTS_FILE}"`] : []),
427
480
  ...(o.build ? [o.build] : []),
428
481
  ...(o.verify ? [`${o.chant} release verify "$CHANT_RELEASE_LABEL"`] : []),
429
482
  `${o.chant} release publish "$CHANT_RELEASE_LABEL" ${o.flags}`,
@@ -485,8 +538,7 @@ export async function runReleaseWorkflow(ctx: import("../cli/registry").CommandC
485
538
  groups,
486
539
  workspaceRoot,
487
540
  ...(release?.workflow ? { pipeline: release.workflow } : {}),
488
- // release.images (#4657) is read loosely, so this file renders with a config of either shape.
489
- ...(((release as { images?: unknown[] } | undefined)?.images?.length ?? 0) > 0 ? { images: true } : {}),
541
+ ...((release?.images?.length ?? 0) > 0 ? { images: true, imageArchives: release!.images!.map((i) => i.archive) } : {}),
490
542
  ...(release?.lane ? { lane: release.lane } : {}),
491
543
  ...(args.ciInstall ? { install: args.ciInstall } : {}),
492
544
  ...(args.buildCommand ? { build: args.buildCommand } : {}),