shiplane 0.5.1 → 0.6.0-ci-setup-action.d7598bc
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/README.md +1 -1
- package/dist/cli.js +157 -310
- package/dist/cli.js.map +1 -1
- package/dist/{readStatus-QU-K9Czb.js → compose-D4iloRtV.js} +2819 -1441
- package/dist/compose-D4iloRtV.js.map +1 -0
- package/dist/{budget-BTnKtGF6.js → display-CfV4G1TR.js} +155 -52
- package/dist/display-CfV4G1TR.js.map +1 -0
- package/dist/{static-hosting.port-pfDvRESk.d.ts → index-C13VtxPj.d.ts} +495 -23
- package/dist/index.d.ts +2 -3
- package/dist/index.js +3 -4
- package/dist/{issues-TcWtMTv5.js → issues-DCRpXUBW.js} +1 -1
- package/dist/{issues-TcWtMTv5.js.map → issues-DCRpXUBW.js.map} +1 -1
- package/dist/memory.d.ts +1 -1
- package/dist/memory.js +1 -1
- package/dist/{package-registry.fake-BuiTldHL.js → package-registry.fake-CSdBAEEV.js} +61 -6
- package/dist/package-registry.fake-CSdBAEEV.js.map +1 -0
- package/dist/{package-registry.fake-CPAwyGn_.d.ts → package-registry.fake-DZj2Hu3S.d.ts} +59 -6
- package/dist/plugin-ts16G1ar.d.ts +118 -0
- package/dist/plugin.d.ts +3 -23
- package/dist/plugin.js +84 -7
- package/dist/plugin.js.map +1 -0
- package/dist/shell-server-hosting.adapter-8IgiuCgh.js +371 -0
- package/dist/shell-server-hosting.adapter-8IgiuCgh.js.map +1 -0
- package/dist/{src-DO7WyrfV.js → src-DPSNCKTT.js} +2 -2
- package/dist/src-DPSNCKTT.js.map +1 -0
- package/dist/testing.d.ts +107 -20
- package/dist/testing.js +242 -24
- package/dist/testing.js.map +1 -1
- package/package.json +2 -1
- package/dist/budget-BTnKtGF6.js.map +0 -1
- package/dist/display-IqkJ6uCw.js +0 -96
- package/dist/display-IqkJ6uCw.js.map +0 -1
- package/dist/index-CpQPaO28.d.ts +0 -252
- package/dist/package-registry.fake-BuiTldHL.js.map +0 -1
- package/dist/readStatus-QU-K9Czb.js.map +0 -1
- package/dist/shell-server-hosting.adapter-C7_5MWrl.js +0 -50
- package/dist/shell-server-hosting.adapter-C7_5MWrl.js.map +0 -1
- package/dist/src-DO7WyrfV.js.map +0 -1
- package/dist/web-app.module-Cg3SYqSo.js +0 -121
- package/dist/web-app.module-Cg3SYqSo.js.map +0 -1
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ flowchart LR
|
|
|
16
16
|
## ⚡ Three commands
|
|
17
17
|
|
|
18
18
|
```sh
|
|
19
|
-
pnpm shiplane
|
|
19
|
+
pnpm shiplane setup # find what ships, rehearse, write the config
|
|
20
20
|
pnpm shiplane # release PR, merge, tags, ship to preview
|
|
21
21
|
pnpm shiplane promote # what preview validated, to production
|
|
22
22
|
```
|
package/dist/cli.js
CHANGED
|
@@ -1,307 +1,92 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as
|
|
3
|
-
import { C as refreshEditorSchema, D as keysAt, E as ENVIRONMENTS, O as nodeFiles, _ as loadRelease, a as releaseToPreview, b as initRelease, c as promote, d as pickScope, f as openReleasePr, g as findConfig, h as docsFor, i as setup, l as shipTo, m as newAdapter, n as systemShell, o as missingTags, p as prepareRelease, r as liveLine, s as tagRelease, t as readStatus, u as planShips, v as addUnit, w as environmentLabel, x as doctor, y as removeUnit } from "./readStatus-QU-K9Czb.js";
|
|
4
|
-
import { n as resolveDisplay, t as progressBar } from "./display-IqkJ6uCw.js";
|
|
5
|
-
import { createRequire } from "node:module";
|
|
2
|
+
import { A as commandLine, C as initRelease, D as checkStatus, E as refreshEditorSchema, F as keysAt, I as nodeFiles, N as paint, O as requirementsOf, P as ENVIRONMENTS, S as removeUnit, _ as tagRelease, a as findConfig, b as prepareRelease, c as promote, d as docsFor, f as branchRelease, g as missingTags, h as readStatus, j as environmentLabel, k as signInsOf, l as planShips, m as shipTo, n as composeSetup, r as loadReleaseOnDisk, s as setup, t as composeContext, u as newAdapter, v as pickScope, w as doctor, x as addUnit, y as openReleasePr } from "./compose-D4iloRtV.js";
|
|
6
3
|
import { z } from "zod";
|
|
7
4
|
import fs from "node:fs";
|
|
8
5
|
import path from "node:path";
|
|
9
|
-
import { parseArgs
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const face = frame.slice(5, 10).join("");
|
|
27
|
-
return `${styleText("yellow", frame.slice(0, 5).join(""))}${styleText(mood === "happy" ? ["bold", "green"] : "bold", face)}${styleText("cyan", frame.slice(10).join(""))}`;
|
|
28
|
-
};
|
|
29
|
-
const elapsed = (since) => {
|
|
30
|
-
const seconds = Math.round((Date.now() - since) / 1e3);
|
|
31
|
-
return seconds < 60 ? `${seconds}s` : `${Math.floor(seconds / 60)}m ${String(seconds % 60).padStart(2, "0")}s`;
|
|
32
|
-
};
|
|
33
|
-
/** Cuts `text` to what the terminal shows on one line, so redrawing it in place stays clean. */
|
|
34
|
-
const fit = (text, taken) => {
|
|
35
|
-
const room = Math.max(20, (process.stdout.columns || 100) - taken);
|
|
36
|
-
return text.length > room ? `${text.slice(0, room - 1)}…` : text;
|
|
37
|
-
};
|
|
38
|
-
const counterOf = (step) => step ? `${step.index + 1}/${step.total} ` : "";
|
|
6
|
+
import { parseArgs } from "node:util";
|
|
7
|
+
//#region src/application/doctorCi.ts
|
|
8
|
+
/** Where every check a runner makes is listed, with what it supports. */
|
|
9
|
+
const WORKFLOW_DOCS = "https://github.com/arnaud-zg/js-packages/blob/main/docs/shiplane/reference.md#github-actions-workflow";
|
|
10
|
+
/** The units a run names, each one the config's. */
|
|
11
|
+
const unitsSchema = (known) => z.array(z.string()).superRefine((names, context) => {
|
|
12
|
+
const unknown = names.filter((name) => !known.includes(name));
|
|
13
|
+
if (unknown.length > 0) context.addIssue({
|
|
14
|
+
code: "custom",
|
|
15
|
+
message: `unknown units [${unknown.join(", ")}]: known [${known.join(", ")}]`
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
const environmentSchema = z.enum(ENVIRONMENTS, { error: ({ input }) => `unknown environment "${String(input)}": ${ENVIRONMENTS.join(", ")}` });
|
|
19
|
+
/** The first problem a schema found, as said. */
|
|
20
|
+
const problemOf = (error) => error.issues[0]?.message ?? "invalid";
|
|
21
|
+
/** `$NAME` and `${NAME}` read from the environment, such as `$HOME/.fly/bin`. */
|
|
22
|
+
const expand = (context, text) => text.replace(/\$\{?(\w+)\}?/g, (_, name) => context.shell.env(name) ?? "");
|
|
39
23
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* gets plain lines, never a redraw.
|
|
24
|
+
* A missing tool installed, its folder put first on PATH for this run and, through `GITHUB_PATH`,
|
|
25
|
+
* for the steps after it. The problem, or null once it answers.
|
|
43
26
|
*/
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
const text = fit(label, taken(step));
|
|
61
|
-
if (!inPlace || liveLine.busy) {
|
|
62
|
-
liveLine.above(` ${mascot(mood, 0, label)}${counter}${text}`);
|
|
63
|
-
return work();
|
|
64
|
-
}
|
|
65
|
-
const started = Date.now();
|
|
66
|
-
const time = () => styleText("dim", elapsed(started));
|
|
67
|
-
const drawing = display.mascot;
|
|
68
|
-
liveLine.show({
|
|
69
|
-
...drawing ? { frames: Array.from({ length: display.motion ? drawing.frames(mood) : 1 }, (_, tick) => paintMascot(drawing, {
|
|
70
|
-
mood,
|
|
71
|
-
tick,
|
|
72
|
-
label
|
|
73
|
-
})) } : {},
|
|
74
|
-
text: `${counter}${text}`,
|
|
75
|
-
suffix: time
|
|
76
|
-
}, true);
|
|
77
|
-
try {
|
|
78
|
-
const result = await work();
|
|
79
|
-
liveLine.finish(` ${styleText("green", "✓")}`, `${counter}${text} ${time()}`);
|
|
80
|
-
return result;
|
|
81
|
-
} catch (error) {
|
|
82
|
-
liveLine.finish(` ${styleText("red", "✗")}`, `${counter}${text} ${time()}`);
|
|
83
|
-
throw error;
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
return {
|
|
87
|
-
stage: (stages, index) => {
|
|
88
|
-
if (!display.verbose) return;
|
|
89
|
-
const bar = styleText("green", progressBar(index + 1, stages.length, 18));
|
|
90
|
-
liveLine.above("");
|
|
91
|
-
liveLine.above(` ${bar} ${styleText("dim", `${index + 1}/${stages.length}`)} ${styleText("bold", stages[index] ?? "")}`);
|
|
92
|
-
},
|
|
93
|
-
during,
|
|
94
|
-
say: (mood, text) => liveLine.above(display.mascot ? ` ${mascot(mood, 0, text)}${text}` : text)
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
//#endregion
|
|
98
|
-
//#region src/adapters/terminal/terminal.adapter.ts
|
|
99
|
-
const terminalOutput = { line: (line = "") => liveLine.above(line) };
|
|
100
|
-
/** Whether this process runs inside a GitHub Actions job. */
|
|
101
|
-
const onGitHubActions = () => process.env.GITHUB_ACTIONS === "true";
|
|
102
|
-
const systemClock = {
|
|
103
|
-
now: () => /* @__PURE__ */ new Date(),
|
|
104
|
-
sleep: async (ms) => {
|
|
105
|
-
await setTimeout$1(ms);
|
|
27
|
+
const install = async (context, requirement) => {
|
|
28
|
+
const { shell, files, root } = context;
|
|
29
|
+
const { label, install: how } = requirement;
|
|
30
|
+
if (!how) return `${label} missing and no install for linux`;
|
|
31
|
+
const { command } = how;
|
|
32
|
+
const status = await shell.attach(command.command, command.args, {
|
|
33
|
+
cwd: path.join(root, command.cwd ?? ""),
|
|
34
|
+
env: command.env
|
|
35
|
+
});
|
|
36
|
+
if (status !== 0) return `${label} install failed: ${commandLine(command)} exited with ${status}`;
|
|
37
|
+
if (how.path !== void 0) {
|
|
38
|
+
const dir = expand(context, how.path);
|
|
39
|
+
shell.prependPath?.(dir);
|
|
40
|
+
const githubPath = shell.env("GITHUB_PATH");
|
|
41
|
+
if (githubPath) files.append(githubPath, `${dir}\n`);
|
|
106
42
|
}
|
|
43
|
+
return await checkStatus(shell, root, requirement) === 127 ? `${label} still missing after ${commandLine(command)}` : null;
|
|
107
44
|
};
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
];
|
|
120
|
-
/** A spinner, or the mascot waiting, on one line until a listed key is pressed or `ms` pass. Ctrl-C ends the process. */
|
|
121
|
-
const waitForKey = (display, label, ms, keys) => new Promise((resolve) => {
|
|
122
|
-
const startedAt = Date.now();
|
|
123
|
-
let frame = 0;
|
|
124
|
-
const draw = () => {
|
|
125
|
-
const seconds = Math.round((Date.now() - startedAt) / 1e3);
|
|
126
|
-
const tick = frame++;
|
|
127
|
-
const glyph = display.mascot ? paintMascot(display.mascot, {
|
|
128
|
-
mood: "waiting",
|
|
129
|
-
tick: display.motion ? Math.floor(tick / 5) : 0,
|
|
130
|
-
label
|
|
131
|
-
}) : styleText("cyan", FRAMES[tick % FRAMES.length] ?? "");
|
|
132
|
-
process.stdout.write(`\r ${glyph} ${label} ${styleText("dim", `${seconds}s`)}`);
|
|
133
|
-
};
|
|
134
|
-
const timer = setInterval(draw, 80);
|
|
135
|
-
const finish = (key) => {
|
|
136
|
-
clearInterval(timer);
|
|
137
|
-
clearTimeout(timeout);
|
|
138
|
-
process.stdin.off("keypress", onKey);
|
|
139
|
-
process.stdin.setRawMode(false);
|
|
140
|
-
process.stdin.pause();
|
|
141
|
-
process.stdout.write("\r\x1B[2K");
|
|
142
|
-
resolve(key);
|
|
143
|
-
};
|
|
144
|
-
const onKey = (_text, key) => {
|
|
145
|
-
if (key?.ctrl && key.name === "c") {
|
|
146
|
-
finish(null);
|
|
147
|
-
process.stdout.write(`${styleText("dim", " Stopped waiting. release picks up right here.")}\n`);
|
|
148
|
-
process.exit(130);
|
|
149
|
-
}
|
|
150
|
-
if (key?.name && keys.includes(key.name)) finish(key.name);
|
|
151
|
-
};
|
|
152
|
-
const timeout = setTimeout(() => finish(null), ms);
|
|
153
|
-
emitKeypressEvents(process.stdin);
|
|
154
|
-
process.stdin.setRawMode(true);
|
|
155
|
-
process.stdin.resume();
|
|
156
|
-
process.stdin.on("keypress", onKey);
|
|
157
|
-
});
|
|
158
|
-
const asOptions = (choices) => choices;
|
|
159
|
-
const orNull = (answer) => isCancel(answer) ? null : answer;
|
|
160
|
-
const NO_MASCOT = {
|
|
161
|
-
verbose: false,
|
|
162
|
-
mascot: null,
|
|
163
|
-
motion: false
|
|
164
|
-
};
|
|
165
|
-
/** Questions through @clack/prompts, each owning the terminal; without one, every answer is no. */
|
|
166
|
-
const terminalPrompter = (display = NO_MASCOT) => {
|
|
167
|
-
const interactive = Boolean(process.stdin.isTTY);
|
|
168
|
-
const hold = (work) => liveLine.hold(work);
|
|
169
|
-
return {
|
|
170
|
-
interactive,
|
|
171
|
-
confirm: (question, initial = false) => hold(async () => interactive && orNull(await confirm({
|
|
172
|
-
message: question,
|
|
173
|
-
initialValue: initial
|
|
174
|
-
})) === true),
|
|
175
|
-
typed: (question, word) => hold(async () => {
|
|
176
|
-
if (!interactive) return false;
|
|
177
|
-
const prompt = createInterface({
|
|
178
|
-
input: process.stdin,
|
|
179
|
-
output: process.stdout
|
|
180
|
-
});
|
|
181
|
-
const answer = await prompt.question(`${styleText("bold", question)} `);
|
|
182
|
-
prompt.close();
|
|
183
|
-
return answer.trim() === word;
|
|
184
|
-
}),
|
|
185
|
-
select: (message, choices, initial) => hold(async () => interactive ? orNull(await select({
|
|
186
|
-
message,
|
|
187
|
-
options: asOptions(choices),
|
|
188
|
-
initialValue: initial
|
|
189
|
-
})) : null),
|
|
190
|
-
multiselect: (message, choices, initial) => hold(async () => interactive ? orNull(await multiselect({
|
|
191
|
-
message,
|
|
192
|
-
options: asOptions(choices),
|
|
193
|
-
initialValues: initial,
|
|
194
|
-
required: false
|
|
195
|
-
})) : null),
|
|
196
|
-
text: (message, initial) => hold(async () => interactive ? orNull(await text({
|
|
197
|
-
message,
|
|
198
|
-
initialValue: initial
|
|
199
|
-
})) : null),
|
|
200
|
-
waitForKey: (label, ms, keys) => hold(async () => {
|
|
201
|
-
if (interactive) return waitForKey(display, label, ms, keys);
|
|
202
|
-
await setTimeout$1(ms);
|
|
203
|
-
return null;
|
|
204
|
-
})
|
|
205
|
-
};
|
|
206
|
-
};
|
|
207
|
-
//#endregion
|
|
208
|
-
//#region src/cli/plugins.ts
|
|
209
|
-
const readJson = (file) => JSON.parse(fs.readFileSync(file, "utf8"));
|
|
210
|
-
const isRecord = (value) => typeof value === "object" && value !== null;
|
|
45
|
+
/** Each secret a requirement names that this run does not hold, as said. */
|
|
46
|
+
const missing = (context, who, requirements) => requirements.flatMap(({ label, secrets = [] }) => secrets.filter((name) => !context.shell.env(name)).map((name) => ({
|
|
47
|
+
who,
|
|
48
|
+
label,
|
|
49
|
+
name
|
|
50
|
+
})));
|
|
51
|
+
/** Every secret the picked units and the flow need that this run does not hold, in release order. */
|
|
52
|
+
const missingSecrets = (context, release, picked) => [...release.units.filter(({ name }) => picked.has(name)).flatMap((unit) => {
|
|
53
|
+
const provider = release.modules.find(({ name }) => name === unit.module)?.provider;
|
|
54
|
+
return missing(context, `${unit.name} ships with ${provider ?? unit.module}`, signInsOf(release, new Set([unit.name])));
|
|
55
|
+
}), ...requirementsOf(release, /* @__PURE__ */ new Set()).flatMap((requirement) => missing(context, `shiplane needs ${requirement.label}`, [requirement]))];
|
|
211
56
|
/**
|
|
212
|
-
*
|
|
213
|
-
*
|
|
57
|
+
* `shiplane doctor --ci`: what a runner checks before it ships, in order, stopping at the first
|
|
58
|
+
* problem: the units, the environment, each tool (installed when missing), each secret.
|
|
214
59
|
*/
|
|
215
|
-
const
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
});
|
|
223
|
-
const require = createRequire(manifestFile);
|
|
224
|
-
return [...(await Promise.all(names.map(async (name) => {
|
|
225
|
-
try {
|
|
226
|
-
const factories = readJson(require.resolve(`${name}/package.json`)).shiplane?.adapters ?? [];
|
|
227
|
-
if (factories.length === 0) return [];
|
|
228
|
-
const loaded = await import(pathToFileURL(require.resolve(name)).href);
|
|
229
|
-
if (!isRecord(loaded)) return [];
|
|
230
|
-
return factories.flatMap((factory) => {
|
|
231
|
-
const make = loaded[factory];
|
|
232
|
-
return typeof make === "function" ? [make()] : [];
|
|
233
|
-
});
|
|
234
|
-
} catch {
|
|
235
|
-
return [];
|
|
236
|
-
}
|
|
237
|
-
}))).flat(), shellServerHosting()];
|
|
238
|
-
};
|
|
239
|
-
//#endregion
|
|
240
|
-
//#region src/cli/compose.ts
|
|
241
|
-
/** Creates each port the flow runs on, for this repository. */
|
|
242
|
-
const composeServices = (release, open) => ({
|
|
243
|
-
sourceControl: open(release.flow.sourceControl),
|
|
244
|
-
codeHost: open(release.flow.codeHost),
|
|
245
|
-
ciPipeline: open(release.flow.ciPipeline),
|
|
246
|
-
versioning: open(release.flow.versioning)
|
|
247
|
-
});
|
|
248
|
-
/** Ports created on demand, in this repository, through this shell. */
|
|
249
|
-
const opener = (root, shell) => (adapter) => adapter.create({
|
|
250
|
-
root,
|
|
251
|
-
shell
|
|
252
|
-
});
|
|
253
|
-
/** A context wired to this machine: its shell, its terminal, its clock, unless `io` says otherwise. */
|
|
254
|
-
const composeContext = (release, { yes, display: flags }, io = {}) => {
|
|
255
|
-
const ci = onGitHubActions() || systemShell.env("CI") === "true";
|
|
256
|
-
const tty = Boolean(process.stdout.isTTY);
|
|
257
|
-
const display = resolveDisplay(release.display ?? {}, flags, {
|
|
258
|
-
tty,
|
|
259
|
-
ci,
|
|
260
|
-
noMotion: Boolean(systemShell.env("NO_MOTION"))
|
|
261
|
-
});
|
|
262
|
-
const shell = io.shell ?? systemShell;
|
|
263
|
-
const output = io.output ?? terminalOutput;
|
|
264
|
-
const open = opener(release.root, shell);
|
|
265
|
-
return {
|
|
266
|
-
release,
|
|
267
|
-
load: () => loadRelease(release.root, { aliases: io.aliases }),
|
|
268
|
-
services: composeServices(release, open),
|
|
269
|
-
open,
|
|
270
|
-
prompter: io.prompter ?? terminalPrompter(display),
|
|
271
|
-
output,
|
|
272
|
-
progress: io.progress ?? terminalProgress(display, tty && !ci),
|
|
273
|
-
clock: systemClock,
|
|
274
|
-
shell,
|
|
275
|
-
options: {
|
|
276
|
-
yes,
|
|
277
|
-
ci: onGitHubActions()
|
|
278
|
-
}
|
|
279
|
-
};
|
|
280
|
-
};
|
|
281
|
-
/** What init, add, doctor and the rest need: the repository on disk and the adapters installed. */
|
|
282
|
-
const composeSetup = async (root, io = {}) => {
|
|
283
|
-
const ci = onGitHubActions() || systemShell.env("CI") === "true";
|
|
284
|
-
const tty = Boolean(process.stdout.isTTY);
|
|
285
|
-
const display = resolveDisplay({}, { mascot: false }, {
|
|
286
|
-
tty,
|
|
287
|
-
ci,
|
|
288
|
-
noMotion: Boolean(systemShell.env("NO_MOTION"))
|
|
289
|
-
});
|
|
290
|
-
return {
|
|
291
|
-
root,
|
|
292
|
-
files: nodeFiles(root),
|
|
293
|
-
shell: systemShell,
|
|
294
|
-
prompter: terminalPrompter(),
|
|
295
|
-
output: terminalOutput,
|
|
296
|
-
adapters: io.adapters ?? await installedAdapters(root),
|
|
297
|
-
load: () => loadRelease(root),
|
|
298
|
-
progress: terminalProgress(display, tty && !ci),
|
|
299
|
-
compose: (release) => composeContext(release, {
|
|
300
|
-
yes: true,
|
|
301
|
-
display: { mascot: false }
|
|
302
|
-
}),
|
|
303
|
-
...io
|
|
60
|
+
const doctorCi = async (context, { units, channel }) => {
|
|
61
|
+
const { output, shell, root } = context;
|
|
62
|
+
const passed = (check, detail) => output.line(`${paint("green", "✓")} ${check} ${paint("dim", detail)}`);
|
|
63
|
+
const stop = (problem) => {
|
|
64
|
+
output.line(`${paint("red", "✗")} ${problem}`);
|
|
65
|
+
output.line(` ${paint("dim", WORKFLOW_DOCS)}`);
|
|
66
|
+
return false;
|
|
304
67
|
};
|
|
68
|
+
const release = await context.load();
|
|
69
|
+
const [problem] = release.problems;
|
|
70
|
+
if (problem) return stop(`${problem.line === void 0 ? problem.file : `${problem.file}:${problem.line}`}: ${problem.message}`);
|
|
71
|
+
const known = release.units.map(({ name }) => name);
|
|
72
|
+
const named = unitsSchema(known).safeParse(units.length > 0 ? units : known);
|
|
73
|
+
if (!named.success) return stop(problemOf(named.error));
|
|
74
|
+
passed("units", named.data.join(", "));
|
|
75
|
+
const environment = environmentSchema.safeParse(channel);
|
|
76
|
+
if (!environment.success) return stop(problemOf(environment.error));
|
|
77
|
+
passed("environment", environment.data);
|
|
78
|
+
const picked = new Set(named.data);
|
|
79
|
+
for (const requirement of requirementsOf(release, picked)) {
|
|
80
|
+
const found = await checkStatus(shell, root, requirement) !== 127;
|
|
81
|
+
const problem = found ? null : await install(context, requirement);
|
|
82
|
+
if (problem) return stop(problem);
|
|
83
|
+
passed(requirement.label, found ? "installed" : "installed now");
|
|
84
|
+
}
|
|
85
|
+
const [absent] = missingSecrets(context, release, picked);
|
|
86
|
+
if (absent) return stop(`${absent.who}: ${absent.name} missing in "${environment.data}"`);
|
|
87
|
+
const secrets = requirementsOf(release, picked).flatMap(({ secrets = [] }) => secrets);
|
|
88
|
+
passed("secrets", secrets.length > 0 ? [...new Set(secrets)].join(", ") : "none needed");
|
|
89
|
+
return true;
|
|
305
90
|
};
|
|
306
91
|
//#endregion
|
|
307
92
|
//#region src/cli/findRoot.ts
|
|
@@ -316,7 +101,6 @@ const findRoot = (from) => {
|
|
|
316
101
|
};
|
|
317
102
|
//#endregion
|
|
318
103
|
//#region src/cli/output.ts
|
|
319
|
-
const paint = (style, text) => styleText(style, text);
|
|
320
104
|
const out = (line = "") => process.stdout.write(`${line}\n`);
|
|
321
105
|
/** Problems as `file:line message`, each hint on the line below. */
|
|
322
106
|
const printProblems = (problems) => {
|
|
@@ -410,33 +194,66 @@ const statusCommand = async (context, { environment, json }) => {
|
|
|
410
194
|
};
|
|
411
195
|
//#endregion
|
|
412
196
|
//#region src/cli/main.ts
|
|
197
|
+
/** What `shiplane help` shows: the commands a person runs day to day, and where the rest are. */
|
|
198
|
+
const SHORT_HELP = `${paint("bold", "shiplane")}: detect what changed, version it, trigger each app's deploy.
|
|
199
|
+
|
|
200
|
+
shiplane the next step to preview: release PR, merge, tags, ship
|
|
201
|
+
shiplane promote production, from what preview runs
|
|
202
|
+
shiplane test-release [channel] publish what the changesets release for testers: a snapshot, or beta, nightly…
|
|
203
|
+
shiplane status where every unit stands, and what to run next
|
|
204
|
+
shiplane setup set up releases, or add an app
|
|
205
|
+
shiplane doctor check the config, tools and sign-ins, offer each fix
|
|
206
|
+
shiplane docs <name> every key a module's or an adapter's unit files take
|
|
207
|
+
|
|
208
|
+
shiplane help all every command and flag: version, tag, ship, remove and the rest
|
|
209
|
+
`;
|
|
413
210
|
const HELP = `${paint("bold", "shiplane")}: detect what changed, version it, trigger each app's deploy.
|
|
414
211
|
|
|
415
212
|
shiplane the next step to preview: release PR, merge, tags, ship
|
|
213
|
+
(on a branch: a test release, asked first)
|
|
214
|
+
shiplane test-release [channel] publish what the changesets release for testers, npm packages only:
|
|
215
|
+
a snapshot (0.6.0-main.329aafb) or a numbered channel (0.6.0-beta.2)
|
|
416
216
|
shiplane promote production, from what preview runs (--channel production too)
|
|
417
217
|
shiplane status [--json] where every unit stands, and what to run next
|
|
418
218
|
shiplane version open the release PR for what is pending
|
|
419
219
|
shiplane tag tag merged versions and publish their release notes
|
|
420
220
|
shiplane ship [unit...] trigger each tagged unit's deploy, then return
|
|
421
|
-
shiplane plan every command a ship would run, run nothing
|
|
422
221
|
shiplane plugins [--json] the flow, the modules in release order and who uses each, the features
|
|
423
222
|
|
|
424
|
-
shiplane setup [--yes] set up or
|
|
425
|
-
|
|
426
|
-
shiplane add <folder> init's questions for one folder
|
|
223
|
+
shiplane setup [--yes] set up, check, or add an app: asks only what it can't tell, rehearses, then writes
|
|
224
|
+
(shiplane init and shiplane add are now setup; both still run for now)
|
|
427
225
|
shiplane remove <unit> stop shipping a unit; it stays versioned
|
|
428
226
|
shiplane doctor check the config, tools and sign-ins, offer each fix
|
|
227
|
+
shiplane doctor --ci [unit...] on a runner: units, --channel, tools (installed when missing), secrets
|
|
429
228
|
shiplane adapter new <name> scaffold a server hosting adapter, its contract test and its module
|
|
430
229
|
shiplane docs <name> every key a module's or an adapter's unit files take
|
|
431
|
-
shiplane help
|
|
230
|
+
shiplane help [all] the main commands; all: this, every command and flag
|
|
432
231
|
|
|
433
232
|
--channel preview|production where status reads (preview by default)
|
|
434
|
-
--via
|
|
233
|
+
--via ci|local ship through the CI pipeline (such as GitHub Actions) or this machine, without asking
|
|
435
234
|
--yes answer yes to every question (never on production)
|
|
235
|
+
--dry-run with shiplane, ship or promote: every command it would run, run nothing;
|
|
236
|
+
with test-release: each package's version and npm tag, publish nothing
|
|
237
|
+
(shiplane plan before)
|
|
436
238
|
--verbose / --no-verbose say each thing it reads and runs, with a progress bar (on by default)
|
|
437
239
|
--mascot / --no-mascot the mascot beside it, still in CI or under NO_MOTION=1 (on by default)
|
|
438
240
|
Both defaults live in shiplane.config.ts: display: { verbose, mascot }
|
|
439
241
|
`;
|
|
242
|
+
/** The commands `--dry-run` previews instead of running. */
|
|
243
|
+
const DRY_RUNS = new Set([
|
|
244
|
+
"next",
|
|
245
|
+
"ship",
|
|
246
|
+
"promote"
|
|
247
|
+
]);
|
|
248
|
+
/** --via ci|local; the older --via github still means the CI pipeline, said once. */
|
|
249
|
+
const viaFlag = (value) => {
|
|
250
|
+
if (value === void 0) return void 0;
|
|
251
|
+
if (value === "github") {
|
|
252
|
+
out(paint("dim", "--via github is now --via ci: the flow's CI pipeline"));
|
|
253
|
+
return "ci";
|
|
254
|
+
}
|
|
255
|
+
return z.enum(["ci", "local"]).parse(value);
|
|
256
|
+
};
|
|
440
257
|
/** The CLI as a person runs it, from its arguments and folder; resolves to its exit code. */
|
|
441
258
|
const runCli = async (argv, cwd, io = {}) => {
|
|
442
259
|
const { values, positionals } = parseArgs({
|
|
@@ -446,6 +263,10 @@ const runCli = async (argv, cwd, io = {}) => {
|
|
|
446
263
|
options: {
|
|
447
264
|
verbose: { type: "boolean" },
|
|
448
265
|
mascot: { type: "boolean" },
|
|
266
|
+
"dry-run": {
|
|
267
|
+
type: "boolean",
|
|
268
|
+
default: false
|
|
269
|
+
},
|
|
449
270
|
json: {
|
|
450
271
|
type: "boolean",
|
|
451
272
|
default: false
|
|
@@ -463,14 +284,25 @@ const runCli = async (argv, cwd, io = {}) => {
|
|
|
463
284
|
blank: {
|
|
464
285
|
type: "boolean",
|
|
465
286
|
default: false
|
|
287
|
+
},
|
|
288
|
+
ci: {
|
|
289
|
+
type: "boolean",
|
|
290
|
+
default: false
|
|
466
291
|
}
|
|
467
292
|
}
|
|
468
293
|
});
|
|
469
294
|
const [command = "next", ...units] = positionals;
|
|
470
|
-
const environment = z.enum(ENVIRONMENTS).parse(values.channel);
|
|
471
|
-
const via =
|
|
295
|
+
const environment = command === "doctor" ? "preview" : z.enum(ENVIRONMENTS).parse(values.channel);
|
|
296
|
+
const via = viaFlag(values.via);
|
|
297
|
+
const testRelease = {
|
|
298
|
+
onDefault: "publish",
|
|
299
|
+
dryRun: values["dry-run"],
|
|
300
|
+
...units[0] === void 0 ? {} : { channel: units[0] }
|
|
301
|
+
};
|
|
472
302
|
const commands = {
|
|
473
|
-
next: (context) => environment === "preview" ?
|
|
303
|
+
next: (context) => environment === "preview" ? branchRelease(context, { onDefault: "release" }) : promote(context, via),
|
|
304
|
+
"test-release": (context) => branchRelease(context, testRelease),
|
|
305
|
+
branch: (context) => branchRelease(context, testRelease),
|
|
474
306
|
promote: (context) => promote(context, via),
|
|
475
307
|
status: (context) => statusCommand(context, {
|
|
476
308
|
environment,
|
|
@@ -486,7 +318,10 @@ const runCli = async (argv, cwd, io = {}) => {
|
|
|
486
318
|
via,
|
|
487
319
|
...units.length > 0 ? { scope: new Set(units) } : {}
|
|
488
320
|
}),
|
|
489
|
-
plan: (context) =>
|
|
321
|
+
plan: (context) => {
|
|
322
|
+
out(paint("dim", "plan is now --dry-run: shiplane ship --dry-run, shiplane promote --dry-run"));
|
|
323
|
+
return planShips(context, environment);
|
|
324
|
+
},
|
|
490
325
|
plugins: (context) => Promise.resolve(pluginsCommand(context.release, { json: values.json }))
|
|
491
326
|
};
|
|
492
327
|
const [first = ""] = units;
|
|
@@ -500,9 +335,15 @@ const runCli = async (argv, cwd, io = {}) => {
|
|
|
500
335
|
out(paint("dim", "init is now shiplane setup"));
|
|
501
336
|
return setup(context, { yes: values.yes });
|
|
502
337
|
},
|
|
503
|
-
add: (context) =>
|
|
338
|
+
add: (context) => {
|
|
339
|
+
out(paint("dim", "add is now shiplane setup: run it again to add an app"));
|
|
340
|
+
return addUnit(context, first);
|
|
341
|
+
},
|
|
504
342
|
remove: (context) => removeUnit(context, first),
|
|
505
|
-
doctor: (context) =>
|
|
343
|
+
doctor: (context) => values.ci ? doctorCi(context, {
|
|
344
|
+
units,
|
|
345
|
+
channel: values.channel
|
|
346
|
+
}) : doctor(context, { yes: values.yes }),
|
|
506
347
|
adapter: (context) => {
|
|
507
348
|
if (first === "new" && units[1]) return newAdapter(context, units[1]);
|
|
508
349
|
out(`${paint("red", "✗")} shiplane adapter new <name>`);
|
|
@@ -513,11 +354,17 @@ const runCli = async (argv, cwd, io = {}) => {
|
|
|
513
354
|
const root = findRoot(cwd);
|
|
514
355
|
const files = io.setup?.files ?? nodeFiles(root);
|
|
515
356
|
const firstRun = command === "next" && !files.exists("shiplane.config.ts");
|
|
516
|
-
const run = commands[command];
|
|
357
|
+
const run = values["dry-run"] && DRY_RUNS.has(command) ? (context) => planShips(context, command === "promote" ? "production" : environment) : commands[command];
|
|
517
358
|
const setUp = setupCommands[firstRun ? "setup" : command];
|
|
518
|
-
if (setUp)
|
|
359
|
+
if (setUp) {
|
|
360
|
+
const load = () => loadReleaseOnDisk(root, { aliases: io.aliases });
|
|
361
|
+
return await setUp(await composeSetup(root, {
|
|
362
|
+
load,
|
|
363
|
+
...io.setup
|
|
364
|
+
})) ? 0 : 1;
|
|
365
|
+
}
|
|
519
366
|
if (command === "help") {
|
|
520
|
-
out(HELP);
|
|
367
|
+
out(first === "all" ? HELP : SHORT_HELP);
|
|
521
368
|
return 0;
|
|
522
369
|
}
|
|
523
370
|
if (!run) {
|
|
@@ -525,7 +372,7 @@ const runCli = async (argv, cwd, io = {}) => {
|
|
|
525
372
|
out(HELP);
|
|
526
373
|
return 1;
|
|
527
374
|
}
|
|
528
|
-
const release = await
|
|
375
|
+
const release = await loadReleaseOnDisk(root, { aliases: io.aliases });
|
|
529
376
|
if (release.problems.length > 0) {
|
|
530
377
|
printProblems(release.problems);
|
|
531
378
|
return 2;
|