@intentius/chant 0.124.74 → 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.
- package/dist/cli/handlers/release.d.ts +1 -1
- package/dist/cli/handlers/release.d.ts.map +1 -1
- package/dist/cli/handlers/release.js +13 -5
- package/dist/cli/main.js +1 -1
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +4 -0
- package/dist/cli/registry.d.ts +2 -0
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/wave-runtime.mjs +4 -4
- package/dist/workspace/release-workflow.d.ts +10 -0
- package/dist/workspace/release-workflow.d.ts.map +1 -1
- package/dist/workspace/release-workflow.js +35 -6
- package/package.json +1 -1
- package/src/cli/handlers/release.ts +12 -5
- package/src/cli/main.ts +1 -1
- package/src/cli/parse-args.ts +3 -0
- package/src/cli/registry.ts +2 -0
- package/src/workspace/release-workflow.test.ts +44 -0
- package/src/workspace/release-workflow.ts +48 -6
|
@@ -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,oBAAoB,EAAE,MAAM,CAKvE,CAAC;AAEF,yGAAyG;AACzG,MAAM,WAAW,qBAAqB;IACpC,8HAA8H;IAC9H,OAAO,CAAC,EAAE,KAAK,GAAG,UAAU,CAAC;IAC7B,iLAAiL;IACjL,IAAI,CAAC,EAAE,YAAY,GAAG,MAAM,CAAC;IAC7B,wEAAwE;IACxE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yJAAyJ;IACzJ,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IACvB,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8GAA8G;IAC9G,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC;IAC/C;;;;;OAKG;IACH,GAAG,CA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C,EAAE,OAAO,CAAC;IACjB;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,qDAAqD;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,+DAA+D;AAC/D,wBAAgB,YAAY,CAAC,MAAM,EAAE,WAAW,CAAC,aAAa,CAAC,GAAG,MAAM,EAAE,CAEzE;AAED,6FAA6F;AAC7F,eAAO,MAAM,oBAAoB,gCAAgC,CAAC;AAOlE,iEAAiE;AACjE,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,oBAAoB,GAAG,MAAM,CA+FzE;AAgFD,wEAAwE;AACxE,eAAO,MAAM,uBAAuB,yBAAyB,CAAC;AA6L9D,wFAAwF;AACxF,wBAAgB,qBAAqB,CAAC,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
|
|
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. */
|
|
@@ -253,6 +269,17 @@ function renderGithubDispatch(o) {
|
|
|
253
269
|
fetches[0],
|
|
254
270
|
` - run: ${LEDGER_FETCH_FIRST}`,
|
|
255
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
|
+
: []),
|
|
256
283
|
" publish:",
|
|
257
284
|
" needs: [gate, cut]",
|
|
258
285
|
" runs-on: ubuntu-latest",
|
|
@@ -263,7 +290,10 @@ function renderGithubDispatch(o) {
|
|
|
263
290
|
` - run: ${o.install}`,
|
|
264
291
|
...o.extra.githubSteps,
|
|
265
292
|
...fetches,
|
|
266
|
-
...(o.
|
|
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"`] : []),
|
|
267
297
|
...(o.build ? [` - run: ${o.build}`] : []),
|
|
268
298
|
...(o.verify ? [` - run: ${o.chant} release verify "$CHANT_RELEASE_LABEL"`] : []),
|
|
269
299
|
` - run: ${o.chant} release publish "$CHANT_RELEASE_LABEL" ${o.flags}`,
|
|
@@ -304,7 +334,7 @@ function renderGitlabDispatch(o) {
|
|
|
304
334
|
const lines = [
|
|
305
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"]),
|
|
306
336
|
"",
|
|
307
|
-
...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.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),
|
|
308
338
|
"",
|
|
309
339
|
...job("chant-release-publish", ["chant-release-gate", "chant-release-cut"], [
|
|
310
340
|
...checkout,
|
|
@@ -313,7 +343,7 @@ function renderGitlabDispatch(o) {
|
|
|
313
343
|
...o.extra.gitlabScript,
|
|
314
344
|
...fetches,
|
|
315
345
|
...auth,
|
|
316
|
-
...(o.images ? [
|
|
346
|
+
...(o.images ? [imagesLine(o), `export CHANT_RELEASE_DIGESTS="$PWD/${RELEASE_DIGESTS_FILE}"`] : []),
|
|
317
347
|
...(o.build ? [o.build] : []),
|
|
318
348
|
...(o.verify ? [`${o.chant} release verify "$CHANT_RELEASE_LABEL"`] : []),
|
|
319
349
|
`${o.chant} release publish "$CHANT_RELEASE_LABEL" ${o.flags}`,
|
|
@@ -372,8 +402,7 @@ export async function runReleaseWorkflow(ctx) {
|
|
|
372
402
|
groups,
|
|
373
403
|
workspaceRoot,
|
|
374
404
|
...(release?.workflow ? { pipeline: release.workflow } : {}),
|
|
375
|
-
|
|
376
|
-
...((release?.images?.length ?? 0) > 0 ? { images: true } : {}),
|
|
405
|
+
...((release?.images?.length ?? 0) > 0 ? { images: true, imageArchives: release.images.map((i) => i.archive) } : {}),
|
|
377
406
|
...(release?.lane ? { lane: release.lane } : {}),
|
|
378
407
|
...(args.ciInstall ? { install: args.ciInstall } : {}),
|
|
379
408
|
...(args.buildCommand ? { build: args.buildCommand } : {}),
|
package/package.json
CHANGED
|
@@ -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
|
|
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(
|
|
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
|
package/src/cli/parse-args.ts
CHANGED
|
@@ -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;
|
package/src/cli/registry.ts
CHANGED
|
@@ -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`. */
|
|
@@ -5,6 +5,7 @@ import { mkdtempSync, readFileSync } from "node:fs";
|
|
|
5
5
|
import { tmpdir } from "node:os";
|
|
6
6
|
import { join } from "node:path";
|
|
7
7
|
import { parseYAML } from "../yaml";
|
|
8
|
+
import { ACTION_PINS } from "../action-pins";
|
|
8
9
|
import { renderReleaseWorkflow, RELEASE_DIGESTS_FILE, type ReleaseWorkflowInput } from "./release-workflow";
|
|
9
10
|
import type { SecurityGroup } from "./security";
|
|
10
11
|
|
|
@@ -228,3 +229,46 @@ describe("a repository's first dispatched release (terragucci 0.4.50's cut)", ()
|
|
|
228
229
|
expect(sh(line, clone).status).not.toBe(0);
|
|
229
230
|
});
|
|
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
|
|
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}??""))'`;
|
|
@@ -369,6 +398,17 @@ function renderGithubDispatch(o: DispatchInput): string {
|
|
|
369
398
|
fetches[0]!,
|
|
370
399
|
` - run: ${LEDGER_FETCH_FIRST}`,
|
|
371
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
|
+
: []),
|
|
372
412
|
" publish:",
|
|
373
413
|
" needs: [gate, cut]",
|
|
374
414
|
" runs-on: ubuntu-latest",
|
|
@@ -379,7 +419,10 @@ function renderGithubDispatch(o: DispatchInput): string {
|
|
|
379
419
|
` - run: ${o.install}`,
|
|
380
420
|
...o.extra.githubSteps,
|
|
381
421
|
...fetches,
|
|
382
|
-
...(o.
|
|
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"`] : []),
|
|
383
426
|
...(o.build ? [` - run: ${o.build}`] : []),
|
|
384
427
|
...(o.verify ? [` - run: ${o.chant} release verify "$CHANT_RELEASE_LABEL"`] : []),
|
|
385
428
|
` - run: ${o.chant} release publish "$CHANT_RELEASE_LABEL" ${o.flags}`,
|
|
@@ -421,7 +464,7 @@ function renderGitlabDispatch(o: DispatchInput): string {
|
|
|
421
464
|
const lines = [
|
|
422
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"]),
|
|
423
466
|
"",
|
|
424
|
-
...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.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),
|
|
425
468
|
"",
|
|
426
469
|
...job(
|
|
427
470
|
"chant-release-publish",
|
|
@@ -433,7 +476,7 @@ function renderGitlabDispatch(o: DispatchInput): string {
|
|
|
433
476
|
...o.extra.gitlabScript,
|
|
434
477
|
...fetches,
|
|
435
478
|
...auth,
|
|
436
|
-
...(o.images ? [
|
|
479
|
+
...(o.images ? [imagesLine(o), `export CHANT_RELEASE_DIGESTS="$PWD/${RELEASE_DIGESTS_FILE}"`] : []),
|
|
437
480
|
...(o.build ? [o.build] : []),
|
|
438
481
|
...(o.verify ? [`${o.chant} release verify "$CHANT_RELEASE_LABEL"`] : []),
|
|
439
482
|
`${o.chant} release publish "$CHANT_RELEASE_LABEL" ${o.flags}`,
|
|
@@ -495,8 +538,7 @@ export async function runReleaseWorkflow(ctx: import("../cli/registry").CommandC
|
|
|
495
538
|
groups,
|
|
496
539
|
workspaceRoot,
|
|
497
540
|
...(release?.workflow ? { pipeline: release.workflow } : {}),
|
|
498
|
-
|
|
499
|
-
...(((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) } : {}),
|
|
500
542
|
...(release?.lane ? { lane: release.lane } : {}),
|
|
501
543
|
...(args.ciInstall ? { install: args.ciInstall } : {}),
|
|
502
544
|
...(args.buildCommand ? { build: args.buildCommand } : {}),
|