@intentius/chant 0.124.102 → 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.
- package/dist/audit/secrets.d.ts +6 -0
- package/dist/audit/secrets.js +9 -2
- package/dist/cli/commands/import-index.d.ts +15 -0
- package/dist/cli/commands/import-index.js +37 -3
- package/dist/cli/commands/onboard.js +8 -8
- package/dist/cli/handlers/lifecycle.js +6 -0
- package/dist/cli/handlers/release-config.d.ts +15 -0
- package/dist/cli/handlers/release-config.js +58 -0
- package/dist/cli/handlers/release-init.js +3 -1
- package/dist/cli/handlers/release.js +36 -3
- package/dist/cli/main.js +24 -3
- package/dist/cli/parse-args.js +12 -0
- package/dist/cli/registry.d.ts +4 -0
- package/dist/cli/release-commands/cut.js +3 -0
- package/dist/cloud-lister/kubernetes-components.js +1 -2
- package/dist/config-import.js +26 -4
- package/dist/config.d.ts +14 -0
- package/dist/config.js +4 -0
- package/dist/floor-table.data.js +13 -11
- package/dist/floor-table.js +3 -1
- package/dist/graph-refs.d.ts +9 -0
- package/dist/graph-refs.js +9 -7
- package/dist/lifecycle/cloud-index.d.ts +6 -0
- package/dist/lifecycle/cloud-index.js +32 -5
- package/dist/lifecycle/identity-match.d.ts +18 -2
- package/dist/lifecycle/identity-match.js +10 -5
- package/dist/lifecycle/index-drift.d.ts +13 -0
- package/dist/lifecycle/index-drift.js +21 -3
- package/dist/lifecycle/index-import.d.ts +15 -0
- package/dist/lifecycle/index-import.js +25 -2
- package/dist/lifecycle/index-join.d.ts +1 -1
- package/dist/lifecycle/index-join.js +1 -1
- package/dist/lifecycle/publish-declaration.d.ts +6 -0
- package/dist/lifecycle/publish-declaration.js +19 -3
- package/dist/lifecycle/publish-forge.d.ts +2 -0
- package/dist/lifecycle/publish-forge.js +3 -1
- package/dist/lifecycle/publish-helm.js +1 -2
- package/dist/lifecycle/publish-maven.js +1 -2
- package/dist/lifecycle/publish-npm.js +1 -1
- package/dist/lifecycle/publish-nuget.js +1 -2
- package/dist/lifecycle/publish-oci.d.ts +27 -0
- package/dist/lifecycle/publish-oci.js +63 -8
- package/dist/lifecycle/publish-rubygems.js +1 -2
- package/dist/lifecycle/release-artifacts.js +1 -2
- package/dist/lifecycle/release-changelog.d.ts +18 -5
- package/dist/lifecycle/release-changelog.js +22 -10
- package/dist/lifecycle/release-cut.d.ts +13 -1
- package/dist/lifecycle/release-cut.js +3 -0
- package/dist/lifecycle/release-images.d.ts +32 -2
- package/dist/lifecycle/release-images.js +70 -2
- package/dist/lifecycle/release-init-goreleaser-images.d.ts +21 -0
- package/dist/lifecycle/release-init-goreleaser-images.js +160 -0
- package/dist/lifecycle/release-init.d.ts +22 -0
- package/dist/lifecycle/release-init.js +96 -16
- package/dist/local-chant.d.ts +3 -0
- package/dist/local-chant.js +28 -2
- package/dist/release-floors.d.ts +10 -6
- package/dist/release-floors.js +10 -6
- package/dist/ts-loader.d.ts +12 -3
- package/dist/ts-loader.js +27 -11
- package/dist/wave-runtime.mjs +291 -290
- package/dist/workspace/catalog-edges.d.ts +22 -0
- package/dist/workspace/catalog-edges.js +23 -0
- package/dist/workspace/release-steps/goreleaser.d.ts +6 -3
- package/dist/workspace/release-steps/goreleaser.js +12 -6
- package/dist/workspace/release-toolchains.d.ts +6 -0
- package/dist/workspace/release-toolchains.js +8 -0
- package/dist/workspace/release-train-workflow.d.ts +39 -3
- package/dist/workspace/release-train-workflow.js +258 -9
- package/dist/workspace/release-train.js +5 -1
- package/dist/workspace/release-workflow.d.ts +37 -0
- package/dist/workspace/release-workflow.js +97 -16
- package/dist/workspace/train-artifacts.d.ts +107 -0
- package/dist/workspace/train-artifacts.js +238 -0
- package/dist/workspace/train-cut.d.ts +34 -1
- package/dist/workspace/train-cut.js +98 -14
- package/dist/workspace/train-publish.d.ts +9 -0
- package/dist/workspace/train-publish.js +27 -1
- package/package.json +2 -2
|
@@ -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}. */
|
|
@@ -171,6 +174,30 @@ export interface ReleaseWorkflowInput {
|
|
|
171
174
|
*/
|
|
172
175
|
train?: {
|
|
173
176
|
env: string;
|
|
177
|
+
/**
|
|
178
|
+
* What the members declare (#5216): `release.images` (with the platforms
|
|
179
|
+
* they build, for QEMU), `release.artifacts`, and an artifact goreleaser
|
|
180
|
+
* builds. The jobs hand them from the cut to the publish.
|
|
181
|
+
*/
|
|
182
|
+
imagePlatforms?: string[];
|
|
183
|
+
images?: boolean;
|
|
184
|
+
artifacts?: boolean;
|
|
185
|
+
goreleaser?: boolean;
|
|
186
|
+
/** The directory, from the workspace root, of the member whose goreleaser build Go is set up for: its `go.mod` names the Go. */
|
|
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
|
+
}>;
|
|
174
201
|
};
|
|
175
202
|
}
|
|
176
203
|
/** What the generator reads of a `release.publish` target: enough to know which credentials and tools its job needs. */
|
|
@@ -242,6 +269,16 @@ export interface JobExtras {
|
|
|
242
269
|
export declare function jobPermissions(extra: Pick<JobExtras, "permissions">, base: Record<string, string>, job: "gate" | "cut" | "publish" | "after", indent?: string): string[];
|
|
243
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. */
|
|
244
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;
|
|
245
282
|
/** The checkout and toolchain setup a GitHub or Forgejo job starts with (#5152); `ref` checks out that commit. */
|
|
246
283
|
export declare function githubSetup(ref: string | undefined, setup: readonly string[], persist?: boolean): string[];
|
|
247
284
|
interface DispatchInput {
|
|
@@ -46,14 +46,15 @@
|
|
|
46
46
|
import { readFileSync } from "node:fs";
|
|
47
47
|
import { ACTION_PINS, tagComments, usesRef } from "../action-pins.js";
|
|
48
48
|
import { TOOL_PINS } from "../tool-pins.js";
|
|
49
|
-
import { releaseImagePlatforms, resolveReleaseImages } from "../lifecycle/release-images.js";
|
|
49
|
+
import { placeReleaseImages, releaseImagePlatforms, resolveReleaseImages } from "../lifecycle/release-images.js";
|
|
50
50
|
import { GENERATED_MARKER } from "../discovery/files.js";
|
|
51
51
|
import { tagShape } from "../lifecycle/release-tag.js";
|
|
52
|
-
import { checkBuilds, releaseBuildArchive, releaseBuildArtifact, resolveToolchains, toolchainLines } from "./release-toolchains.js";
|
|
52
|
+
import { buildJobToolchains, checkBuilds, releaseBuildArchive, releaseBuildArtifact, resolveToolchains, toolchainLines } from "./release-toolchains.js";
|
|
53
53
|
import { releaseJobSteps, releaseSetupSteps } from "./release-steps/index.js";
|
|
54
54
|
import { packLine } from "./release-steps/builds.js";
|
|
55
55
|
import { RELEASE_BINFMT_IMAGE, qemuArchitectures } from "./release-steps/qemu.js";
|
|
56
56
|
import { targetExtras } from "./release-steps/targets.js";
|
|
57
|
+
import { goreleaserSetup, setsUpGo } from "./release-steps/goreleaser.js";
|
|
57
58
|
import { renderTrainWorkflow } from "./release-train-workflow.js";
|
|
58
59
|
export const RELEASE_WORKFLOW_FORGES = ["github", "forgejo", "gitlab"];
|
|
59
60
|
/** Where each forge's publish workflow is written, relative to the repository root. */
|
|
@@ -95,7 +96,7 @@ export function renderReleaseWorkflow(input) {
|
|
|
95
96
|
throw new Error("release.workflow.toolchains: a GitLab job runs in its runner's image, which brings the toolchain; name the image in .gitlab-ci.yml (default: image:) and leave toolchains out");
|
|
96
97
|
}
|
|
97
98
|
const chantSetup = toolchainLines(resolveToolchains(p.toolchains === false ? false : (p.toolchains ?? []).filter((t) => (typeof t === "string" ? t : t.name) === "node"), new Set(), root, p.toolchains !== false));
|
|
98
|
-
const fullSetup = toolchainLines(
|
|
99
|
+
const fullSetup = toolchainLines(buildJobToolchains(p.toolchains, input.projectFiles, root));
|
|
99
100
|
const builds = p.builds ?? [];
|
|
100
101
|
if (builds.length > 0) {
|
|
101
102
|
if (p.trigger !== "dispatch")
|
|
@@ -143,12 +144,33 @@ export function renderReleaseWorkflow(input) {
|
|
|
143
144
|
: [];
|
|
144
145
|
// #5154: the root's members released as a train.
|
|
145
146
|
if (input.train) {
|
|
146
|
-
if (input.forge === "gitlab")
|
|
147
|
-
throw new Error("release.train: the train workflow renders for GitHub and Forgejo; on GitLab, run chant workspace train cut, prepare and publish from your own jobs");
|
|
148
147
|
if (builds.length > 0)
|
|
149
|
-
throw new Error("release.workflow.builds: a train
|
|
148
|
+
throw new Error("release.workflow.builds at the root: a train releases its members, not the root; declare each build in the release.workflow.builds of the member whose files it builds");
|
|
150
149
|
if (images || input.artifacts)
|
|
151
|
-
throw new Error("release.images and release.artifacts at the root: a train releases its members,
|
|
150
|
+
throw new Error("release.images and release.artifacts at the root: a train releases its members, not the root; declare them in the member that publishes them");
|
|
151
|
+
const t = input.train;
|
|
152
|
+
// #5237: the members' per-platform builds, each run with the label the gate's plan gives its member.
|
|
153
|
+
const memberBuilds = t.builds ?? [];
|
|
154
|
+
if (memberBuilds.length > 0) {
|
|
155
|
+
if (p.trigger !== "dispatch")
|
|
156
|
+
throw new Error('release.workflow.builds in a member: the tag trigger publishes a train cut before the workflow ran, so nothing built here would be in it; use trigger: "dispatch"');
|
|
157
|
+
try {
|
|
158
|
+
checkBuilds(memberBuilds.map((b) => b.build));
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
throw new Error(`${err instanceof Error ? err.message : String(err)} (a train runs every member's builds in one workflow, so each job name is used once across the members)`);
|
|
162
|
+
}
|
|
163
|
+
if (input.forge === "gitlab" && memberBuilds.some((b) => b.build.toolchains && b.build.toolchains.length > 0))
|
|
164
|
+
throw new Error("release.workflow.builds: toolchains: a GitLab job runs in its runner's image, which brings the toolchain; leave toolchains out");
|
|
165
|
+
}
|
|
166
|
+
const trainBuilds = memberBuilds.map((b) => {
|
|
167
|
+
const dir = [root, b.dir].filter((d) => !!d && d !== ".").join("/") || ".";
|
|
168
|
+
// The toolchains the build names, else those the member's files name, else the root's.
|
|
169
|
+
const own = (b.files ?? []).length > 0;
|
|
170
|
+
const setup = toolchainLines(resolveToolchains(b.build.toolchains !== undefined ? b.build.toolchains : p.toolchains === false ? false : own ? undefined : p.toolchains, own ? new Set(b.files) : files, own ? (dir === "." ? null : dir) : root, false));
|
|
171
|
+
return { ...b.build, member: b.member, memberDir: b.dir, path: dir, setup };
|
|
172
|
+
});
|
|
173
|
+
const trainContext = { forge: input.forge, shape: "dispatch", input: { ...input, imagePlatforms: t.imagePlatforms ?? [] }, pipeline: p, chant, root, verify: false, images: t.images === true, archives: [], artifacts: false, version: false, doctor: false, signing: input.signing === true, green, builds: [] };
|
|
152
174
|
return renderTrainWorkflow({
|
|
153
175
|
forge: input.forge,
|
|
154
176
|
env: input.train.env,
|
|
@@ -161,12 +183,20 @@ export function renderReleaseWorkflow(input) {
|
|
|
161
183
|
after,
|
|
162
184
|
chantSetup,
|
|
163
185
|
fullSetup,
|
|
164
|
-
extra: jobExtras({ ...p, ...(derived.permissions ? { permissions: { ...p.permissions, ...derived.permissions } } : {}), ...(derived.env ? { env: { ...p.env, ...derived.env } } : {}), setup: releaseSetupSteps(
|
|
186
|
+
extra: jobExtras({ ...p, ...(derived.permissions ? { permissions: { ...p.permissions, ...derived.permissions } } : {}), ...(derived.env ? { env: { ...p.env, ...derived.env } } : {}), setup: releaseSetupSteps(trainContext) }, input.forge),
|
|
165
187
|
forgeToken,
|
|
166
188
|
cutToken: green === "forge-checks" && p.env?.GITHUB_TOKEN === undefined ? [" GITHUB_TOKEN: ${{ github.token }}"] : [],
|
|
167
189
|
green,
|
|
168
190
|
gate: p.gate ?? "last-green",
|
|
169
191
|
...(input.lane ? { lane: input.lane } : {}),
|
|
192
|
+
// #5216: the members' images and files, from the cut to the publish; the doctor before the cut; verify before the publish.
|
|
193
|
+
files: t.images === true || t.artifacts === true,
|
|
194
|
+
...(t.artifacts && t.goreleaser ? { goreleaser: ((g) => (input.forge === "gitlab" ? g.gitlab : g.github))(goreleaserSetup(input.forge, [root, t.goreleaserDir].filter((d) => !!d && d !== ".").join("/") || null, p, setsUpGo(p, input.projectFiles, root))) } : {}),
|
|
195
|
+
...(input.signing ? { signing: true } : {}),
|
|
196
|
+
...(input.forge === "gitlab" ? { idTokens: stepLines(releaseJobSteps({ ...trainContext, job: "publish", label: '"$CHANT_RELEASE_TRAIN"' })("idTokens"), (l) => l) } : {}),
|
|
197
|
+
doctor: p.trigger === "dispatch" && p.doctor !== false,
|
|
198
|
+
verify: input.groups.has("verified-releases"),
|
|
199
|
+
...(trainBuilds.length > 0 ? { builds: trainBuilds } : {}),
|
|
170
200
|
});
|
|
171
201
|
}
|
|
172
202
|
if (shape === "dispatch") {
|
|
@@ -431,6 +461,21 @@ export function jobExtras(p, forge) {
|
|
|
431
461
|
gitlabScript: setup.flatMap((s) => ("uses" in s ? [] : [...Object.entries(s.env ?? {}).map(([k, v]) => `export ${k}=${q(v)}`), s.run])),
|
|
432
462
|
};
|
|
433
463
|
}
|
|
464
|
+
/**
|
|
465
|
+
* A job that uploads a workflow artifact checks out without persisting the
|
|
466
|
+
* token in `.git/config` (#5268), where the upload could sweep it up, and
|
|
467
|
+
* these lines give its git the job's token instead: a credential helper for
|
|
468
|
+
* the forge's own host only, read from the job's environment, which no
|
|
469
|
+
* upload carries. The cut's fetches, the ledger push and the tag push use it.
|
|
470
|
+
*/
|
|
471
|
+
export const GIT_TOKEN_ENV = [
|
|
472
|
+
" CHANT_RELEASE_GIT_TOKEN: ${{ github.token }}",
|
|
473
|
+
' GIT_CONFIG_COUNT: "1"',
|
|
474
|
+
" GIT_CONFIG_KEY_0: credential.${{ github.server_url }}.helper",
|
|
475
|
+
` GIT_CONFIG_VALUE_0: ${JSON.stringify('!f() { test "$1" = get && echo username=x-access-token && echo "password=$CHANT_RELEASE_GIT_TOKEN"; }; f')}`,
|
|
476
|
+
];
|
|
477
|
+
/** The job's steps upload a workflow artifact (#5268). */
|
|
478
|
+
export const uploadsArtifact = (steps) => steps.some((l) => /uses:\s*actions\/upload-artifact@/.test(l));
|
|
434
479
|
/** The checkout and toolchain setup a GitHub or Forgejo job starts with (#5152); `ref` checks out that commit. */
|
|
435
480
|
export function githubSetup(ref, setup, persist = true) {
|
|
436
481
|
return [
|
|
@@ -562,6 +607,8 @@ function renderGithubDispatch(o) {
|
|
|
562
607
|
const cutStep = (slot) => stepLines(cut(slot), run);
|
|
563
608
|
const publishStep = (slot) => stepLines(publish(slot), run);
|
|
564
609
|
const built = o.builds.map((b) => `build-${b.name}`);
|
|
610
|
+
// #5268: a cut that hands files on keeps no token in .git/config.
|
|
611
|
+
const cutUploads = uploadsArtifact(cutStep("afterCut"));
|
|
565
612
|
const lines = [
|
|
566
613
|
"name: chant release",
|
|
567
614
|
"on:",
|
|
@@ -599,9 +646,9 @@ function renderGithubDispatch(o) {
|
|
|
599
646
|
" runs-on: ubuntu-latest",
|
|
600
647
|
...jobPermissions(o.extra, { contents: "write", ...(o.context.signing && o.context.doctor ? { "id-token": "write" } : {}) }, "cut"),
|
|
601
648
|
...defaults,
|
|
602
|
-
...o.extra.githubEnv([` CHANT_RELEASE_COMMIT: ${commit}`, ` CHANT_RELEASE_LABEL: ${GATE_LABEL}`, ...cutEnvToken(o)]),
|
|
649
|
+
...o.extra.githubEnv([` CHANT_RELEASE_COMMIT: ${commit}`, ` CHANT_RELEASE_LABEL: ${GATE_LABEL}`, ...cutEnvToken(o), ...(cutUploads ? GIT_TOKEN_ENV : [])]),
|
|
603
650
|
" steps:",
|
|
604
|
-
...githubSetup(commit, o.fullSetup),
|
|
651
|
+
...githubSetup(commit, o.fullSetup, !cutUploads),
|
|
605
652
|
...installLines,
|
|
606
653
|
...o.extra.githubSteps,
|
|
607
654
|
...cutStep("prepare"),
|
|
@@ -800,6 +847,9 @@ export async function runReleaseWorkflow(ctx) {
|
|
|
800
847
|
}
|
|
801
848
|
// #5154: a train publishes its members' targets, so their credentials, tools and signing are the workflow's.
|
|
802
849
|
const memberReleases = [];
|
|
850
|
+
let goreleaserDir;
|
|
851
|
+
// #5237: the members' per-platform builds, each with its member.
|
|
852
|
+
const memberBuilds = [];
|
|
803
853
|
if (release?.train) {
|
|
804
854
|
const { locateWorkspace } = await import("./which-chant.js");
|
|
805
855
|
const { readDeclaration } = await import("./declaration.js");
|
|
@@ -810,18 +860,38 @@ export async function runReleaseWorkflow(ctx) {
|
|
|
810
860
|
const r = (await loadChantConfig(join(root, m.dir))).config.release;
|
|
811
861
|
if (r)
|
|
812
862
|
memberReleases.push(r);
|
|
863
|
+
if ((r?.workflow?.builds?.length ?? 0) > 0) {
|
|
864
|
+
const { TOOLCHAIN_MARKERS } = await import("./release-toolchains.js");
|
|
865
|
+
const files = TOOLCHAIN_MARKERS.filter((f) => existsSync(join(root, m.dir, f)));
|
|
866
|
+
for (const build of r.workflow.builds)
|
|
867
|
+
memberBuilds.push({ member: m.name, dir: m.dir.split(sep).join("/"), files, build });
|
|
868
|
+
}
|
|
869
|
+
if (r?.artifacts && goreleaserDir === undefined && (await import("../lifecycle/release-artifacts.js")).usesGoreleaser(r.artifacts))
|
|
870
|
+
goreleaserDir = m.dir.split(sep).join("/");
|
|
813
871
|
}
|
|
814
872
|
catch (err) {
|
|
815
873
|
console.error(formatError({ message: `member ${m.name}'s chant.config.ts could not be read: ${err instanceof Error ? err.message : String(err)}`, hint: usage }));
|
|
816
874
|
return 1;
|
|
817
875
|
}
|
|
818
876
|
}
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
877
|
+
// #5216: a member's files are built by its cut, in the train's cut job; #5237: or by the member's own release.workflow.builds, which builtBy names.
|
|
878
|
+
const { checkReleaseArtifacts, ReleaseArtifactError } = await import("../lifecycle/release-artifacts.js");
|
|
879
|
+
for (const r of memberReleases) {
|
|
880
|
+
if ((r.artifacts?.length ?? 0) === 0)
|
|
881
|
+
continue;
|
|
882
|
+
try {
|
|
883
|
+
checkReleaseArtifacts(r.artifacts, { builds: r.workflow?.builds ?? [] });
|
|
884
|
+
}
|
|
885
|
+
catch (err) {
|
|
886
|
+
if (!(err instanceof ReleaseArtifactError))
|
|
887
|
+
throw err;
|
|
888
|
+
console.error(formatError({ message: `release.train: a member's ${err.message} [${err.code}]`, hint: err.fix ?? "Fix release.artifacts in the member's chant.config.ts." }));
|
|
889
|
+
return 1;
|
|
890
|
+
}
|
|
823
891
|
}
|
|
824
892
|
}
|
|
893
|
+
const memberImages = memberReleases.flatMap((r) => r.images ?? []);
|
|
894
|
+
const memberArtifacts = memberReleases.flatMap((r) => r.artifacts ?? []);
|
|
825
895
|
const allTargets = [...(release?.publish ?? []), ...memberReleases.flatMap((r) => r.publish ?? [])];
|
|
826
896
|
const { resolveSigning } = await import("../lifecycle/publish-signing.js");
|
|
827
897
|
const signs = [release, ...memberReleases].some((r) => resolveSigning(r?.signing, groups).on && (r?.publish ?? []).some((t) => t.type === "oci" || t.type === "forge" || t.type === "pypi"));
|
|
@@ -854,7 +924,7 @@ export async function runReleaseWorkflow(ctx) {
|
|
|
854
924
|
workspaceRoot,
|
|
855
925
|
tags,
|
|
856
926
|
...(release?.workflow ? { pipeline: release.workflow } : {}),
|
|
857
|
-
...((release?.images?.length ?? 0) > 0 ? { images: true, imageArchives: resolveReleaseImages(release.images).map((i) => i.archive), imagePlatforms: releaseImagePlatforms(release.images) } : {}),
|
|
927
|
+
...((release?.images?.length ?? 0) > 0 ? { images: true, imageArchives: resolveReleaseImages(placeReleaseImages(release.images, release.artifacts ?? [])).map((i) => i.archive), imagePlatforms: releaseImagePlatforms(release.images) } : {}),
|
|
858
928
|
...((release?.artifacts?.length ?? 0) > 0 ? { artifacts: true, ...((await import("../lifecycle/release-artifacts.js")).usesGoreleaser(release.artifacts) ? { goreleaser: true } : {}), ...((await import("../lifecycle/release-artifacts.js")).usesNfpm(release.artifacts) ? { nfpm: true } : {}) } : {}),
|
|
859
929
|
...(release?.lane ? { lane: release.lane } : {}),
|
|
860
930
|
green: await (async () => {
|
|
@@ -873,7 +943,16 @@ export async function runReleaseWorkflow(ctx) {
|
|
|
873
943
|
...(release?.version ? { version: true } : {}),
|
|
874
944
|
...(signs ? { signing: true } : {}),
|
|
875
945
|
...(allTargets.length > 0 ? { publish: allTargets } : {}),
|
|
876
|
-
...(release?.train
|
|
946
|
+
...(release?.train
|
|
947
|
+
? {
|
|
948
|
+
train: {
|
|
949
|
+
env: release.train.env,
|
|
950
|
+
...(memberImages.length > 0 ? { images: true, imagePlatforms: releaseImagePlatforms(memberImages) } : {}),
|
|
951
|
+
...(memberArtifacts.length > 0 ? { artifacts: true, ...((await import("../lifecycle/release-artifacts.js")).usesGoreleaser(memberArtifacts) ? { goreleaser: true, ...(goreleaserDir ? { goreleaserDir } : {}) } : {}) } : {}),
|
|
952
|
+
...(memberBuilds.length > 0 ? { builds: memberBuilds } : {}),
|
|
953
|
+
},
|
|
954
|
+
}
|
|
955
|
+
: {}),
|
|
877
956
|
...(args.ciInstall ? { install: args.ciInstall } : {}),
|
|
878
957
|
...(args.buildCommand ? { build: args.buildCommand } : !hasBuildScript(root) && release?.workflow?.build === undefined ? { build: null } : {}),
|
|
879
958
|
...(args.ciChant ? { chant: args.ciChant } : {}),
|
|
@@ -931,5 +1010,7 @@ export async function runReleaseWorkflow(ctx) {
|
|
|
931
1010
|
console.log("The job that builds release.artifacts runs goreleaser with the Go of the job's image: give it an image with the Go your go.mod names.");
|
|
932
1011
|
if (forge === "gitlab" && release?.workflow?.trigger === "dispatch")
|
|
933
1012
|
console.log("The cut and publish jobs push with CHANT_RELEASE_TOKEN: a project access token with write_repository, as a masked CI/CD variable.");
|
|
1013
|
+
if (forge === "gitlab" && release?.train && release.workflow?.trigger === "dispatch")
|
|
1014
|
+
console.log(`Start a train by running a pipeline with CHANT_RELEASE_LEVELS=auto (or the levels), and publish a recorded one with CHANT_RELEASE_TRAIN=<id>. A release-train/${release.train.env}/* tag pushed from a workstation starts nothing in this file: publish it with CHANT_RELEASE_TRAIN.`);
|
|
934
1015
|
return 0;
|
|
935
1016
|
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The files a release train's members build at the cut, carried from the job
|
|
3
|
+
* that cut them to the job that publishes them (#5216), and the signature
|
|
4
|
+
* check of each member before the publish.
|
|
5
|
+
*
|
|
6
|
+
* `chant workspace train artifacts <env> [<train>] [--from <dir>] [-o <dir>]
|
|
7
|
+
* [--no-build] [--json]`, in a checkout of the train's commit: for each member
|
|
8
|
+
* the train cut from this commit that declares `release.images` or
|
|
9
|
+
* `release.artifacts`, the image archives and files the release records are
|
|
10
|
+
* checked against their recorded digests, as `chant release images` and
|
|
11
|
+
* `chant release artifacts` check one member's:
|
|
12
|
+
*
|
|
13
|
+
* - `--from <dir>` first copies each member's files from `<dir>/<member
|
|
14
|
+
* directory>/`, where an earlier job staged them;
|
|
15
|
+
* - a member whose files are all here is checked as they are; a member with
|
|
16
|
+
* one missing builds its images, or its files, again (`--no-build` refuses
|
|
17
|
+
* instead), and what it builds must have the recorded digests;
|
|
18
|
+
* - `-o <dir>` stages every member's checked files at `<dir>/<member
|
|
19
|
+
* directory>/<path>`, with `chant-train-artifacts.json` naming the members,
|
|
20
|
+
* for the next job's `--from`.
|
|
21
|
+
*
|
|
22
|
+
* `chant workspace train verify <env> [<train>] [--json]` runs `chant release
|
|
23
|
+
* verify` for each member the train cut from this commit, so a cut whose
|
|
24
|
+
* signature does not verify stops the publish (the `verified-releases`
|
|
25
|
+
* group).
|
|
26
|
+
*/
|
|
27
|
+
import { type ReadTrain } from "./release-train.js";
|
|
28
|
+
/** The first chant with `chant workspace train artifacts`, `train verify` and `train cut --doctor`, and a train publish that gives a member with images its digests in `CHANT_RELEASE_DIGESTS` (#5216): what the train workflow's cut and publish jobs run. */
|
|
29
|
+
export declare const TRAIN_ARTIFACTS_FLOOR = "0.124.103";
|
|
30
|
+
/** The file `-o` writes beside the staged files, naming the members staged. */
|
|
31
|
+
export declare const TRAIN_ARTIFACTS_INDEX = "chant-train-artifacts.json";
|
|
32
|
+
/** A member the train cut from this checkout's commit. */
|
|
33
|
+
export interface TrainMemberHere {
|
|
34
|
+
member: string;
|
|
35
|
+
/** The member's directory on disk. */
|
|
36
|
+
dir: string;
|
|
37
|
+
/** The member's directory from the workspace root, with `/`. */
|
|
38
|
+
rel: string;
|
|
39
|
+
/** The label, or the release digest for a release with none: what `chant release <command>` takes. */
|
|
40
|
+
ref: string;
|
|
41
|
+
releaseDigest: string;
|
|
42
|
+
}
|
|
43
|
+
/** The train, and its members cut from the commit checked out at the workspace root. */
|
|
44
|
+
export declare function trainMembersHere(cwd: string, env: string, ref?: string): Promise<{
|
|
45
|
+
root: string;
|
|
46
|
+
train: ReadTrain;
|
|
47
|
+
members: TrainMemberHere[];
|
|
48
|
+
}>;
|
|
49
|
+
/** Runs this chant with `args` in `cwd` and returns its exit code; its stdout goes to this process's stderr. */
|
|
50
|
+
export type MemberChant = (args: string[], cwd: string) => number;
|
|
51
|
+
/** The default {@link MemberChant}: this chant, its stdout on stderr so a `--json` caller's stdout stays one document. */
|
|
52
|
+
export declare const spawnMemberChant: MemberChant;
|
|
53
|
+
export interface TrainArtifactsQuery {
|
|
54
|
+
cwd: string;
|
|
55
|
+
env: string;
|
|
56
|
+
train?: string;
|
|
57
|
+
/** Copy each member's files from `<from>/<member directory>/` first. */
|
|
58
|
+
from?: string;
|
|
59
|
+
/** Stage each member's checked files at `<output>/<member directory>/`. */
|
|
60
|
+
output?: string;
|
|
61
|
+
/** Refuse a member with a file missing rather than build it again. */
|
|
62
|
+
noBuild?: boolean;
|
|
63
|
+
chant?: MemberChant;
|
|
64
|
+
say?: (line: string) => void;
|
|
65
|
+
}
|
|
66
|
+
/** One member's files, as checked. */
|
|
67
|
+
export interface TrainArtifactsMember {
|
|
68
|
+
member: string;
|
|
69
|
+
ref: string;
|
|
70
|
+
/** The image archives the release records, from the member's directory. */
|
|
71
|
+
images: string[];
|
|
72
|
+
/** The `release.artifacts` files the release records, from the member's directory. */
|
|
73
|
+
files: string[];
|
|
74
|
+
/** Whether the images, and the files, were built again here rather than checked as they were. */
|
|
75
|
+
built: {
|
|
76
|
+
images: boolean;
|
|
77
|
+
files: boolean;
|
|
78
|
+
};
|
|
79
|
+
/** How many of the paths `--from` copied. */
|
|
80
|
+
copied: number;
|
|
81
|
+
}
|
|
82
|
+
export interface TrainArtifactsOutcome {
|
|
83
|
+
train: ReadTrain;
|
|
84
|
+
members: TrainArtifactsMember[];
|
|
85
|
+
staged: string | null;
|
|
86
|
+
}
|
|
87
|
+
/** Check, build again where missing, and stage the images and files of every member the train cut here (#5216). */
|
|
88
|
+
export declare function trainArtifacts(q: TrainArtifactsQuery): Promise<TrainArtifactsOutcome>;
|
|
89
|
+
/** Run `chant release verify` for each member the train cut here (#5216); every failure is reported before the exit. */
|
|
90
|
+
export declare function trainVerify(q: {
|
|
91
|
+
cwd: string;
|
|
92
|
+
env: string;
|
|
93
|
+
train?: string;
|
|
94
|
+
chant?: MemberChant;
|
|
95
|
+
say?: (line: string) => void;
|
|
96
|
+
}): Promise<{
|
|
97
|
+
train: ReadTrain;
|
|
98
|
+
members: Array<{
|
|
99
|
+
member: string;
|
|
100
|
+
ref: string;
|
|
101
|
+
ok: boolean;
|
|
102
|
+
}>;
|
|
103
|
+
}>;
|
|
104
|
+
/** `chant workspace train artifacts <env> [<train>]` (#5216). */
|
|
105
|
+
export declare function runTrainArtifacts(ctx: import("../cli/registry.js").CommandContext, words: string[]): Promise<number>;
|
|
106
|
+
/** `chant workspace train verify <env> [<train>]` (#5216). */
|
|
107
|
+
export declare function runTrainVerify(ctx: import("../cli/registry.js").CommandContext, words: string[]): Promise<number>;
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The files a release train's members build at the cut, carried from the job
|
|
3
|
+
* that cut them to the job that publishes them (#5216), and the signature
|
|
4
|
+
* check of each member before the publish.
|
|
5
|
+
*
|
|
6
|
+
* `chant workspace train artifacts <env> [<train>] [--from <dir>] [-o <dir>]
|
|
7
|
+
* [--no-build] [--json]`, in a checkout of the train's commit: for each member
|
|
8
|
+
* the train cut from this commit that declares `release.images` or
|
|
9
|
+
* `release.artifacts`, the image archives and files the release records are
|
|
10
|
+
* checked against their recorded digests, as `chant release images` and
|
|
11
|
+
* `chant release artifacts` check one member's:
|
|
12
|
+
*
|
|
13
|
+
* - `--from <dir>` first copies each member's files from `<dir>/<member
|
|
14
|
+
* directory>/`, where an earlier job staged them;
|
|
15
|
+
* - a member whose files are all here is checked as they are; a member with
|
|
16
|
+
* one missing builds its images, or its files, again (`--no-build` refuses
|
|
17
|
+
* instead), and what it builds must have the recorded digests;
|
|
18
|
+
* - `-o <dir>` stages every member's checked files at `<dir>/<member
|
|
19
|
+
* directory>/<path>`, with `chant-train-artifacts.json` naming the members,
|
|
20
|
+
* for the next job's `--from`.
|
|
21
|
+
*
|
|
22
|
+
* `chant workspace train verify <env> [<train>] [--json]` runs `chant release
|
|
23
|
+
* verify` for each member the train cut from this commit, so a cut whose
|
|
24
|
+
* signature does not verify stops the publish (the `verified-releases`
|
|
25
|
+
* group).
|
|
26
|
+
*/
|
|
27
|
+
import { spawnSync } from "node:child_process";
|
|
28
|
+
import { cpSync, existsSync, mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
|
|
29
|
+
import { tmpdir } from "node:os";
|
|
30
|
+
import { join, relative, resolve, sep } from "node:path";
|
|
31
|
+
import { readDeclaration } from "./declaration.js";
|
|
32
|
+
import { findTrain, readReleaseTrains } from "./release-train.js";
|
|
33
|
+
import { ownChant, TrainCutError } from "./train-cut.js";
|
|
34
|
+
import { locateWorkspace } from "./which-chant.js";
|
|
35
|
+
/** The first chant with `chant workspace train artifacts`, `train verify` and `train cut --doctor`, and a train publish that gives a member with images its digests in `CHANT_RELEASE_DIGESTS` (#5216): what the train workflow's cut and publish jobs run. */
|
|
36
|
+
export const TRAIN_ARTIFACTS_FLOOR = "0.124.103";
|
|
37
|
+
/** The file `-o` writes beside the staged files, naming the members staged. */
|
|
38
|
+
export const TRAIN_ARTIFACTS_INDEX = "chant-train-artifacts.json";
|
|
39
|
+
/** The train, and its members cut from the commit checked out at the workspace root. */
|
|
40
|
+
export async function trainMembersHere(cwd, env, ref) {
|
|
41
|
+
const located = locateWorkspace(cwd);
|
|
42
|
+
const root = located.rootOnDisk;
|
|
43
|
+
const train = findTrain((await readReleaseTrains(root, env)).records, ref);
|
|
44
|
+
if (!train)
|
|
45
|
+
throw new TrainCutError("train-unknown", ref ? `no release train ${ref} is recorded for ${env}` : `no release train is recorded for ${env}`, `List them with chant workspace train list ${env}.`);
|
|
46
|
+
let head;
|
|
47
|
+
try {
|
|
48
|
+
head = spawnSync("git", ["rev-parse", "HEAD"], { cwd: root, encoding: "utf-8" }).stdout.trim();
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
head = "";
|
|
52
|
+
}
|
|
53
|
+
if (!head)
|
|
54
|
+
throw new TrainCutError("not-a-git-repository", "a train's files are checked in a checkout of its commit, and this directory is not in a git repository");
|
|
55
|
+
const dirs = new Map(readDeclaration(located.tree, "", { rootChant: true }).members.map((m) => [m.name, m.dir]));
|
|
56
|
+
const members = [];
|
|
57
|
+
for (const m of train.members.filter((x) => x.commit === head)) {
|
|
58
|
+
const rel = dirs.get(m.member);
|
|
59
|
+
if (rel === undefined)
|
|
60
|
+
throw new TrainCutError("train-member-unknown", `release train ${train.id} pins ${m.member}, which the declaration does not list`);
|
|
61
|
+
members.push({ member: m.member, dir: resolve(root, rel), rel: rel.split(sep).join("/"), ref: m.label ?? m.releaseDigest, releaseDigest: m.releaseDigest });
|
|
62
|
+
}
|
|
63
|
+
if (members.length === 0)
|
|
64
|
+
throw new TrainCutError("train-nothing-cut-here", `release train ${train.id} has no release cut from this checkout's commit ${head.slice(0, 12)}`, "Check out the commit the train's release-train tag names.");
|
|
65
|
+
return { root, train, members };
|
|
66
|
+
}
|
|
67
|
+
/** The default {@link MemberChant}: this chant, its stdout on stderr so a `--json` caller's stdout stays one document. */
|
|
68
|
+
export const spawnMemberChant = (args, cwd) => {
|
|
69
|
+
const [bin, ...pre] = ownChant();
|
|
70
|
+
const r = spawnSync(bin, [...pre, ...args], { cwd, stdio: ["ignore", 2, 2] });
|
|
71
|
+
return r.status ?? 1;
|
|
72
|
+
};
|
|
73
|
+
/** Check, build again where missing, and stage the images and files of every member the train cut here (#5216). */
|
|
74
|
+
export async function trainArtifacts(q) {
|
|
75
|
+
const { train, members } = await trainMembersHere(q.cwd, q.env, q.train);
|
|
76
|
+
const { loadChantConfig } = await import("../config.js");
|
|
77
|
+
const { resolveRelease } = await import("../lifecycle/release-store.js");
|
|
78
|
+
const { releaseArtifactFiles } = await import("../lifecycle/release-artifacts.js");
|
|
79
|
+
const { placeReleaseImages, resolveReleaseImages } = await import("../lifecycle/release-images.js");
|
|
80
|
+
const chant = q.chant ?? spawnMemberChant;
|
|
81
|
+
const say = q.say ?? (() => undefined);
|
|
82
|
+
const out = [];
|
|
83
|
+
const scratch = mkdtempSync(join(tmpdir(), "chant-train-artifacts-"));
|
|
84
|
+
for (const m of members) {
|
|
85
|
+
const release = (await loadChantConfig(m.dir)).config.release;
|
|
86
|
+
const declaredImages = release?.images ?? [];
|
|
87
|
+
const declaredFiles = release?.artifacts ?? [];
|
|
88
|
+
if (declaredImages.length === 0 && declaredFiles.length === 0)
|
|
89
|
+
continue;
|
|
90
|
+
const found = await resolveRelease(m.releaseDigest, { cwd: m.dir });
|
|
91
|
+
if (!found)
|
|
92
|
+
throw new TrainCutError("release-not-found", `${m.member}: the train pins release ${m.releaseDigest}, which no cut in the member names`, `Fetch chant/lifecycle (git fetch origin chant/lifecycle:chant/lifecycle) in the train's checkout.`);
|
|
93
|
+
const images = resolveReleaseImages(placeReleaseImages(declaredImages, declaredFiles)).map((i) => i.archive.replace(/^\.\//, ""));
|
|
94
|
+
const files = releaseArtifactFiles(found.release, declaredFiles.map((d) => d.name)).map((f) => f.path);
|
|
95
|
+
let copied = 0;
|
|
96
|
+
if (q.from !== undefined) {
|
|
97
|
+
for (const p of [...images, ...files]) {
|
|
98
|
+
const src = resolve(q.from, m.rel, p);
|
|
99
|
+
if (!existsSync(src))
|
|
100
|
+
continue;
|
|
101
|
+
const dest = resolve(m.dir, p);
|
|
102
|
+
mkdirSync(resolve(dest, ".."), { recursive: true });
|
|
103
|
+
cpSync(src, dest, { recursive: true, force: true });
|
|
104
|
+
copied++;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const here = (paths) => paths.length > 0 && paths.every((p) => existsSync(resolve(m.dir, p)));
|
|
108
|
+
const built = { images: false, files: false };
|
|
109
|
+
const step = (what, paths) => {
|
|
110
|
+
const present = here(paths);
|
|
111
|
+
if (!present && q.noBuild) {
|
|
112
|
+
const absent = paths.filter((p) => !existsSync(resolve(m.dir, p)));
|
|
113
|
+
throw new TrainCutError("train-artifact-missing", `${m.member} ${m.ref}: ${absent.length > 0 ? absent.join(", ") : `its release.${what}`} ${absent.length === 1 ? "is" : "are"} not here`, "Hand this job the files the cut staged (--from <dir>), or run without --no-build to build them again.");
|
|
114
|
+
}
|
|
115
|
+
if (!present)
|
|
116
|
+
built[what === "images" ? "images" : "files"] = true;
|
|
117
|
+
const args = what === "images" ? ["release", "images", m.ref, ...(present ? ["--no-build"] : []), "-o", join(scratch, `${m.member}-digests.json`)] : ["release", "artifacts", m.ref, ...(present ? ["--no-build"] : [])];
|
|
118
|
+
say(`${m.member} ${m.ref}: ${present ? "check" : "build again and check"} its ${what === "images" ? `image archive(s) ${paths.join(", ")}` : `file(s)${paths.length > 0 ? ` ${paths.join(", ")}` : ""}`}`);
|
|
119
|
+
const code = chant(args, m.dir);
|
|
120
|
+
if (code !== 0)
|
|
121
|
+
throw new TrainCutError(`train-${what === "images" ? "image" : "artifact"}-check-failed`, `${m.member} ${m.ref}: chant ${args.slice(0, 3).join(" ")}${present ? " --no-build" : ""} failed (exit ${code})`, "Its output above says which file differs from the release. Publish the files the cut built, or cut a new train.");
|
|
122
|
+
};
|
|
123
|
+
if (declaredImages.length > 0)
|
|
124
|
+
step("images", images);
|
|
125
|
+
if (declaredFiles.length > 0)
|
|
126
|
+
step("artifacts", files);
|
|
127
|
+
if (q.output !== undefined) {
|
|
128
|
+
for (const p of [...images, ...files]) {
|
|
129
|
+
const dest = resolve(q.output, m.rel, p);
|
|
130
|
+
mkdirSync(resolve(dest, ".."), { recursive: true });
|
|
131
|
+
cpSync(resolve(m.dir, p), dest, { recursive: true, force: true });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
out.push({ member: m.member, ref: m.ref, images, files, built, copied });
|
|
135
|
+
}
|
|
136
|
+
let staged = null;
|
|
137
|
+
if (q.output !== undefined) {
|
|
138
|
+
staged = resolve(q.output);
|
|
139
|
+
mkdirSync(staged, { recursive: true });
|
|
140
|
+
// Always written, so the next job finds a staged directory even when no member of this train builds files.
|
|
141
|
+
writeFileSync(join(staged, TRAIN_ARTIFACTS_INDEX), `${JSON.stringify({ train: train.id, members: out.map((m) => ({ member: m.member, ref: m.ref, images: m.images, files: m.files })) }, null, 2)}\n`);
|
|
142
|
+
}
|
|
143
|
+
return { train, members: out, staged };
|
|
144
|
+
}
|
|
145
|
+
/** Run `chant release verify` for each member the train cut here (#5216); every failure is reported before the exit. */
|
|
146
|
+
export async function trainVerify(q) {
|
|
147
|
+
const { train, members } = await trainMembersHere(q.cwd, q.env, q.train);
|
|
148
|
+
const chant = q.chant ?? spawnMemberChant;
|
|
149
|
+
const say = q.say ?? (() => undefined);
|
|
150
|
+
const out = members.map((m) => {
|
|
151
|
+
say(`${m.member} ${m.ref}: chant release verify ${m.ref}`);
|
|
152
|
+
return { member: m.member, ref: m.ref, ok: chant(["release", "verify", m.ref], m.dir) === 0 };
|
|
153
|
+
});
|
|
154
|
+
const failed = out.filter((m) => !m.ok);
|
|
155
|
+
if (failed.length > 0) {
|
|
156
|
+
throw new TrainCutError("train-verify-failed", `release verify failed for ${failed.map((m) => `${m.member} ${m.ref}`).join(", ")}, so nothing of train ${train.id} is published`, "Its output above says why. A cut whose signature does not verify is cut again by a signer .chant/allowed_signers lists.");
|
|
157
|
+
}
|
|
158
|
+
return { train, members: out };
|
|
159
|
+
}
|
|
160
|
+
const ARTIFACTS_USAGE = "chant workspace train artifacts <env> [<train id|digest>] [--from <dir>] [-o <dir>] [--no-build] [--json]";
|
|
161
|
+
const VERIFY_USAGE = "chant workspace train verify <env> [<train id|digest>] [--json]";
|
|
162
|
+
async function report(err, json, usage) {
|
|
163
|
+
const { formatError } = await import("../cli/format.js");
|
|
164
|
+
const { WorkspaceReadError } = await import("./declaration.js");
|
|
165
|
+
if (err instanceof TrainCutError) {
|
|
166
|
+
if (json)
|
|
167
|
+
console.log(JSON.stringify({ status: "refused", code: err.code, message: err.message }, null, 2));
|
|
168
|
+
console.error(formatError({ message: `${err.message} [${err.code}]`, hint: err.fix ?? usage }));
|
|
169
|
+
return 1;
|
|
170
|
+
}
|
|
171
|
+
if (err instanceof WorkspaceReadError) {
|
|
172
|
+
console.error(formatError({ message: `${err.code}: ${err.describe()}`, hint: usage }));
|
|
173
|
+
return 1;
|
|
174
|
+
}
|
|
175
|
+
throw err;
|
|
176
|
+
}
|
|
177
|
+
/** `chant workspace train artifacts <env> [<train>]` (#5216). */
|
|
178
|
+
export async function runTrainArtifacts(ctx, words) {
|
|
179
|
+
const { formatError, formatSuccess } = await import("../cli/format.js");
|
|
180
|
+
const [env, ref] = words;
|
|
181
|
+
if (!env || words.length > 2) {
|
|
182
|
+
console.error(formatError({ message: env ? `chant workspace train artifacts takes an environment and a train, not ${words.join(" ")}` : "chant workspace train artifacts needs an environment", hint: ARTIFACTS_USAGE }));
|
|
183
|
+
return 1;
|
|
184
|
+
}
|
|
185
|
+
const json = ctx.args.json === true;
|
|
186
|
+
const cwd = resolve(".");
|
|
187
|
+
const { fetchLifecycle } = await import("../lifecycle/git.js");
|
|
188
|
+
await fetchLifecycle({ cwd }).catch(() => false);
|
|
189
|
+
let outcome;
|
|
190
|
+
try {
|
|
191
|
+
outcome = await trainArtifacts({
|
|
192
|
+
cwd,
|
|
193
|
+
env,
|
|
194
|
+
...(ref !== undefined ? { train: ref } : {}),
|
|
195
|
+
...(ctx.args.migrateFrom !== undefined ? { from: resolve(ctx.args.migrateFrom) } : {}),
|
|
196
|
+
...(ctx.args.output !== undefined ? { output: resolve(ctx.args.output) } : {}),
|
|
197
|
+
...(ctx.args.noBuild ? { noBuild: true } : {}),
|
|
198
|
+
say: (line) => console.error(line),
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
catch (err) {
|
|
202
|
+
return report(err, json, ARTIFACTS_USAGE);
|
|
203
|
+
}
|
|
204
|
+
if (json) {
|
|
205
|
+
console.log(JSON.stringify({ train: outcome.train.id, env, members: outcome.members, staged: outcome.staged }, null, 2));
|
|
206
|
+
return 0;
|
|
207
|
+
}
|
|
208
|
+
const n = outcome.members.length;
|
|
209
|
+
const where = outcome.staged ? `, staged in ${relative(cwd, outcome.staged) || outcome.staged}` : "";
|
|
210
|
+
console.error(formatSuccess(n === 0 ? `No member release train ${outcome.train.id} cut here declares release.images or release.artifacts${where}` : `Checked the images and files of ${n} member(s) of release train ${outcome.train.id} against their releases${where}`));
|
|
211
|
+
return 0;
|
|
212
|
+
}
|
|
213
|
+
/** `chant workspace train verify <env> [<train>]` (#5216). */
|
|
214
|
+
export async function runTrainVerify(ctx, words) {
|
|
215
|
+
const { formatError, formatSuccess } = await import("../cli/format.js");
|
|
216
|
+
const [env, ref] = words;
|
|
217
|
+
if (!env || words.length > 2) {
|
|
218
|
+
console.error(formatError({ message: env ? `chant workspace train verify takes an environment and a train, not ${words.join(" ")}` : "chant workspace train verify needs an environment", hint: VERIFY_USAGE }));
|
|
219
|
+
return 1;
|
|
220
|
+
}
|
|
221
|
+
const json = ctx.args.json === true;
|
|
222
|
+
const cwd = resolve(".");
|
|
223
|
+
const { fetchLifecycle } = await import("../lifecycle/git.js");
|
|
224
|
+
await fetchLifecycle({ cwd }).catch(() => false);
|
|
225
|
+
let outcome;
|
|
226
|
+
try {
|
|
227
|
+
outcome = await trainVerify({ cwd, env, ...(ref !== undefined ? { train: ref } : {}), say: (line) => console.error(line) });
|
|
228
|
+
}
|
|
229
|
+
catch (err) {
|
|
230
|
+
return report(err, json, VERIFY_USAGE);
|
|
231
|
+
}
|
|
232
|
+
if (json) {
|
|
233
|
+
console.log(JSON.stringify({ train: outcome.train.id, env, members: outcome.members }, null, 2));
|
|
234
|
+
return 0;
|
|
235
|
+
}
|
|
236
|
+
console.error(formatSuccess(`Verified ${outcome.members.length} member(s) of release train ${outcome.train.id}`));
|
|
237
|
+
return 0;
|
|
238
|
+
}
|