@intentius/chant 0.124.102 → 0.124.103
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/commands/onboard.js +8 -8
- package/dist/cli/handlers/release-init.js +3 -1
- package/dist/cli/main.js +13 -2
- package/dist/cli/parse-args.js +5 -0
- package/dist/cli/registry.d.ts +2 -0
- package/dist/cloud-lister/kubernetes-components.js +1 -2
- package/dist/floor-table.data.js +7 -6
- package/dist/lifecycle/publish-declaration.js +1 -2
- 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-rubygems.js +1 -2
- package/dist/lifecycle/release-artifacts.js +1 -2
- package/dist/lifecycle/release-init.js +10 -9
- package/dist/release-floors.d.ts +1 -1
- package/dist/release-floors.js +1 -1
- package/dist/wave-runtime.mjs +4 -4
- package/dist/workspace/release-train-workflow.d.ts +21 -3
- package/dist/workspace/release-train-workflow.js +129 -8
- package/dist/workspace/release-train.js +5 -1
- package/dist/workspace/release-workflow.d.ts +11 -0
- package/dist/workspace/release-workflow.js +42 -9
- package/dist/workspace/train-artifacts.d.ts +107 -0
- package/dist/workspace/train-artifacts.js +239 -0
- package/dist/workspace/train-cut.d.ts +12 -0
- package/dist/workspace/train-cut.js +22 -2
- package/dist/workspace/train-publish.d.ts +9 -0
- package/dist/workspace/train-publish.js +27 -1
- package/package.json +1 -1
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The files a release train's members build at the cut, carried from the job
|
|
3
|
+
* that cut them to the job that publishes them (#5216), and the signature
|
|
4
|
+
* check of each member before the publish.
|
|
5
|
+
*
|
|
6
|
+
* `chant workspace train artifacts <env> [<train>] [--from <dir>] [-o <dir>]
|
|
7
|
+
* [--no-build] [--json]`, in a checkout of the train's commit: for each member
|
|
8
|
+
* the train cut from this commit that declares `release.images` or
|
|
9
|
+
* `release.artifacts`, the image archives and files the release records are
|
|
10
|
+
* checked against their recorded digests, as `chant release images` and
|
|
11
|
+
* `chant release artifacts` check one member's:
|
|
12
|
+
*
|
|
13
|
+
* - `--from <dir>` first copies each member's files from `<dir>/<member
|
|
14
|
+
* directory>/`, where an earlier job staged them;
|
|
15
|
+
* - a member whose files are all here is checked as they are; a member with
|
|
16
|
+
* one missing builds its images, or its files, again (`--no-build` refuses
|
|
17
|
+
* instead), and what it builds must have the recorded digests;
|
|
18
|
+
* - `-o <dir>` stages every member's checked files at `<dir>/<member
|
|
19
|
+
* directory>/<path>`, with `chant-train-artifacts.json` naming the members,
|
|
20
|
+
* for the next job's `--from`.
|
|
21
|
+
*
|
|
22
|
+
* `chant workspace train verify <env> [<train>] [--json]` runs `chant release
|
|
23
|
+
* verify` for each member the train cut from this commit, so a cut whose
|
|
24
|
+
* signature does not verify stops the publish (the `verified-releases`
|
|
25
|
+
* group).
|
|
26
|
+
*/
|
|
27
|
+
import { spawnSync } from "node:child_process";
|
|
28
|
+
import { cpSync, existsSync, mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
|
|
29
|
+
import { tmpdir } from "node:os";
|
|
30
|
+
import { join, relative, resolve, sep } from "node:path";
|
|
31
|
+
import { readDeclaration } from "./declaration.js";
|
|
32
|
+
import { findTrain, readReleaseTrains } from "./release-train.js";
|
|
33
|
+
import { ownChant, TrainCutError } from "./train-cut.js";
|
|
34
|
+
import { locateWorkspace } from "./which-chant.js";
|
|
35
|
+
import { NEXT_RELEASE } from "../release-floors.js";
|
|
36
|
+
/** The first chant with `chant workspace train artifacts`, `train verify` and `train cut --doctor`, and a train publish that gives a member with images its digests in `CHANT_RELEASE_DIGESTS` (#5216): what the train workflow's cut and publish jobs run. */
|
|
37
|
+
export const TRAIN_ARTIFACTS_FLOOR = NEXT_RELEASE;
|
|
38
|
+
/** The file `-o` writes beside the staged files, naming the members staged. */
|
|
39
|
+
export const TRAIN_ARTIFACTS_INDEX = "chant-train-artifacts.json";
|
|
40
|
+
/** The train, and its members cut from the commit checked out at the workspace root. */
|
|
41
|
+
export async function trainMembersHere(cwd, env, ref) {
|
|
42
|
+
const located = locateWorkspace(cwd);
|
|
43
|
+
const root = located.rootOnDisk;
|
|
44
|
+
const train = findTrain((await readReleaseTrains(root, env)).records, ref);
|
|
45
|
+
if (!train)
|
|
46
|
+
throw new TrainCutError("train-unknown", ref ? `no release train ${ref} is recorded for ${env}` : `no release train is recorded for ${env}`, `List them with chant workspace train list ${env}.`);
|
|
47
|
+
let head;
|
|
48
|
+
try {
|
|
49
|
+
head = spawnSync("git", ["rev-parse", "HEAD"], { cwd: root, encoding: "utf-8" }).stdout.trim();
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
head = "";
|
|
53
|
+
}
|
|
54
|
+
if (!head)
|
|
55
|
+
throw new TrainCutError("not-a-git-repository", "a train's files are checked in a checkout of its commit, and this directory is not in a git repository");
|
|
56
|
+
const dirs = new Map(readDeclaration(located.tree, "", { rootChant: true }).members.map((m) => [m.name, m.dir]));
|
|
57
|
+
const members = [];
|
|
58
|
+
for (const m of train.members.filter((x) => x.commit === head)) {
|
|
59
|
+
const rel = dirs.get(m.member);
|
|
60
|
+
if (rel === undefined)
|
|
61
|
+
throw new TrainCutError("train-member-unknown", `release train ${train.id} pins ${m.member}, which the declaration does not list`);
|
|
62
|
+
members.push({ member: m.member, dir: resolve(root, rel), rel: rel.split(sep).join("/"), ref: m.label ?? m.releaseDigest, releaseDigest: m.releaseDigest });
|
|
63
|
+
}
|
|
64
|
+
if (members.length === 0)
|
|
65
|
+
throw new TrainCutError("train-nothing-cut-here", `release train ${train.id} has no release cut from this checkout's commit ${head.slice(0, 12)}`, "Check out the commit the train's release-train tag names.");
|
|
66
|
+
return { root, train, members };
|
|
67
|
+
}
|
|
68
|
+
/** The default {@link MemberChant}: this chant, its stdout on stderr so a `--json` caller's stdout stays one document. */
|
|
69
|
+
export const spawnMemberChant = (args, cwd) => {
|
|
70
|
+
const [bin, ...pre] = ownChant();
|
|
71
|
+
const r = spawnSync(bin, [...pre, ...args], { cwd, stdio: ["ignore", 2, 2] });
|
|
72
|
+
return r.status ?? 1;
|
|
73
|
+
};
|
|
74
|
+
/** Check, build again where missing, and stage the images and files of every member the train cut here (#5216). */
|
|
75
|
+
export async function trainArtifacts(q) {
|
|
76
|
+
const { train, members } = await trainMembersHere(q.cwd, q.env, q.train);
|
|
77
|
+
const { loadChantConfig } = await import("../config.js");
|
|
78
|
+
const { resolveRelease } = await import("../lifecycle/release-store.js");
|
|
79
|
+
const { releaseArtifactFiles } = await import("../lifecycle/release-artifacts.js");
|
|
80
|
+
const { resolveReleaseImages } = await import("../lifecycle/release-images.js");
|
|
81
|
+
const chant = q.chant ?? spawnMemberChant;
|
|
82
|
+
const say = q.say ?? (() => undefined);
|
|
83
|
+
const out = [];
|
|
84
|
+
const scratch = mkdtempSync(join(tmpdir(), "chant-train-artifacts-"));
|
|
85
|
+
for (const m of members) {
|
|
86
|
+
const release = (await loadChantConfig(m.dir)).config.release;
|
|
87
|
+
const declaredImages = release?.images ?? [];
|
|
88
|
+
const declaredFiles = release?.artifacts ?? [];
|
|
89
|
+
if (declaredImages.length === 0 && declaredFiles.length === 0)
|
|
90
|
+
continue;
|
|
91
|
+
const found = await resolveRelease(m.releaseDigest, { cwd: m.dir });
|
|
92
|
+
if (!found)
|
|
93
|
+
throw new TrainCutError("release-not-found", `${m.member}: the train pins release ${m.releaseDigest}, which no cut in the member names`, `Fetch chant/lifecycle (git fetch origin chant/lifecycle:chant/lifecycle) in the train's checkout.`);
|
|
94
|
+
const images = resolveReleaseImages(declaredImages).map((i) => i.archive.replace(/^\.\//, ""));
|
|
95
|
+
const files = releaseArtifactFiles(found.release, declaredFiles.map((d) => d.name)).map((f) => f.path);
|
|
96
|
+
let copied = 0;
|
|
97
|
+
if (q.from !== undefined) {
|
|
98
|
+
for (const p of [...images, ...files]) {
|
|
99
|
+
const src = resolve(q.from, m.rel, p);
|
|
100
|
+
if (!existsSync(src))
|
|
101
|
+
continue;
|
|
102
|
+
const dest = resolve(m.dir, p);
|
|
103
|
+
mkdirSync(resolve(dest, ".."), { recursive: true });
|
|
104
|
+
cpSync(src, dest, { recursive: true, force: true });
|
|
105
|
+
copied++;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const here = (paths) => paths.length > 0 && paths.every((p) => existsSync(resolve(m.dir, p)));
|
|
109
|
+
const built = { images: false, files: false };
|
|
110
|
+
const step = (what, paths) => {
|
|
111
|
+
const present = here(paths);
|
|
112
|
+
if (!present && q.noBuild) {
|
|
113
|
+
const absent = paths.filter((p) => !existsSync(resolve(m.dir, p)));
|
|
114
|
+
throw new TrainCutError("train-artifact-missing", `${m.member} ${m.ref}: ${absent.length > 0 ? absent.join(", ") : `its release.${what}`} ${absent.length === 1 ? "is" : "are"} not here`, "Hand this job the files the cut staged (--from <dir>), or run without --no-build to build them again.");
|
|
115
|
+
}
|
|
116
|
+
if (!present)
|
|
117
|
+
built[what === "images" ? "images" : "files"] = true;
|
|
118
|
+
const args = what === "images" ? ["release", "images", m.ref, ...(present ? ["--no-build"] : []), "-o", join(scratch, `${m.member}-digests.json`)] : ["release", "artifacts", m.ref, ...(present ? ["--no-build"] : [])];
|
|
119
|
+
say(`${m.member} ${m.ref}: ${present ? "check" : "build again and check"} its ${what === "images" ? `image archive(s) ${paths.join(", ")}` : `file(s)${paths.length > 0 ? ` ${paths.join(", ")}` : ""}`}`);
|
|
120
|
+
const code = chant(args, m.dir);
|
|
121
|
+
if (code !== 0)
|
|
122
|
+
throw new TrainCutError(`train-${what === "images" ? "image" : "artifact"}-check-failed`, `${m.member} ${m.ref}: chant ${args.slice(0, 3).join(" ")}${present ? " --no-build" : ""} failed (exit ${code})`, "Its output above says which file differs from the release. Publish the files the cut built, or cut a new train.");
|
|
123
|
+
};
|
|
124
|
+
if (declaredImages.length > 0)
|
|
125
|
+
step("images", images);
|
|
126
|
+
if (declaredFiles.length > 0)
|
|
127
|
+
step("artifacts", files);
|
|
128
|
+
if (q.output !== undefined) {
|
|
129
|
+
for (const p of [...images, ...files]) {
|
|
130
|
+
const dest = resolve(q.output, m.rel, p);
|
|
131
|
+
mkdirSync(resolve(dest, ".."), { recursive: true });
|
|
132
|
+
cpSync(resolve(m.dir, p), dest, { recursive: true, force: true });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
out.push({ member: m.member, ref: m.ref, images, files, built, copied });
|
|
136
|
+
}
|
|
137
|
+
let staged = null;
|
|
138
|
+
if (q.output !== undefined) {
|
|
139
|
+
staged = resolve(q.output);
|
|
140
|
+
mkdirSync(staged, { recursive: true });
|
|
141
|
+
// Always written, so the next job finds a staged directory even when no member of this train builds files.
|
|
142
|
+
writeFileSync(join(staged, TRAIN_ARTIFACTS_INDEX), `${JSON.stringify({ train: train.id, members: out.map((m) => ({ member: m.member, ref: m.ref, images: m.images, files: m.files })) }, null, 2)}\n`);
|
|
143
|
+
}
|
|
144
|
+
return { train, members: out, staged };
|
|
145
|
+
}
|
|
146
|
+
/** Run `chant release verify` for each member the train cut here (#5216); every failure is reported before the exit. */
|
|
147
|
+
export async function trainVerify(q) {
|
|
148
|
+
const { train, members } = await trainMembersHere(q.cwd, q.env, q.train);
|
|
149
|
+
const chant = q.chant ?? spawnMemberChant;
|
|
150
|
+
const say = q.say ?? (() => undefined);
|
|
151
|
+
const out = members.map((m) => {
|
|
152
|
+
say(`${m.member} ${m.ref}: chant release verify ${m.ref}`);
|
|
153
|
+
return { member: m.member, ref: m.ref, ok: chant(["release", "verify", m.ref], m.dir) === 0 };
|
|
154
|
+
});
|
|
155
|
+
const failed = out.filter((m) => !m.ok);
|
|
156
|
+
if (failed.length > 0) {
|
|
157
|
+
throw new TrainCutError("train-verify-failed", `release verify failed for ${failed.map((m) => `${m.member} ${m.ref}`).join(", ")}, so nothing of train ${train.id} is published`, "Its output above says why. A cut whose signature does not verify is cut again by a signer .chant/allowed_signers lists.");
|
|
158
|
+
}
|
|
159
|
+
return { train, members: out };
|
|
160
|
+
}
|
|
161
|
+
const ARTIFACTS_USAGE = "chant workspace train artifacts <env> [<train id|digest>] [--from <dir>] [-o <dir>] [--no-build] [--json]";
|
|
162
|
+
const VERIFY_USAGE = "chant workspace train verify <env> [<train id|digest>] [--json]";
|
|
163
|
+
async function report(err, json, usage) {
|
|
164
|
+
const { formatError } = await import("../cli/format.js");
|
|
165
|
+
const { WorkspaceReadError } = await import("./declaration.js");
|
|
166
|
+
if (err instanceof TrainCutError) {
|
|
167
|
+
if (json)
|
|
168
|
+
console.log(JSON.stringify({ status: "refused", code: err.code, message: err.message }, null, 2));
|
|
169
|
+
console.error(formatError({ message: `${err.message} [${err.code}]`, hint: err.fix ?? usage }));
|
|
170
|
+
return 1;
|
|
171
|
+
}
|
|
172
|
+
if (err instanceof WorkspaceReadError) {
|
|
173
|
+
console.error(formatError({ message: `${err.code}: ${err.describe()}`, hint: usage }));
|
|
174
|
+
return 1;
|
|
175
|
+
}
|
|
176
|
+
throw err;
|
|
177
|
+
}
|
|
178
|
+
/** `chant workspace train artifacts <env> [<train>]` (#5216). */
|
|
179
|
+
export async function runTrainArtifacts(ctx, words) {
|
|
180
|
+
const { formatError, formatSuccess } = await import("../cli/format.js");
|
|
181
|
+
const [env, ref] = words;
|
|
182
|
+
if (!env || words.length > 2) {
|
|
183
|
+
console.error(formatError({ message: env ? `chant workspace train artifacts takes an environment and a train, not ${words.join(" ")}` : "chant workspace train artifacts needs an environment", hint: ARTIFACTS_USAGE }));
|
|
184
|
+
return 1;
|
|
185
|
+
}
|
|
186
|
+
const json = ctx.args.json === true;
|
|
187
|
+
const cwd = resolve(".");
|
|
188
|
+
const { fetchLifecycle } = await import("../lifecycle/git.js");
|
|
189
|
+
await fetchLifecycle({ cwd }).catch(() => false);
|
|
190
|
+
let outcome;
|
|
191
|
+
try {
|
|
192
|
+
outcome = await trainArtifacts({
|
|
193
|
+
cwd,
|
|
194
|
+
env,
|
|
195
|
+
...(ref !== undefined ? { train: ref } : {}),
|
|
196
|
+
...(ctx.args.migrateFrom !== undefined ? { from: resolve(ctx.args.migrateFrom) } : {}),
|
|
197
|
+
...(ctx.args.output !== undefined ? { output: resolve(ctx.args.output) } : {}),
|
|
198
|
+
...(ctx.args.noBuild ? { noBuild: true } : {}),
|
|
199
|
+
say: (line) => console.error(line),
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
catch (err) {
|
|
203
|
+
return report(err, json, ARTIFACTS_USAGE);
|
|
204
|
+
}
|
|
205
|
+
if (json) {
|
|
206
|
+
console.log(JSON.stringify({ train: outcome.train.id, env, members: outcome.members, staged: outcome.staged }, null, 2));
|
|
207
|
+
return 0;
|
|
208
|
+
}
|
|
209
|
+
const n = outcome.members.length;
|
|
210
|
+
const where = outcome.staged ? `, staged in ${relative(cwd, outcome.staged) || outcome.staged}` : "";
|
|
211
|
+
console.error(formatSuccess(n === 0 ? `No member release train ${outcome.train.id} cut here declares release.images or release.artifacts${where}` : `Checked the images and files of ${n} member(s) of release train ${outcome.train.id} against their releases${where}`));
|
|
212
|
+
return 0;
|
|
213
|
+
}
|
|
214
|
+
/** `chant workspace train verify <env> [<train>]` (#5216). */
|
|
215
|
+
export async function runTrainVerify(ctx, words) {
|
|
216
|
+
const { formatError, formatSuccess } = await import("../cli/format.js");
|
|
217
|
+
const [env, ref] = words;
|
|
218
|
+
if (!env || words.length > 2) {
|
|
219
|
+
console.error(formatError({ message: env ? `chant workspace train verify takes an environment and a train, not ${words.join(" ")}` : "chant workspace train verify needs an environment", hint: VERIFY_USAGE }));
|
|
220
|
+
return 1;
|
|
221
|
+
}
|
|
222
|
+
const json = ctx.args.json === true;
|
|
223
|
+
const cwd = resolve(".");
|
|
224
|
+
const { fetchLifecycle } = await import("../lifecycle/git.js");
|
|
225
|
+
await fetchLifecycle({ cwd }).catch(() => false);
|
|
226
|
+
let outcome;
|
|
227
|
+
try {
|
|
228
|
+
outcome = await trainVerify({ cwd, env, ...(ref !== undefined ? { train: ref } : {}), say: (line) => console.error(line) });
|
|
229
|
+
}
|
|
230
|
+
catch (err) {
|
|
231
|
+
return report(err, json, VERIFY_USAGE);
|
|
232
|
+
}
|
|
233
|
+
if (json) {
|
|
234
|
+
console.log(JSON.stringify({ train: outcome.train.id, env, members: outcome.members }, null, 2));
|
|
235
|
+
return 0;
|
|
236
|
+
}
|
|
237
|
+
console.error(formatSuccess(`Verified ${outcome.members.length} member(s) of release train ${outcome.train.id}`));
|
|
238
|
+
return 0;
|
|
239
|
+
}
|
|
@@ -26,6 +26,8 @@
|
|
|
26
26
|
* 4. `release.train.check`: shell lines run once the labels are known and
|
|
27
27
|
* before anything is cut, with `CHANT_RELEASE_COMMIT`, `CHANT_TRAIN_ENV`
|
|
28
28
|
* and `CHANT_TRAIN_PLAN` (a JSON file of the members and labels).
|
|
29
|
+
* With `--doctor` (#5216), `chant release doctor` then runs in each
|
|
30
|
+
* member, and a failed check stops the train with nothing cut.
|
|
29
31
|
* 5. `chant release cut <label> --at <commit> --yes` in each member's
|
|
30
32
|
* directory, in publish order. Each cut pushes its record and tags the
|
|
31
33
|
* commit locally.
|
|
@@ -141,6 +143,8 @@ export type MemberCutter = (m: TrainCutMember, commit: string, o: {
|
|
|
141
143
|
root: string;
|
|
142
144
|
yes: boolean;
|
|
143
145
|
}) => Promise<MemberCutResult>;
|
|
146
|
+
/** The chant this process runs, as a command line. */
|
|
147
|
+
export declare function ownChant(): string[];
|
|
144
148
|
/** The default {@link MemberCutter}: this chant's `release cut` in the member's directory. */
|
|
145
149
|
export declare const spawnMemberCut: MemberCutter;
|
|
146
150
|
export interface TrainCutRun extends TrainCutQuery {
|
|
@@ -152,6 +156,14 @@ export interface TrainCutRun extends TrainCutQuery {
|
|
|
152
156
|
remote?: string;
|
|
153
157
|
actor?: string;
|
|
154
158
|
cutter?: MemberCutter;
|
|
159
|
+
/**
|
|
160
|
+
* Run `chant release doctor` in each member of the train before anything is
|
|
161
|
+
* cut (#5216): a target that can't publish from here stops the train with
|
|
162
|
+
* nothing cut, tagged or pushed.
|
|
163
|
+
*/
|
|
164
|
+
doctor?: boolean;
|
|
165
|
+
/** Runs the doctor in a member's directory and returns its exit code. Default: this chant's `release doctor`, its stdout sent to stderr. */
|
|
166
|
+
runDoctor?: (dir: string) => number | Promise<number>;
|
|
155
167
|
/** Runs the `release.train.check` lines. Default: `sh -c` each one, its stdout sent to stderr. */
|
|
156
168
|
runCheck?: (line: string, o: {
|
|
157
169
|
cwd: string;
|
|
@@ -26,6 +26,8 @@
|
|
|
26
26
|
* 4. `release.train.check`: shell lines run once the labels are known and
|
|
27
27
|
* before anything is cut, with `CHANT_RELEASE_COMMIT`, `CHANT_TRAIN_ENV`
|
|
28
28
|
* and `CHANT_TRAIN_PLAN` (a JSON file of the members and labels).
|
|
29
|
+
* With `--doctor` (#5216), `chant release doctor` then runs in each
|
|
30
|
+
* member, and a failed check stops the train with nothing cut.
|
|
29
31
|
* 5. `chant release cut <label> --at <commit> --yes` in each member's
|
|
30
32
|
* directory, in publish order. Each cut pushes its record and tags the
|
|
31
33
|
* commit locally.
|
|
@@ -317,7 +319,7 @@ export async function planTrainCut(q) {
|
|
|
317
319
|
return { env: q.env, commit, first: false, released: null, members: out };
|
|
318
320
|
}
|
|
319
321
|
/** The chant this process runs, as a command line. */
|
|
320
|
-
function ownChant() {
|
|
322
|
+
export function ownChant() {
|
|
321
323
|
return [process.execPath, ...process.execArgv, process.argv[1]];
|
|
322
324
|
}
|
|
323
325
|
/** The default {@link MemberCutter}: this chant's `release cut` in the member's directory. */
|
|
@@ -344,6 +346,11 @@ export const spawnMemberCut = async (m, commit, o) => {
|
|
|
344
346
|
};
|
|
345
347
|
// A check's stdout goes to stderr: under --json, stdout is the cut's JSON document alone.
|
|
346
348
|
const defaultCheck = (line, o) => runToStderr(line, o);
|
|
349
|
+
/** This chant's `release doctor` in a member's directory, its stdout sent to stderr. */
|
|
350
|
+
const defaultDoctor = (dir) => {
|
|
351
|
+
const [bin, ...pre] = ownChant();
|
|
352
|
+
return spawnSync(bin, [...pre, "release", "doctor"], { cwd: dir, stdio: ["ignore", 2, 2] }).status ?? 1;
|
|
353
|
+
};
|
|
347
354
|
/** Plan, and with `yes` cut, record, tag and push, a release train (#5154). */
|
|
348
355
|
export async function cutTrain(q) {
|
|
349
356
|
const root = locateWorkspace(q.cwd).rootOnDisk;
|
|
@@ -385,6 +392,18 @@ export async function cutTrain(q) {
|
|
|
385
392
|
}
|
|
386
393
|
}
|
|
387
394
|
}
|
|
395
|
+
// #5216: each member's doctor, after the checks and before the first cut.
|
|
396
|
+
if (q.doctor) {
|
|
397
|
+
const failed = [];
|
|
398
|
+
for (const m of plan.members) {
|
|
399
|
+
say(`doctor: ${m.member}`);
|
|
400
|
+
const code = await (q.runDoctor ?? defaultDoctor)(resolve(root, m.dir));
|
|
401
|
+
if (code !== 0)
|
|
402
|
+
failed.push(m.member);
|
|
403
|
+
}
|
|
404
|
+
if (failed.length > 0)
|
|
405
|
+
throw new TrainCutError("train-doctor-failed", `release doctor found a target that can't publish from here in ${failed.join(", ")}`, "Nothing was cut. Fix what the doctor reports and run the train again.");
|
|
406
|
+
}
|
|
388
407
|
const cutter = q.cutter ?? spawnMemberCut;
|
|
389
408
|
const tags = {};
|
|
390
409
|
for (const m of plan.members) {
|
|
@@ -434,7 +453,7 @@ export async function cutTrain(q) {
|
|
|
434
453
|
}
|
|
435
454
|
return { ...out, pushed: true };
|
|
436
455
|
}
|
|
437
|
-
const CUT_USAGE = "chant workspace train cut <env> [--at <sha>] [--levels <levels>] [--yes] [--no-push] [--json]";
|
|
456
|
+
const CUT_USAGE = "chant workspace train cut <env> [--at <sha>] [--levels <levels>] [--doctor] [--yes] [--no-push] [--json]";
|
|
438
457
|
/** `chant workspace train cut <env>` (#5154). */
|
|
439
458
|
export async function runTrainCut(ctx, words) {
|
|
440
459
|
const { formatError, formatSuccess, formatWarning } = await import("../cli/format.js");
|
|
@@ -460,6 +479,7 @@ export async function runTrainCut(ctx, words) {
|
|
|
460
479
|
levels: parseTrainLevels(args.levels),
|
|
461
480
|
yes: args.yes === true && args.dryRun !== true,
|
|
462
481
|
noPush: args.noPush === true,
|
|
482
|
+
doctor: args.doctor === true,
|
|
463
483
|
...(args.actor ? { actor: args.actor } : {}),
|
|
464
484
|
say: (line) => (json ? undefined : console.error(line)),
|
|
465
485
|
});
|
|
@@ -173,5 +173,14 @@ export declare function trainDependencies(members: ReadonlyArray<{
|
|
|
173
173
|
}>): Map<string, string[]>;
|
|
174
174
|
/** Plan, and with `yes` publish, a release train (#5136). */
|
|
175
175
|
export declare function publishTrain(query: TrainPublishQuery): Promise<TrainPublishOutcome>;
|
|
176
|
+
/** The tag `release.tag` gives `label` in the member at `dir`, or null when it can't be told. */
|
|
177
|
+
/**
|
|
178
|
+
* The environment a member's targets run with (#5216): for a member that
|
|
179
|
+
* declares `release.images`, `CHANT_RELEASE_DIGESTS` names a file of the
|
|
180
|
+
* digests its release records, as `chant release images` writes it for one
|
|
181
|
+
* release, so a package it packs pins its own images. Other members get the
|
|
182
|
+
* environment as it is.
|
|
183
|
+
*/
|
|
184
|
+
export declare function memberDigestsEnv(dir: string, release: import("../lifecycle/release-store.js").Release, env: NodeJS.ProcessEnv): Promise<NodeJS.ProcessEnv>;
|
|
176
185
|
/** `chant workspace train publish <env> [<train>] [--yes]` (#5136). */
|
|
177
186
|
export declare function runTrainPublish(ctx: import("../cli/registry.js").CommandContext, words: string[]): Promise<number>;
|
|
@@ -228,7 +228,7 @@ export async function publishTrain(query) {
|
|
|
228
228
|
for (const w of [plan.signatureWarning, plan.warning])
|
|
229
229
|
if (w && !warnings.includes(`${m.member}: ${w}`))
|
|
230
230
|
warnings.push(`${m.member}: ${w}`);
|
|
231
|
-
const ctx = publishContext(plan, { cwd: dir, env, tag: plan.channel, log: memberLog(m.member, plan.redactor) });
|
|
231
|
+
const ctx = publishContext(plan, { cwd: dir, env: await memberDigestsEnv(dir, plan.release, env), tag: plan.channel, log: memberLog(m.member, plan.redactor) });
|
|
232
232
|
prepared.push({ m, dir, plan, ctx });
|
|
233
233
|
}
|
|
234
234
|
const redactor = createRedactor(env, credentialEnv);
|
|
@@ -306,6 +306,32 @@ export async function publishTrain(query) {
|
|
|
306
306
|
return { kind: "published", train, members, warnings, redactor, verify, ...ran, floatingWarnings };
|
|
307
307
|
}
|
|
308
308
|
/** The tag `release.tag` gives `label` in the member at `dir`, or null when it can't be told. */
|
|
309
|
+
/**
|
|
310
|
+
* The environment a member's targets run with (#5216): for a member that
|
|
311
|
+
* declares `release.images`, `CHANT_RELEASE_DIGESTS` names a file of the
|
|
312
|
+
* digests its release records, as `chant release images` writes it for one
|
|
313
|
+
* release, so a package it packs pins its own images. Other members get the
|
|
314
|
+
* environment as it is.
|
|
315
|
+
*/
|
|
316
|
+
export async function memberDigestsEnv(dir, release, env) {
|
|
317
|
+
const { loadChantConfig } = await import("../config.js");
|
|
318
|
+
let images;
|
|
319
|
+
try {
|
|
320
|
+
images = (await loadChantConfig(dir)).config.release?.images ?? [];
|
|
321
|
+
}
|
|
322
|
+
catch {
|
|
323
|
+
return env;
|
|
324
|
+
}
|
|
325
|
+
if (images.length === 0)
|
|
326
|
+
return env;
|
|
327
|
+
const { releaseImageDigests, writeReleaseDigests, RELEASE_DIGESTS_ENV } = await import("../lifecycle/release-images.js");
|
|
328
|
+
const { mkdtempSync } = await import("node:fs");
|
|
329
|
+
const { tmpdir } = await import("node:os");
|
|
330
|
+
const { join } = await import("node:path");
|
|
331
|
+
const file = join(mkdtempSync(join(tmpdir(), "chant-train-digests-")), "release-digests.json");
|
|
332
|
+
writeReleaseDigests(file, releaseImageDigests(release, images.map((i) => i.name)));
|
|
333
|
+
return { ...env, [RELEASE_DIGESTS_ENV]: file };
|
|
334
|
+
}
|
|
309
335
|
async function pinnedReleaseTag(dir, label) {
|
|
310
336
|
try {
|
|
311
337
|
const { memberTags, renderReleaseTag } = await import("../lifecycle/release-tag.js");
|
package/package.json
CHANGED