shiplane 0.1.0 → 0.2.0
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/{budget-C8_aayQk.js → budget-BqtW-Ekk.js} +53 -26
- package/dist/budget-BqtW-Ekk.js.map +1 -0
- package/dist/cli.js +81 -36
- package/dist/cli.js.map +1 -1
- package/dist/display-IqkJ6uCw.js +96 -0
- package/dist/display-IqkJ6uCw.js.map +1 -0
- package/dist/index-D4qsXAis.d.ts +214 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +4 -3
- package/dist/{issues-C5fKq1Jv.js → issues-TcWtMTv5.js} +1 -1
- package/dist/{issues-C5fKq1Jv.js.map → issues-TcWtMTv5.js.map} +1 -1
- package/dist/memory.d.ts +2 -0
- package/dist/memory.js +2 -0
- package/dist/package-registry.fake-CC37ptzf.d.ts +444 -0
- package/dist/package-registry.fake-Ciqc4ujx.js +633 -0
- package/dist/package-registry.fake-Ciqc4ujx.js.map +1 -0
- package/dist/perEnv-B7AiYnW_.js +11 -0
- package/dist/perEnv-B7AiYnW_.js.map +1 -0
- package/dist/plugin.d.ts +13 -5
- package/dist/plugin.js +7 -6
- package/dist/{readStatus-D5YVR5ZC.js → readStatus-YTZXH_Hh.js} +1387 -519
- package/dist/readStatus-YTZXH_Hh.js.map +1 -0
- package/dist/{shell-server-hosting.adapter-Bgl6-IWw.js → shell-server-hosting.adapter-DobfDqFm.js} +2 -2
- package/dist/{shell-server-hosting.adapter-Bgl6-IWw.js.map → shell-server-hosting.adapter-DobfDqFm.js.map} +1 -1
- package/dist/{src-Dlr2Sgs8.js → src-CGASfBy2.js} +3 -3
- package/dist/{src-Dlr2Sgs8.js.map → src-CGASfBy2.js.map} +1 -1
- package/dist/{index-QneBUiDD.d.ts → static-hosting.port-mknLsxwR.d.ts} +61 -244
- package/dist/{tags-DL74ni09.d.ts → tags-Bn3JrgPI.d.ts} +1 -1
- package/dist/testing.d.ts +61 -468
- package/dist/testing.js +11 -625
- package/dist/testing.js.map +1 -1
- package/dist/{web-app.module-Bw-npC4Z.js → web-app.module-6KrXIU7j.js} +4 -11
- package/dist/web-app.module-6KrXIU7j.js.map +1 -0
- package/package.json +6 -1
- package/dist/budget-C8_aayQk.js.map +0 -1
- package/dist/display-DM0xtQbT.js +0 -55
- package/dist/display-DM0xtQbT.js.map +0 -1
- package/dist/readStatus-D5YVR5ZC.js.map +0 -1
- package/dist/web-app.module-Bw-npC4Z.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as releaseFlow, i as backendService, n as publishedPackage, r as mobileApp, t as webApp } from "./web-app.module-
|
|
2
|
-
import { C as changelogSection, D as tagName, E as releaseTags, O as expandPatterns, S as cameWithRelease, a as
|
|
1
|
+
import { a as releaseFlow, i as backendService, n as publishedPackage, r as mobileApp, t as webApp } from "./web-app.module-6KrXIU7j.js";
|
|
2
|
+
import { C as changelogSection, D as tagName, E as releaseTags, O as expandPatterns, S as cameWithRelease, a as CommandFailed, c as onlyVersionFiles, d as appBumps, f as changesetApps, g as unreleasedChangesets, h as unreleasedApps, i as minutesBudget, k as workspacePatterns, l as shipsFrom, m as splitChangesets, o as deployRunTitle, p as packageBumps, r as deployEstimate, u as webShip, w as firstRelease, x as DEFAULT_TAG_FORMAT, y as releaseSource } from "./budget-BqtW-Ekk.js";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { styleText } from "node:util";
|
|
5
5
|
import fs from "node:fs";
|
|
@@ -8,6 +8,7 @@ import { Document, LineCounter, isMap, isScalar, isSeq, parseDocument } from "ya
|
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
9
|
import { createJiti } from "jiti";
|
|
10
10
|
import { execFile, spawn } from "node:child_process";
|
|
11
|
+
import ora from "ora";
|
|
11
12
|
//#region src/adapters/files/node-files.adapter.ts
|
|
12
13
|
/** The repository on disk, under `root`. */
|
|
13
14
|
const nodeFiles = (root) => {
|
|
@@ -20,7 +21,8 @@ const nodeFiles = (root) => {
|
|
|
20
21
|
fs.writeFileSync(at(file), text);
|
|
21
22
|
},
|
|
22
23
|
remove: (file) => fs.rmSync(at(file), { force: true }),
|
|
23
|
-
list: (dir) => fs.existsSync(at(dir)) ? fs.readdirSync(at(dir)) : []
|
|
24
|
+
list: (dir) => fs.existsSync(at(dir)) ? fs.readdirSync(at(dir)) : [],
|
|
25
|
+
folders: (dir) => fs.existsSync(at(dir)) ? fs.readdirSync(at(dir), { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name) : []
|
|
24
26
|
};
|
|
25
27
|
};
|
|
26
28
|
//#endregion
|
|
@@ -136,6 +138,7 @@ const keysAt = (schema, at) => {
|
|
|
136
138
|
/** What a unit file naming this module may hold: `module`, then its adapter's settings. */
|
|
137
139
|
const unitSchema = (module) => z.strictObject({
|
|
138
140
|
module: z.literal(module.name).describe(`The module that ships this app, with ${module.provider}`),
|
|
141
|
+
buildCommand: z.string().optional().describe("How to build this app, when its package.json has no \"build\" script"),
|
|
139
142
|
...mapShape(module.settings.shape, deepStrict)
|
|
140
143
|
});
|
|
141
144
|
/** The JSON Schema editors read for `shiplane.unit.yml`: the module an app names picks its keys. */
|
|
@@ -230,10 +233,13 @@ const readUnitFile = (file, text, modules, features = []) => {
|
|
|
230
233
|
if (!module) return problem(file, lineAt(["module"]), `no module named "${named}" in shiplane.config.ts`, didYouMean(named, names) ?? oneOf);
|
|
231
234
|
const parsed = unitSchema(module).safeParse(data);
|
|
232
235
|
if (!parsed.success) return { problems: parsed.error.issues.flatMap((issue) => describeIssue(issue, file, module, lineAt)) };
|
|
236
|
+
const options = Object.fromEntries(Object.entries(data).filter(([key]) => key !== "module" && key !== "buildCommand"));
|
|
237
|
+
const buildCommand = typeof data.buildCommand === "string" ? data.buildCommand : void 0;
|
|
233
238
|
return {
|
|
234
239
|
unit: {
|
|
235
240
|
module: named,
|
|
236
|
-
|
|
241
|
+
...buildCommand ? { buildCommand } : {},
|
|
242
|
+
options,
|
|
237
243
|
lineOf: (at) => lineAt(at)
|
|
238
244
|
},
|
|
239
245
|
problems: []
|
|
@@ -267,6 +273,8 @@ const confirm = async ({ prompter, options, output }, question, initial = false)
|
|
|
267
273
|
};
|
|
268
274
|
/** `api`, `api and admin`, `api, admin and landing`. */
|
|
269
275
|
const listed = (names) => names.length < 2 ? names.join("") : `${names.slice(0, -1).join(", ")} and ${names.slice(-1).join("")}`;
|
|
276
|
+
/** The keys a screen offers, each the same way: `d see the diff o open it on GitHub`. */
|
|
277
|
+
const keyHints = (hints) => hints.map(({ key, label }) => `${paint("cyan", key)} ${paint("dim", label)}`).join(" ");
|
|
270
278
|
//#endregion
|
|
271
279
|
//#region src/domain/codeScope.ts
|
|
272
280
|
const NOT_SHIPPED = [
|
|
@@ -520,16 +528,37 @@ const releasePackage = (files) => {
|
|
|
520
528
|
...manifest.devDependencies
|
|
521
529
|
} ? "shiplane" : INSTALLED;
|
|
522
530
|
};
|
|
523
|
-
/** The flow init writes: git, GitHub, GitHub Actions and changesets, each from its plugin. */
|
|
524
|
-
const FLOW_PLUGINS = {
|
|
525
|
-
git: ["gitSourceControl"],
|
|
526
|
-
github: ["gitHubActionsCiPipeline", "gitHubCodeHost"],
|
|
527
|
-
changesets: ["changesetsVersioning"]
|
|
528
|
-
};
|
|
529
531
|
const importLine = (names, from) => `import { ${[...new Set(names)].sort().join(", ")} } from "${from}";`;
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
532
|
+
const FLOW_PORTS = [
|
|
533
|
+
"sourceControl",
|
|
534
|
+
"codeHost",
|
|
535
|
+
"ciPipeline",
|
|
536
|
+
"versioning"
|
|
537
|
+
];
|
|
538
|
+
/** The flow init writes when nothing else is chosen: git, GitHub, GitHub Actions, changesets. */
|
|
539
|
+
const DEFAULT_FLOW = {
|
|
540
|
+
sourceControl: {
|
|
541
|
+
factory: "gitSourceControl",
|
|
542
|
+
from: pluginPackage("git")
|
|
543
|
+
},
|
|
544
|
+
codeHost: {
|
|
545
|
+
factory: "gitHubCodeHost",
|
|
546
|
+
from: pluginPackage("github")
|
|
547
|
+
},
|
|
548
|
+
ciPipeline: {
|
|
549
|
+
factory: "gitHubActionsCiPipeline",
|
|
550
|
+
from: pluginPackage("github")
|
|
551
|
+
},
|
|
552
|
+
versioning: {
|
|
553
|
+
factory: "changesetsVersioning",
|
|
554
|
+
from: pluginPackage("changesets")
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
/** A root config with this flow (today's by default) and these modules, in the order given. */
|
|
558
|
+
const renderConfig = (entries, pkg = INSTALLED, flow = DEFAULT_FLOW, units) => {
|
|
559
|
+
const byPlugin = /* @__PURE__ */ new Map();
|
|
560
|
+
const add = (from, name) => byPlugin.set(from, [...byPlugin.get(from) ?? [], name]);
|
|
561
|
+
FLOW_PORTS.forEach((port) => add(flow[port].from, flow[port].factory));
|
|
533
562
|
const own = [
|
|
534
563
|
"defineRelease",
|
|
535
564
|
"releaseFlow",
|
|
@@ -537,19 +566,19 @@ const renderConfig = (entries, pkg = INSTALLED) => {
|
|
|
537
566
|
];
|
|
538
567
|
entries.forEach(({ adapter, from }) => {
|
|
539
568
|
if (from === pkg) own.push(adapter);
|
|
540
|
-
else
|
|
569
|
+
else add(from, adapter);
|
|
541
570
|
});
|
|
571
|
+
const local = (from) => from.startsWith(".");
|
|
542
572
|
return [
|
|
543
573
|
importLine(own, pkg),
|
|
544
|
-
...[...byPlugin].sort(([a], [b]) => a.localeCompare(b)).map(([from, names]) => importLine(names, from)),
|
|
574
|
+
...[...byPlugin].filter(([from]) => !local(from)).sort(([a], [b]) => a.localeCompare(b)).map(([from, names]) => importLine(names, from)),
|
|
575
|
+
...[...byPlugin].filter(([from]) => local(from)).sort(([a], [b]) => a.localeCompare(b)).map(([from, names]) => importLine(names, from)),
|
|
545
576
|
"",
|
|
546
577
|
"export default defineRelease({",
|
|
547
578
|
" flow: releaseFlow({",
|
|
548
|
-
|
|
549
|
-
" codeHost: gitHubCodeHost(),",
|
|
550
|
-
" ciPipeline: gitHubActionsCiPipeline(),",
|
|
551
|
-
" versioning: changesetsVersioning(),",
|
|
579
|
+
...FLOW_PORTS.map((port) => ` ${port}: ${flow[port].factory}(),`),
|
|
552
580
|
" }),",
|
|
581
|
+
...units ? [` units: [${units.map((unit) => JSON.stringify(unit)).join(", ")}],`] : [],
|
|
553
582
|
" // What gets released, in this order. The first app is the repository's Latest release.",
|
|
554
583
|
" modules: [",
|
|
555
584
|
...entries.map((entry) => ` ${moduleCall(entry)},`),
|
|
@@ -1121,12 +1150,19 @@ const readConfig = async (file, aliases) => {
|
|
|
1121
1150
|
units,
|
|
1122
1151
|
display: {
|
|
1123
1152
|
verbose: flag(display.verbose),
|
|
1124
|
-
mascot:
|
|
1153
|
+
mascot: mascotOf(display.mascot)
|
|
1125
1154
|
},
|
|
1126
1155
|
tagFormat: tagFormatOf(loaded.tag),
|
|
1127
1156
|
releasesCommits: releasesCommitsOf(loaded.commitsWithoutChangeset)
|
|
1128
1157
|
};
|
|
1129
1158
|
};
|
|
1159
|
+
/** A config's mascot: true, false, frames per mood, or a function; anything else is ignored. */
|
|
1160
|
+
const mascotOf = (value) => {
|
|
1161
|
+
if (typeof value === "boolean" || typeof value === "function") return value;
|
|
1162
|
+
if (!isRecord(value)) return void 0;
|
|
1163
|
+
const frames = Object.entries(value).filter(([, list]) => Array.isArray(list) && list.every((frame) => typeof frame === "string"));
|
|
1164
|
+
return frames.length > 0 ? Object.fromEntries(frames) : void 0;
|
|
1165
|
+
};
|
|
1130
1166
|
/** Apps in release order: by module as the config lists them, then by name. */
|
|
1131
1167
|
const inReleaseOrder = (read, modules) => {
|
|
1132
1168
|
const rank = (unit) => modules.findIndex(({ name }) => name === unit.module);
|
|
@@ -1206,6 +1242,7 @@ const loadRelease = async (root, options = {}) => {
|
|
|
1206
1242
|
packageName: manifest.name,
|
|
1207
1243
|
version: manifest.version,
|
|
1208
1244
|
module: result.unit.module,
|
|
1245
|
+
...result.unit.buildCommand ? { buildCommand: result.unit.buildCommand } : {},
|
|
1209
1246
|
options: result.unit.options,
|
|
1210
1247
|
after: []
|
|
1211
1248
|
},
|
|
@@ -1361,13 +1398,69 @@ const sentence = (items) => items.length < 2 ? items.join("") : `${items.slice(0
|
|
|
1361
1398
|
const MAX_LINE = 100;
|
|
1362
1399
|
/** One app's release commit: `chore(api): release v0.0.4`. */
|
|
1363
1400
|
const releaseCommitTitle = ({ app, to }) => `chore(${app}): release v${to}`;
|
|
1364
|
-
|
|
1365
|
-
const
|
|
1401
|
+
MAX_LINE - 9;
|
|
1402
|
+
const counted = (count, word) => `${count} ${word}${count === 1 ? "" : "s"}`;
|
|
1403
|
+
/** What a title calls a unit of each module kind; several kinds at once are apps. */
|
|
1404
|
+
const NOUN = {
|
|
1405
|
+
"published-package": "package",
|
|
1406
|
+
"backend-service": "service",
|
|
1407
|
+
"web-app": "web app",
|
|
1408
|
+
"mobile-app": "mobile app",
|
|
1409
|
+
"internal-tool": "tool"
|
|
1410
|
+
};
|
|
1411
|
+
/**
|
|
1412
|
+
* The apps, gathered into families in their own order: a root moving with its `root-*` apps
|
|
1413
|
+
* (`shiplane`, `shiplane-npm`) is one family; any other app is a family of one.
|
|
1414
|
+
*/
|
|
1415
|
+
const releaseFamilies = (bumps) => {
|
|
1416
|
+
return bumps.filter(({ app }) => !bumps.some((other) => other.app !== app && app.startsWith(`${other.app}-`))).map((root) => bumps.filter(({ app }) => app === root.app || app.startsWith(`${root.app}-`)));
|
|
1417
|
+
};
|
|
1418
|
+
/** One family as a title names it: `api v0.0.4`, `shiplane and 7 plugins v0.1.0`, `api v0.3.0 and 2 more services`. */
|
|
1419
|
+
const familyLabel = ([root, ...members], kindOf) => {
|
|
1420
|
+
if (!root) return "";
|
|
1421
|
+
if (members.length < 2) return [root, ...members].map(({ app, to }) => `${app} v${to}`).join(", ");
|
|
1422
|
+
const kinds = new Set([root, ...members].map(({ app }) => kindOf(app)));
|
|
1423
|
+
const [kind] = kinds;
|
|
1424
|
+
const noun = kinds.size === 1 && kind && NOUN[kind] || "app";
|
|
1425
|
+
const rest = noun === "package" ? counted(members.length, "plugin") : `${members.length} more ${counted(members.length, noun).replace(/^\d+ /, "")}`;
|
|
1426
|
+
return members.every(({ to }) => to === root.to) ? `${root.app} and ${rest} v${root.to}` : `${root.app} v${root.to} and ${rest}`;
|
|
1427
|
+
};
|
|
1428
|
+
/**
|
|
1429
|
+
* The release PRs a release opens, all from main at once: one per app, a family counting as one.
|
|
1430
|
+
* Apps `linked` (one changeset naming both, or one moving with the other) share a PR, so no two
|
|
1431
|
+
* PRs ever touch the same file.
|
|
1432
|
+
*/
|
|
1433
|
+
const releasePrGroups = (bumps, linked) => {
|
|
1434
|
+
const groups = releaseFamilies(bumps).map((family) => new Set(family.map(({ app }) => app)));
|
|
1435
|
+
const merged = linked.reduce((current, apps) => {
|
|
1436
|
+
const touched = current.filter((group) => apps.some((app) => group.has(app)));
|
|
1437
|
+
if (touched.length < 2) return current;
|
|
1438
|
+
const union = new Set(touched.flatMap((group) => [...group]));
|
|
1439
|
+
return [...current.filter((group) => !touched.includes(group)), union];
|
|
1440
|
+
}, groups);
|
|
1441
|
+
const order = (group) => bumps.findIndex(({ app }) => group.has(app));
|
|
1442
|
+
return merged.sort((left, right) => order(left) - order(right)).map((group) => bumps.filter(({ app }) => group.has(app)));
|
|
1443
|
+
};
|
|
1444
|
+
/** Whether a title still fits once a squash merge appends its PR number. */
|
|
1445
|
+
const titleFits = (title) => title.length <= 91;
|
|
1446
|
+
/**
|
|
1447
|
+
* Conventional, and naming every app it brings, never a bare count: `chore(api): release v0.0.4`,
|
|
1448
|
+
* `chore(release): api v0.0.2 and admin v0.1.0`, or, when listing each one is too long, families
|
|
1449
|
+
* by their root: `chore(release): shiplane and 7 plugins v0.1.0, landing v1.2.0 and expo v2.1.0`.
|
|
1450
|
+
* One release is one PR: a title too long even then stays whole, see `titleFits`.
|
|
1451
|
+
*/
|
|
1452
|
+
const releaseTitle = (bumps, kindOf = () => void 0) => {
|
|
1366
1453
|
const [first, ...others] = bumps;
|
|
1367
1454
|
if (!first) return "chore(release): package changelogs";
|
|
1368
1455
|
if (others.length === 0) return releaseCommitTitle(first);
|
|
1369
|
-
const
|
|
1370
|
-
|
|
1456
|
+
const families = releaseFamilies(bumps);
|
|
1457
|
+
const [only] = families;
|
|
1458
|
+
if (families.length === 1 && only?.[0]) return releaseCommitTitle(only[0]);
|
|
1459
|
+
const every = `chore(release): ${sentence(bumps.map(({ app, to }) => `${app} v${to}`))}`;
|
|
1460
|
+
if (titleFits(every)) return every;
|
|
1461
|
+
families.sort((left, right) => Number(right.length > 1) - Number(left.length > 1));
|
|
1462
|
+
const labels = families.map((family) => familyLabel(family, kindOf));
|
|
1463
|
+
return `chore(release): ${labels.at(-1)?.includes(" and ") ? labels.join(", ") : sentence(labels)}`;
|
|
1371
1464
|
};
|
|
1372
1465
|
/** A bullet wrapped to commitlint's 100-character body lines, continued under its text. */
|
|
1373
1466
|
const bullet = (text) => text.split(" ").reduce((lines, word) => {
|
|
@@ -1454,193 +1547,448 @@ const WAIT_KEYS = {
|
|
|
1454
1547
|
/** What a key does while the release waits for its pull request to merge. */
|
|
1455
1548
|
const waitKey = (name) => name && WAIT_KEYS[name] || null;
|
|
1456
1549
|
//#endregion
|
|
1457
|
-
//#region src/
|
|
1458
|
-
|
|
1459
|
-
const
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
const
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
await context.progress.during(`undo: ${undo.label}`, "working", undo.run);
|
|
1476
|
-
} catch (error) {
|
|
1477
|
-
left.push(undo);
|
|
1478
|
-
context.progress.say("worried", `${paint("red", "✗")} undo ${undo.label}: ${reasonOf$1(error)}`);
|
|
1479
|
-
}
|
|
1480
|
-
if (left.length === 0 && kept.length === 0) {
|
|
1481
|
-
context.progress.say("resting", paint("dim", "Cancelled: everything this run did is undone."));
|
|
1482
|
-
return;
|
|
1550
|
+
//#region src/domain/companions.ts
|
|
1551
|
+
/** The shortest chain of moving packages from `from` to one a changeset names, breadth first. */
|
|
1552
|
+
const chainTo = (from, dependencies, moving, named) => {
|
|
1553
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1554
|
+
let paths = [[from]];
|
|
1555
|
+
while (paths.length > 0) {
|
|
1556
|
+
const next = [];
|
|
1557
|
+
for (const path of paths) {
|
|
1558
|
+
const last = path[path.length - 1] ?? from;
|
|
1559
|
+
for (const dependency of dependencies[last] ?? []) {
|
|
1560
|
+
if (!moving.has(dependency) || seen.has(dependency)) continue;
|
|
1561
|
+
seen.add(dependency);
|
|
1562
|
+
const chain = [...path, dependency];
|
|
1563
|
+
if (named.has(dependency)) return chain.slice(1);
|
|
1564
|
+
next.push(chain);
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
paths = next;
|
|
1483
1568
|
}
|
|
1484
|
-
|
|
1485
|
-
const these = commands.length > 1 ? "these" : "this";
|
|
1486
|
-
const ask = kept.length === 0 ? "run these to finish the cleanup:" : `run ${these} to finish:`;
|
|
1487
|
-
fail(context, "Cancelled, not all of it", [...kept.map(({ label }) => label), ask].join("; "), commands);
|
|
1569
|
+
return [];
|
|
1488
1570
|
};
|
|
1489
1571
|
/**
|
|
1490
|
-
*
|
|
1491
|
-
*
|
|
1572
|
+
* Preview: the units a release moves that the person did not pick. changesets moves a unit whenever
|
|
1573
|
+
* a workspace package it uses moves, so it cannot stay behind; this says through which package.
|
|
1492
1574
|
*/
|
|
1493
|
-
const
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
});
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
label: `branch ${branch} from main`,
|
|
1512
|
-
run: async () => {
|
|
1513
|
-
untracked = new Set(await source.changedFiles());
|
|
1514
|
-
await source.createBranch(branch);
|
|
1515
|
-
},
|
|
1516
|
-
undo: {
|
|
1517
|
-
label: `delete ${branch}`,
|
|
1518
|
-
run: async () => {
|
|
1519
|
-
const created = (await source.changedFiles()).filter((file) => !untracked.has(file));
|
|
1520
|
-
await source.discard(created);
|
|
1521
|
-
await source.switchTo("main");
|
|
1522
|
-
await source.deleteBranch(branch);
|
|
1523
|
-
},
|
|
1524
|
-
byHand: () => [
|
|
1525
|
-
"git reset --hard",
|
|
1526
|
-
"git switch main",
|
|
1527
|
-
`git branch -D ${branch}`
|
|
1528
|
-
]
|
|
1529
|
-
}
|
|
1530
|
-
};
|
|
1531
|
-
};
|
|
1532
|
-
const pushStep = ({ services: { sourceControl: source } }, branch) => ({
|
|
1533
|
-
label: `push ${branch}`,
|
|
1534
|
-
run: () => source.push(branch),
|
|
1535
|
-
undo: {
|
|
1536
|
-
label: `delete ${branch} on origin`,
|
|
1537
|
-
run: () => source.deleteRemoteBranch(branch),
|
|
1538
|
-
byHand: () => [`git push origin --delete ${branch}`]
|
|
1539
|
-
}
|
|
1540
|
-
});
|
|
1541
|
-
/** Opens a pull request; undone by closing it, with a comment saying why. */
|
|
1542
|
-
const openPrStep = ({ services: { codeHost: host } }, label, open) => {
|
|
1543
|
-
let opened = null;
|
|
1544
|
-
return {
|
|
1545
|
-
label,
|
|
1546
|
-
run: async () => {
|
|
1547
|
-
opened = await open();
|
|
1548
|
-
},
|
|
1549
|
-
undo: {
|
|
1550
|
-
label: "close the pull request",
|
|
1551
|
-
run: async () => {
|
|
1552
|
-
if (opened) await host.closePr(opened, "The release stopped part way, so it closed this.");
|
|
1553
|
-
},
|
|
1554
|
-
byHand: () => opened ? [`gh pr close ${opened.number}`] : []
|
|
1555
|
-
}
|
|
1556
|
-
};
|
|
1575
|
+
const draggedUnits = (plan, dependencies, units, scope) => {
|
|
1576
|
+
const moving = new Set(plan.releases.map(({ name }) => name));
|
|
1577
|
+
const named = new Set(plan.releases.filter(({ changesets }) => changesets.length > 0).map(({ name }) => name));
|
|
1578
|
+
const picked = units.filter(({ name }) => scope.has(name));
|
|
1579
|
+
return units.flatMap(({ name: app, packageName }) => {
|
|
1580
|
+
const release = plan.releases.find(({ name }) => name === packageName);
|
|
1581
|
+
if (scope.has(app) || !release) return [];
|
|
1582
|
+
const chain = chainTo(packageName, dependencies, moving, named);
|
|
1583
|
+
const source = chain[chain.length - 1];
|
|
1584
|
+
const movers = picked.filter((unit) => plan.changesets.some(({ releases }) => releases.some(({ name }) => name === source) && releases.some(({ name }) => name === unit.packageName))).map(({ name }) => name);
|
|
1585
|
+
const whose = movers.length > 0 ? `${movers.join(", ")}'s changes move` : "this release moves";
|
|
1586
|
+
return [{
|
|
1587
|
+
app,
|
|
1588
|
+
version: release.newVersion,
|
|
1589
|
+
with: movers,
|
|
1590
|
+
why: chain.length > 0 ? `uses ${chain.join(" → ")}, which ${whose}` : "moves with this release"
|
|
1591
|
+
}];
|
|
1592
|
+
});
|
|
1557
1593
|
};
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
const
|
|
1566
|
-
const
|
|
1567
|
-
|
|
1568
|
-
return
|
|
1594
|
+
const OWN_CHANGE = /^- ([0-9a-f]{7,40}): /gm;
|
|
1595
|
+
const DEPENDENCY_CHANGES = /^- Updated dependencies \[([^\]]+)\]/gm;
|
|
1596
|
+
/** The changes a version carries: its own, and those a package it uses moved for. */
|
|
1597
|
+
const changeIds = (notes) => new Set([...[...notes.matchAll(OWN_CHANGE)].flatMap(([, id]) => id ? [id] : []), ...[...notes.matchAll(DEPENDENCY_CHANGES)].flatMap(([, ids]) => (ids ?? "").split(",").map((id) => id.trim()))]);
|
|
1598
|
+
/** A change's first line in these notes, with an ellipsis when it goes on. */
|
|
1599
|
+
const summaryOf = (notes, id) => {
|
|
1600
|
+
const lines = notes.split("\n");
|
|
1601
|
+
const index = lines.findIndex((line) => line.startsWith(`- ${id}: `));
|
|
1602
|
+
const first = lines[index]?.slice(`- ${id}: `.length).trim();
|
|
1603
|
+
if (index < 0 || !first) return null;
|
|
1604
|
+
return /^ {2}\S/.test(lines[index + 1] ?? "") ? `${first}…` : first;
|
|
1569
1605
|
};
|
|
1570
|
-
/**
|
|
1571
|
-
const
|
|
1572
|
-
|
|
1573
|
-
const
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
const waiting = split.waits.filter(({ releases }) => releases.some(({ name }) => name === packageName)).length;
|
|
1579
|
-
const own = waiting > 0 ? ` · picking it ships its ${plural$1(waiting, "changeset")} too` : "";
|
|
1580
|
-
output.line(` ${app.padEnd(11)}${version.padEnd(20)}${paint("dim", `${why}${own}`)}`);
|
|
1581
|
-
});
|
|
1582
|
-
output.line();
|
|
1606
|
+
/** The packages listed under the `Updated dependencies` line that names this change. */
|
|
1607
|
+
const packagesMovedFor = (notes, id) => {
|
|
1608
|
+
const lines = notes.split("\n");
|
|
1609
|
+
const start = lines.findIndex((line) => line.startsWith("- Updated dependencies [") && line.includes(id));
|
|
1610
|
+
if (start < 0) return [];
|
|
1611
|
+
const listed = lines.slice(start + 1);
|
|
1612
|
+
const end = listed.findIndex((line) => !/^ {2}- \S+@/.test(line));
|
|
1613
|
+
return (end < 0 ? listed : listed.slice(0, end)).map((line) => line.trim().slice(2).replace(/@[^@]*$/, ""));
|
|
1583
1614
|
};
|
|
1584
|
-
/**
|
|
1585
|
-
const
|
|
1586
|
-
const
|
|
1587
|
-
|
|
1588
|
-
const
|
|
1589
|
-
const
|
|
1590
|
-
|
|
1591
|
-
const where = environmentLabel(context, bumps.map(({ app }) => app), "preview");
|
|
1592
|
-
output.line();
|
|
1593
|
-
output.line(` ${paint("bold", "Release")} ${dot} ${where} ${dot} ${plural$1(pending, "changeset")}${heldLabel}`);
|
|
1594
|
-
output.line();
|
|
1595
|
-
const width = Math.max(13, ...release.units.map(({ name }) => name.length)) + 2;
|
|
1596
|
-
output.line(paint("dim", ` ${"Unit".padEnd(width)}${"Version".padEnd(20)}${where === "live" ? "Ships live" : "Ships to preview"}`));
|
|
1597
|
-
release.units.forEach((unit) => {
|
|
1598
|
-
const bump = bumps.find(({ app }) => app === unit.name);
|
|
1599
|
-
const version = bump ? `${bump.from} → ${bump.to}` : unit.version;
|
|
1600
|
-
const left = unreleased.find(({ app }) => app === unit.name);
|
|
1601
|
-
const ships = (() => {
|
|
1602
|
-
if (held.includes(unit.name) && !bump) return paint("yellow", "⏸ held, its changesets stay pending");
|
|
1603
|
-
if (left && !bump) return paint("yellow", `! ${plural$1(left.commits.length, "commit")} since ${left.version}, no changeset: not in this release`);
|
|
1604
|
-
const contributed = contributions[unit.name]?.summary;
|
|
1605
|
-
if (contributed && contributed.length > 0) return contributed.join(`\n ${" ".repeat(width + 20)}`);
|
|
1606
|
-
if (!bump) return paint("dim", "– nothing changed");
|
|
1607
|
-
const along = companions.some(({ app }) => app === unit.name) ? paint("yellow", " not picked, goes along") : "";
|
|
1608
|
-
return `${paint("green", "↑ ship")} ${paint("dim", moduleOf(context, unit)?.provider ?? "")}${along}`;
|
|
1609
|
-
})();
|
|
1610
|
-
output.line(` ${unit.name.padEnd(width)}${version.padEnd(20)}${ships}`);
|
|
1611
|
-
});
|
|
1612
|
-
if (packages > 0) output.line(` ${"packages".padEnd(width)}${`${packages} bumped`.padEnd(20)}${paint("dim", "changelogs only, nothing published")}`);
|
|
1613
|
-
output.line();
|
|
1614
|
-
printCompanions(context, prepared);
|
|
1615
|
+
/** Why two versions went out together: the change they share, or the package both moved for. */
|
|
1616
|
+
const sharedReason = (partner, other, id) => {
|
|
1617
|
+
const summary = summaryOf(partner.notes, id) ?? summaryOf(other.notes, id);
|
|
1618
|
+
if (summary) return ` for: ${summary}`;
|
|
1619
|
+
const theirs = new Set(packagesMovedFor(partner.notes, id));
|
|
1620
|
+
const both = packagesMovedFor(other.notes, id).filter((name) => theirs.has(name));
|
|
1621
|
+
return both.length > 0 ? `: both use ${both.join(", ")}, which moved` : "";
|
|
1615
1622
|
};
|
|
1616
1623
|
/**
|
|
1617
|
-
*
|
|
1618
|
-
*
|
|
1624
|
+
* Production: the units preview runs with the picked ones that are not picked. Two versions went to
|
|
1625
|
+
* preview together when their notes share a change, their own or one a package they use moved for.
|
|
1619
1626
|
*/
|
|
1620
|
-
const
|
|
1621
|
-
const
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1627
|
+
const releasedTogether = (picked, others) => others.flatMap((other) => {
|
|
1628
|
+
const ids = changeIds(other.notes);
|
|
1629
|
+
const partners = picked.flatMap((partner) => {
|
|
1630
|
+
const shared = [...changeIds(partner.notes)].find((id) => ids.has(id));
|
|
1631
|
+
return shared ? [{
|
|
1632
|
+
partner,
|
|
1633
|
+
shared
|
|
1634
|
+
}] : [];
|
|
1635
|
+
});
|
|
1636
|
+
const [first] = partners;
|
|
1637
|
+
if (!first) return [];
|
|
1638
|
+
const names = partners.map(({ partner }) => `${partner.app} ${partner.version}`).join(", ");
|
|
1639
|
+
return [{
|
|
1640
|
+
app: other.app,
|
|
1641
|
+
version: other.version,
|
|
1642
|
+
with: partners.map(({ partner }) => partner.app),
|
|
1643
|
+
why: `went to preview with ${names}${sharedReason(first.partner, other, first.shared)}`
|
|
1644
|
+
}];
|
|
1645
|
+
});
|
|
1646
|
+
//#endregion
|
|
1647
|
+
//#region src/application/readScope.ts
|
|
1648
|
+
const MANIFEST = "package.json";
|
|
1649
|
+
const unitRefs = (units) => units.map(({ name, packageName }) => ({
|
|
1650
|
+
name,
|
|
1651
|
+
packageName
|
|
1652
|
+
}));
|
|
1653
|
+
/** The units the pending changesets name. */
|
|
1654
|
+
const namedUnits = async ({ release, services }) => new Set((await services.versioning.pending()).flatMap(({ text }) => changesetApps(text, unitRefs(release.units))));
|
|
1655
|
+
/** Units whose folder moved since their current version, that no changeset or bump ships. */
|
|
1656
|
+
const findUnreleased = async ({ release, services: { sourceControl: source } }, named) => {
|
|
1657
|
+
if (!release.releasesCommits) return [];
|
|
1658
|
+
return unreleasedApps((await Promise.all(release.units.map(async ({ name, dir, version }) => {
|
|
1659
|
+
const since = await source.tagCommit(tagName(name, version, release.tagFormat)) ?? (await source.versionCommit(dir, "package.json", version))?.sha;
|
|
1660
|
+
if (!since) return [];
|
|
1661
|
+
return [{
|
|
1662
|
+
app: name,
|
|
1663
|
+
version,
|
|
1664
|
+
commits: await source.subjectsSince(since, dir, UNIT_FILES)
|
|
1665
|
+
}];
|
|
1666
|
+
}))).flat(), named);
|
|
1667
|
+
};
|
|
1668
|
+
/** A tag's deploy on an environment, from every record the host keeps. */
|
|
1669
|
+
const deployedOn = (history, tag, environment) => {
|
|
1670
|
+
const states = history.filter(({ title }) => title === deployRunTitle(tag, environment)).map(({ state }) => state);
|
|
1671
|
+
if (states.includes("done")) return "done";
|
|
1672
|
+
return states.includes("running") ? "running" : "none";
|
|
1673
|
+
};
|
|
1674
|
+
/**
|
|
1675
|
+
* Each unit as the first question sees it: git for what is new, the host's deploy records for what
|
|
1676
|
+
* each environment runs (offline, nothing counts as deployed).
|
|
1677
|
+
*/
|
|
1678
|
+
const readScope = async (context, environment) => {
|
|
1679
|
+
const { release, services } = context;
|
|
1680
|
+
const pending = await services.versioning.pending();
|
|
1681
|
+
const refs = unitRefs(release.units);
|
|
1682
|
+
const named = pending.map(({ text }) => changesetApps(text, refs));
|
|
1683
|
+
const unreleased = await findUnreleased(context, new Set(named.flat()));
|
|
1684
|
+
const [deployed, tags] = await Promise.all([services.codeHost.deployments().catch(() => []), services.sourceControl.tags()]);
|
|
1685
|
+
return Promise.all(release.units.map(async (unit) => {
|
|
1686
|
+
const tag = tagName(unit.name, unit.version, context.release.tagFormat);
|
|
1687
|
+
const target = moduleOf(context, unit);
|
|
1688
|
+
const decidedBy = target?.decidedBy;
|
|
1689
|
+
const commit = await services.sourceControl.versionCommit(unit.dir, MANIFEST, unit.version);
|
|
1690
|
+
const tagged = await services.sourceControl.tagCommit(tag) !== null;
|
|
1691
|
+
const live = async (on) => {
|
|
1692
|
+
if (!target?.live || !tagged) return deployedOn(deployed, tag, on) === "done";
|
|
1693
|
+
const { head } = await services.sourceControl.position();
|
|
1694
|
+
const input = jobInput(context, target, unit, {
|
|
1695
|
+
tag,
|
|
1696
|
+
environment: on,
|
|
1697
|
+
commit: head
|
|
1698
|
+
});
|
|
1699
|
+
return target.live(decideContext(context), input).catch(() => false);
|
|
1700
|
+
};
|
|
1701
|
+
return {
|
|
1702
|
+
app: unit.name,
|
|
1703
|
+
version: unit.version,
|
|
1704
|
+
changesets: named.filter((apps) => apps.includes(unit.name)).length,
|
|
1705
|
+
commits: unreleased.find((entry) => entry.app === unit.name)?.commits.length ?? 0,
|
|
1706
|
+
tagged,
|
|
1707
|
+
versioned: commit !== null && cameWithRelease({
|
|
1708
|
+
app: unit.name,
|
|
1709
|
+
version: unit.version,
|
|
1710
|
+
commit
|
|
1711
|
+
}),
|
|
1712
|
+
firstRelease: !tagged && commit !== null && firstRelease(unit.name, unit.version, tags, context.release.tagFormat),
|
|
1713
|
+
onChannel: await live(environment),
|
|
1714
|
+
onPreview: await live("preview"),
|
|
1715
|
+
...decidedBy ? { decidedBy } : {},
|
|
1716
|
+
...target?.releaseOnly ? { releaseOnly: true } : {}
|
|
1717
|
+
};
|
|
1718
|
+
}));
|
|
1719
|
+
};
|
|
1720
|
+
//#endregion
|
|
1721
|
+
//#region src/application/prepareRelease.ts
|
|
1722
|
+
const NOTHING_HELD = {
|
|
1723
|
+
ships: [],
|
|
1724
|
+
waits: []
|
|
1725
|
+
};
|
|
1726
|
+
/** The person's answer to a plugin's choice; the suggestion without a terminal or with --yes. */
|
|
1727
|
+
const choose = async ({ prompter, options }, choice) => {
|
|
1728
|
+
if (!choice) return null;
|
|
1729
|
+
if (options.yes || !prompter.interactive) return choice.suggested;
|
|
1730
|
+
return prompter.select(choice.question, choice.options, choice.suggested);
|
|
1731
|
+
};
|
|
1732
|
+
/** What each picked unit's plugin adds, given the unit's bump so far. One at a time: it may ask. */
|
|
1733
|
+
const contributionsOf = async (context, scope, bumps, known = {}) => {
|
|
1734
|
+
const { head } = await context.services.sourceControl.position();
|
|
1735
|
+
const contributions = {};
|
|
1736
|
+
for (const unit of context.release.units.filter(({ name }) => scope.has(name))) {
|
|
1737
|
+
const answered = known[unit.name];
|
|
1738
|
+
if (answered) {
|
|
1739
|
+
contributions[unit.name] = answered;
|
|
1740
|
+
continue;
|
|
1741
|
+
}
|
|
1742
|
+
const module = moduleOf(context, unit);
|
|
1743
|
+
const version = module?.version?.bind(module);
|
|
1744
|
+
if (!module || !version) continue;
|
|
1745
|
+
const input = jobInput(context, module, unit, {
|
|
1746
|
+
tag: tagName(unit.name, unit.version, context.release.tagFormat),
|
|
1747
|
+
environment: "preview",
|
|
1748
|
+
commit: head
|
|
1749
|
+
});
|
|
1750
|
+
const bump = bumps.find(({ app }) => app === unit.name);
|
|
1751
|
+
const contribute = (chosen) => version(decideContext(context), {
|
|
1752
|
+
...input,
|
|
1753
|
+
bump,
|
|
1754
|
+
chosen
|
|
1755
|
+
});
|
|
1756
|
+
const suggested = await contribute();
|
|
1757
|
+
const chosen = await choose(context, suggested.choice);
|
|
1758
|
+
contributions[unit.name] = chosen && chosen !== suggested.choice?.suggested ? await contribute(chosen) : suggested;
|
|
1759
|
+
}
|
|
1760
|
+
return contributions;
|
|
1761
|
+
};
|
|
1762
|
+
/** What a release PR covering `scope` would version, computed without writing anything. */
|
|
1763
|
+
const prepareRelease = async (context, scope, known = {}) => {
|
|
1764
|
+
const { release, services } = context;
|
|
1765
|
+
const refs = unitRefs(release.units);
|
|
1766
|
+
const [dependencies, named, base, pendingFiles] = await Promise.all([
|
|
1767
|
+
services.versioning.dependencies(),
|
|
1768
|
+
namedUnits(context),
|
|
1769
|
+
services.versioning.plan([], []),
|
|
1770
|
+
services.versioning.pending()
|
|
1771
|
+
]);
|
|
1772
|
+
const baseBumps = appBumps(base, dependencies, refs);
|
|
1773
|
+
const unreleased = await findUnreleased(context, new Set([...named, ...baseBumps.map(({ app }) => app)]));
|
|
1774
|
+
const held = [...named].filter((app) => !scope.has(app));
|
|
1775
|
+
const adopted = unreleased.filter(({ app }) => scope.has(app)).flatMap(({ app, version, commits }) => {
|
|
1776
|
+
const ref = refs.find(({ name }) => name === app);
|
|
1777
|
+
return ref ? unreleasedChangesets(ref, version, commits) : [];
|
|
1778
|
+
});
|
|
1779
|
+
const split = held.length > 0 ? splitChangesets(base.changesets, held, refs) : NOTHING_HELD;
|
|
1780
|
+
const picked = held.length > 0 || adopted.length > 0 ? await services.versioning.plan(adopted, split.waits) : base;
|
|
1781
|
+
const contributions = await contributionsOf(context, scope, appBumps(picked, dependencies, refs), known);
|
|
1782
|
+
const contributed = Object.values(contributions).flatMap(({ added }) => added);
|
|
1783
|
+
const added = [...adopted, ...contributed];
|
|
1784
|
+
const plan = contributed.length > 0 ? await services.versioning.plan(added, split.waits) : picked;
|
|
1785
|
+
return {
|
|
1786
|
+
pending: (held.length > 0 ? split.ships.length : pendingFiles.length) + added.length,
|
|
1787
|
+
held,
|
|
1788
|
+
unreleased: unreleased.filter(({ app }) => !scope.has(app)),
|
|
1789
|
+
split,
|
|
1790
|
+
bumps: appBumps(plan, dependencies, refs),
|
|
1791
|
+
companions: draggedUnits(plan, dependencies, refs, scope),
|
|
1792
|
+
packages: packageBumps(plan, refs),
|
|
1793
|
+
added,
|
|
1794
|
+
shipped: plan.changesets,
|
|
1795
|
+
contributions
|
|
1796
|
+
};
|
|
1797
|
+
};
|
|
1798
|
+
//#endregion
|
|
1799
|
+
//#region src/application/steps.ts
|
|
1800
|
+
const MAX_OUTPUT_LINES = 40;
|
|
1801
|
+
const reasonOf$1 = (error) => error instanceof Error ? error.message : String(error);
|
|
1802
|
+
/** What the failed command printed, so the person reads why without running it again. */
|
|
1803
|
+
const printOutput = ({ output }, error) => {
|
|
1804
|
+
if (!(error instanceof CommandFailed) || !error.output) return;
|
|
1805
|
+
const lines = error.output.split("\n");
|
|
1806
|
+
const shown = lines.slice(-MAX_OUTPUT_LINES);
|
|
1807
|
+
if (shown.length < lines.length) output.line(paint("dim", ` … ${lines.length - shown.length} earlier lines`));
|
|
1808
|
+
shown.forEach((line) => output.line(paint("dim", ` │ ${line}`)));
|
|
1809
|
+
};
|
|
1810
|
+
/** Takes back the steps that ran, newest first; one that cannot be undone never stops the rest. */
|
|
1811
|
+
const cancel = async (context, ran) => {
|
|
1812
|
+
const undos = ran.flatMap(({ undo }) => undo ? [undo] : []).reverse();
|
|
1813
|
+
const kept = ran.flatMap((step) => step.kept ? [step.kept] : []);
|
|
1814
|
+
if (undos.length === 0 && kept.length === 0) return;
|
|
1815
|
+
const left = [];
|
|
1816
|
+
for (const undo of undos) try {
|
|
1817
|
+
await context.progress.during(`undo: ${undo.label}`, "working", undo.run);
|
|
1818
|
+
} catch (error) {
|
|
1819
|
+
left.push(undo);
|
|
1820
|
+
context.progress.say("worried", `${paint("red", "✗")} undo ${undo.label}: ${reasonOf$1(error)}`);
|
|
1821
|
+
}
|
|
1822
|
+
if (left.length === 0 && kept.length === 0) {
|
|
1823
|
+
context.progress.say("resting", paint("dim", "Cancelled: everything this run did is undone."));
|
|
1824
|
+
return;
|
|
1825
|
+
}
|
|
1826
|
+
const commands = [...new Set([...left, ...kept].flatMap(({ byHand }) => byHand()))];
|
|
1827
|
+
const these = commands.length > 1 ? "these" : "this";
|
|
1828
|
+
const ask = kept.length === 0 ? "run these to finish the cleanup:" : `run ${these} to finish:`;
|
|
1829
|
+
fail(context, "Cancelled, not all of it", [...kept.map(({ label }) => label), ask].join("; "), commands);
|
|
1830
|
+
};
|
|
1831
|
+
/**
|
|
1832
|
+
* Runs steps in order, each shown with its place in the run. At the first failure it says why,
|
|
1833
|
+
* with the command's own output, and undoes the steps that ran.
|
|
1834
|
+
*/
|
|
1835
|
+
const runSteps = async (context, steps) => {
|
|
1836
|
+
for (const [index, step] of steps.entries()) try {
|
|
1837
|
+
await context.progress.during(step.label, "working", step.run, {
|
|
1838
|
+
index,
|
|
1839
|
+
total: steps.length
|
|
1840
|
+
});
|
|
1841
|
+
} catch (error) {
|
|
1842
|
+
fail(context, `${step.label} failed`, `${reasonOf$1(error)}, the steps after it did not run.`);
|
|
1843
|
+
printOutput(context, error);
|
|
1844
|
+
await cancel(context, steps.slice(0, index));
|
|
1845
|
+
return false;
|
|
1846
|
+
}
|
|
1847
|
+
return true;
|
|
1848
|
+
};
|
|
1849
|
+
/** A branch from main; undone by dropping the changes made on it and the branch itself. */
|
|
1850
|
+
const branchStep = ({ services: { sourceControl: source } }, branch) => {
|
|
1851
|
+
let untracked = /* @__PURE__ */ new Set();
|
|
1852
|
+
return {
|
|
1853
|
+
label: `branch ${branch} from main`,
|
|
1854
|
+
run: async () => {
|
|
1855
|
+
untracked = new Set(await source.changedFiles());
|
|
1856
|
+
await source.createBranch(branch);
|
|
1857
|
+
},
|
|
1858
|
+
undo: {
|
|
1859
|
+
label: `delete ${branch}`,
|
|
1860
|
+
run: async () => {
|
|
1861
|
+
const created = (await source.changedFiles()).filter((file) => !untracked.has(file));
|
|
1862
|
+
await source.discard(created);
|
|
1863
|
+
await source.switchTo("main");
|
|
1864
|
+
await source.deleteBranch(branch);
|
|
1865
|
+
},
|
|
1866
|
+
byHand: () => [
|
|
1867
|
+
"git reset --hard",
|
|
1868
|
+
"git switch main",
|
|
1869
|
+
`git branch -D ${branch}`
|
|
1870
|
+
]
|
|
1871
|
+
}
|
|
1872
|
+
};
|
|
1873
|
+
};
|
|
1874
|
+
const pushStep = ({ services: { sourceControl: source } }, branch) => ({
|
|
1875
|
+
label: `push ${branch}`,
|
|
1876
|
+
run: () => source.push(branch),
|
|
1877
|
+
undo: {
|
|
1878
|
+
label: `delete ${branch} on origin`,
|
|
1879
|
+
run: () => source.deleteRemoteBranch(branch),
|
|
1880
|
+
byHand: () => [`git push origin --delete ${branch}`]
|
|
1881
|
+
}
|
|
1882
|
+
});
|
|
1883
|
+
/** Opens a pull request; undone by closing it, with a comment saying why. */
|
|
1884
|
+
const openPrStep = ({ services: { codeHost: host } }, label, open) => {
|
|
1885
|
+
let opened = null;
|
|
1886
|
+
return {
|
|
1887
|
+
label,
|
|
1888
|
+
run: async () => {
|
|
1889
|
+
opened = await open();
|
|
1890
|
+
},
|
|
1891
|
+
undo: {
|
|
1892
|
+
label: "close the pull request",
|
|
1893
|
+
run: async () => {
|
|
1894
|
+
if (opened) await host.closePr(opened, "The release stopped part way, so it closed this.");
|
|
1895
|
+
},
|
|
1896
|
+
byHand: () => opened ? [`gh pr close ${opened.number}`] : []
|
|
1897
|
+
}
|
|
1898
|
+
};
|
|
1899
|
+
};
|
|
1900
|
+
//#endregion
|
|
1901
|
+
//#region src/application/openReleasePr.ts
|
|
1902
|
+
const plural$2 = (count, word) => `${count} ${word}${count === 1 ? "" : "s"}`;
|
|
1903
|
+
/** What happens to a unit once the release PR merges: its module ships the version to preview. */
|
|
1904
|
+
const shipsOnMerge = (context, { contributions, companions }) => (bump) => {
|
|
1905
|
+
const contributed = contributions[bump.app]?.onMerge;
|
|
1906
|
+
if (contributed) return contributed;
|
|
1907
|
+
const unit = context.release.units.find(({ name }) => name === bump.app);
|
|
1908
|
+
const along = companions.find(({ app }) => app === bump.app);
|
|
1909
|
+
const reason = along ? ` (not picked: ${along.why})` : bump.movedWith.length > 0 ? ` (moved with ${bump.movedWith.join(", ")})` : "";
|
|
1910
|
+
return `${environmentLabel(context, [bump.app], "preview") === "live" ? "Ship live" : "Ship to preview"} with ${(unit && moduleOf(context, unit)?.provider) ?? "its target"}${reason}`;
|
|
1911
|
+
};
|
|
1912
|
+
/** Units going out unpicked, each with the package that takes it along. */
|
|
1913
|
+
const printCompanions = ({ output, release }, { companions, split }) => {
|
|
1914
|
+
if (companions.length === 0) return;
|
|
1915
|
+
const names = companions.map(({ app }) => app);
|
|
1916
|
+
const verb = names.length === 1 ? "is not picked but ships too" : "are not picked but ship too";
|
|
1917
|
+
output.line(` ${paint(["bold", "yellow"], "!")} ${paint("bold", `${listed(names)} ${verb}:`)}`);
|
|
1918
|
+
companions.forEach(({ app, version, why }) => {
|
|
1919
|
+
const packageName = release.units.find(({ name }) => name === app)?.packageName;
|
|
1920
|
+
const waiting = split.waits.filter(({ releases }) => releases.some(({ name }) => name === packageName)).length;
|
|
1921
|
+
const own = waiting > 0 ? ` · picking it ships its ${plural$2(waiting, "changeset")} too` : "";
|
|
1922
|
+
output.line(` ${app.padEnd(11)}${version.padEnd(20)}${paint("dim", `${why}${own}`)}`);
|
|
1923
|
+
});
|
|
1924
|
+
output.line();
|
|
1925
|
+
};
|
|
1926
|
+
/** The table a person reads before anything is written: each unit, its move, what ships. */
|
|
1927
|
+
const printSummary = (context, prepared) => {
|
|
1928
|
+
const { output, release } = context;
|
|
1929
|
+
const { bumps, packages, pending, held, unreleased, contributions, companions } = prepared;
|
|
1930
|
+
const dot = paint("dim", "·");
|
|
1931
|
+
const stays = held.filter((app) => !bumps.some((bump) => bump.app === app));
|
|
1932
|
+
const heldLabel = stays.length > 0 ? ` ${dot} ${stays.join(", ")} held` : "";
|
|
1933
|
+
const where = environmentLabel(context, bumps.map(({ app }) => app), "preview");
|
|
1934
|
+
output.line();
|
|
1935
|
+
output.line(` ${paint("bold", "Release")} ${dot} ${where} ${dot} ${plural$2(pending, "changeset")}${heldLabel}`);
|
|
1936
|
+
output.line();
|
|
1937
|
+
const width = Math.max(13, ...release.units.map(({ name }) => name.length)) + 2;
|
|
1938
|
+
output.line(paint("dim", ` ${"Unit".padEnd(width)}${"Version".padEnd(20)}${where === "live" ? "Ships live" : "Ships to preview"}`));
|
|
1939
|
+
release.units.forEach((unit) => {
|
|
1940
|
+
const bump = bumps.find(({ app }) => app === unit.name);
|
|
1941
|
+
const version = bump ? `${bump.from} → ${bump.to}` : unit.version;
|
|
1942
|
+
const left = unreleased.find(({ app }) => app === unit.name);
|
|
1943
|
+
const ships = (() => {
|
|
1944
|
+
if (held.includes(unit.name) && !bump) return paint("yellow", "⏸ held, its changesets stay pending");
|
|
1945
|
+
if (left && !bump) return paint("yellow", `! ${plural$2(left.commits.length, "commit")} since ${left.version}, no changeset: not in this release`);
|
|
1946
|
+
const contributed = contributions[unit.name]?.summary;
|
|
1947
|
+
if (contributed && contributed.length > 0) return contributed.join(`\n ${" ".repeat(width + 20)}`);
|
|
1948
|
+
if (!bump) return paint("dim", "– nothing changed");
|
|
1949
|
+
const along = companions.some(({ app }) => app === unit.name) ? paint("yellow", " not picked, goes along") : "";
|
|
1950
|
+
return `${paint("green", "↑ ship")} ${paint("dim", moduleOf(context, unit)?.provider ?? "")}${along}`;
|
|
1951
|
+
})();
|
|
1952
|
+
output.line(` ${unit.name.padEnd(width)}${version.padEnd(20)}${ships}`);
|
|
1953
|
+
});
|
|
1954
|
+
if (packages > 0) output.line(` ${"packages".padEnd(width)}${`${packages} bumped`.padEnd(20)}${paint("dim", "changelogs only, nothing published")}`);
|
|
1955
|
+
output.line();
|
|
1956
|
+
printCompanions(context, prepared);
|
|
1957
|
+
};
|
|
1958
|
+
/**
|
|
1959
|
+
* Versions what `prepared` covers on one branch from main, opens its PR, and goes back to main.
|
|
1960
|
+
* Null, with what to do, when it must not run.
|
|
1961
|
+
*/
|
|
1962
|
+
const openReleasePr = async (context, prepared, replaces = []) => {
|
|
1963
|
+
const { output, services, clock } = context;
|
|
1964
|
+
printSummary(context, prepared);
|
|
1965
|
+
const blocked = Object.values(prepared.contributions).find((entry) => entry.blocked)?.blocked;
|
|
1966
|
+
if (blocked) {
|
|
1967
|
+
fail(context, blocked.title, blocked.detail, blocked.commands);
|
|
1968
|
+
return null;
|
|
1969
|
+
}
|
|
1970
|
+
const source = releaseSource("build", "preview", await services.sourceControl.position());
|
|
1971
|
+
if (!source.allowed) {
|
|
1972
|
+
fail(context, source.why === "not-main" ? "Not from main" : "main is behind origin", "a release versions what is merged.", [
|
|
1973
|
+
"git switch main",
|
|
1974
|
+
"git pull",
|
|
1975
|
+
"shiplane"
|
|
1976
|
+
]);
|
|
1977
|
+
return null;
|
|
1978
|
+
}
|
|
1979
|
+
if (!await services.sourceControl.isClean()) {
|
|
1980
|
+
fail(context, "Uncommitted changes", "commit or stash them first, the release PR commits every change.");
|
|
1981
|
+
return null;
|
|
1982
|
+
}
|
|
1983
|
+
const kindOf = (app) => {
|
|
1984
|
+
const unit = context.release.units.find(({ name }) => name === app);
|
|
1985
|
+
return unit && moduleOf(context, unit)?.kind;
|
|
1986
|
+
};
|
|
1987
|
+
const groups = prGroupsOf(context, prepared);
|
|
1988
|
+
const titles = groups.map((group) => releaseTitle(group, kindOf));
|
|
1989
|
+
const planned = [
|
|
1990
|
+
groups.length > 1 ? `Open ${groups.length} release PRs from main, one per app, then wait for you to squash merge each:\n${titles.map((title) => ` ${title}`).join("\n")}` : "Open the release PR, then wait for you to squash merge it",
|
|
1991
|
+
"Tag each version and publish its release notes",
|
|
1644
1992
|
...Object.values(prepared.contributions).flatMap(({ step }) => step ? [step] : [])
|
|
1645
1993
|
];
|
|
1646
1994
|
output.line(paint("dim", " Steps"));
|
|
@@ -1650,9 +1998,40 @@ const openReleasePr = async (context, prepared) => {
|
|
|
1650
1998
|
output.line(paint("dim", "Nothing ran."));
|
|
1651
1999
|
return null;
|
|
1652
2000
|
}
|
|
1653
|
-
const
|
|
1654
|
-
const title = releaseTitle(prepared.bumps);
|
|
2001
|
+
const now = clock.now();
|
|
1655
2002
|
const prs = [];
|
|
2003
|
+
for (const group of groups) {
|
|
2004
|
+
const apps = new Set(group.map(({ app }) => app));
|
|
2005
|
+
const scoped = groups.length > 1 ? await prepareRelease(context, apps, prepared.contributions) : prepared;
|
|
2006
|
+
const [first] = group;
|
|
2007
|
+
const pr = await openOne(context, scoped, kindOf, `${releaseBranchName(now)}${groups.length > 1 && first ? `-${first.app}` : ""}`, replaces);
|
|
2008
|
+
if (!pr) {
|
|
2009
|
+
if (prs.length > 0) output.line(paint("dim", ` ${listed(prs.map(({ number }) => `#${number}`))} stay open: merge them, then run shiplane for the rest.`));
|
|
2010
|
+
return null;
|
|
2011
|
+
}
|
|
2012
|
+
prs.push(pr);
|
|
2013
|
+
}
|
|
2014
|
+
return prs;
|
|
2015
|
+
};
|
|
2016
|
+
/**
|
|
2017
|
+
* The apps each release PR takes: one PR per app, a family as one. Apps one changeset names or
|
|
2018
|
+
* one moving with the other share a PR. A release moving internal packages stays one PR: their
|
|
2019
|
+
* changelog lines have no app to go with.
|
|
2020
|
+
*/
|
|
2021
|
+
const prGroupsOf = ({ release }, prepared) => {
|
|
2022
|
+
if (prepared.packages > 0) return [prepared.bumps];
|
|
2023
|
+
const appOf = (packageName) => release.units.find((unit) => unit.packageName === packageName)?.name;
|
|
2024
|
+
const linked = [...prepared.shipped.map(({ releases }) => releases.map(({ name }) => appOf(name) ?? name)), ...prepared.bumps.map(({ app, movedWith }) => [app, ...movedWith.map((name) => appOf(name) ?? name)])];
|
|
2025
|
+
return releasePrGroups(prepared.bumps, linked);
|
|
2026
|
+
};
|
|
2027
|
+
/** The line a release PR opens with when it takes the place of release PRs main moved past. */
|
|
2028
|
+
const replacedLine = (replaces) => replaces.length === 0 ? "" : `Replaces ${listed(replaces.map(({ number }) => `#${number}`))}, which went out of date when main moved.\n\n`;
|
|
2029
|
+
/** Versions `prepared` on `branch` from main, opens its PR, and goes back to main. */
|
|
2030
|
+
const openOne = async (context, prepared, kindOf, branch, replaces) => {
|
|
2031
|
+
const { services } = context;
|
|
2032
|
+
const title = releaseTitle(prepared.bumps, kindOf);
|
|
2033
|
+
const skipHooks = !titleFits(title);
|
|
2034
|
+
const created = {};
|
|
1656
2035
|
return await runSteps(context, [
|
|
1657
2036
|
branchStep(context, branch),
|
|
1658
2037
|
{
|
|
@@ -1662,38 +2041,37 @@ const openReleasePr = async (context, prepared) => {
|
|
|
1662
2041
|
...Object.values(prepared.contributions).flatMap(({ writes }) => writes),
|
|
1663
2042
|
{
|
|
1664
2043
|
label: `commit "${title}"`,
|
|
1665
|
-
run: async () => services.sourceControl.commit(await services.sourceControl.changedFiles(), title, releaseCommitBody(prepared.bumps) || void 0)
|
|
2044
|
+
run: async () => services.sourceControl.commit(await services.sourceControl.changedFiles(), title, releaseCommitBody(prepared.bumps) || void 0, { skipHooks })
|
|
1666
2045
|
},
|
|
1667
2046
|
pushStep(context, branch),
|
|
1668
2047
|
openPrStep(context, "open the release pull request", async () => {
|
|
1669
|
-
|
|
2048
|
+
created.pr = await services.codeHost.createPr({
|
|
1670
2049
|
base: "main",
|
|
1671
2050
|
head: branch,
|
|
1672
2051
|
title,
|
|
1673
|
-
body: releasePrBody(prepared.bumps, shipsOnMerge(context, prepared)),
|
|
2052
|
+
body: replacedLine(replaces) + releasePrBody(prepared.bumps, shipsOnMerge(context, prepared)),
|
|
1674
2053
|
label: "type: chore"
|
|
1675
2054
|
});
|
|
1676
|
-
|
|
1677
|
-
return pr;
|
|
2055
|
+
return created.pr;
|
|
1678
2056
|
}),
|
|
1679
2057
|
{
|
|
1680
2058
|
label: "back to main",
|
|
1681
2059
|
run: () => services.sourceControl.switchTo("main")
|
|
1682
2060
|
}
|
|
1683
|
-
]) ?
|
|
2061
|
+
]) && created.pr ? created.pr : null;
|
|
1684
2062
|
};
|
|
1685
2063
|
//#endregion
|
|
1686
2064
|
//#region src/domain/scope.ts
|
|
1687
|
-
const plural = (count, word) => `${count} ${word}${count === 1 ? "" : "s"}`;
|
|
2065
|
+
const plural$1 = (count, word) => `${count} ${word}${count === 1 ? "" : "s"}`;
|
|
1688
2066
|
const previewChoice = ({ version, changesets, commits, tagged, versioned, firstRelease, onChannel, decidedBy, releaseOnly }) => {
|
|
1689
2067
|
const later = decidedBy ? ` · ${decidedBy.platform} decides ${decidedBy.choice} once picked` : "";
|
|
1690
2068
|
if (changesets > 0) return {
|
|
1691
2069
|
pending: true,
|
|
1692
|
-
hint: `${plural(changesets, "changeset")}${later}`
|
|
2070
|
+
hint: `${plural$1(changesets, "changeset")}${later}`
|
|
1693
2071
|
};
|
|
1694
2072
|
if (commits > 0) return {
|
|
1695
2073
|
pending: true,
|
|
1696
|
-
hint: `${plural(commits, "commit")} since ${version}, changelog from its commits${later}`
|
|
2074
|
+
hint: `${plural$1(commits, "commit")} since ${version}, changelog from its commits${later}`
|
|
1697
2075
|
};
|
|
1698
2076
|
if (!tagged) {
|
|
1699
2077
|
if (versioned) return {
|
|
@@ -1755,80 +2133,6 @@ const scopeChoices = (apps, channel) => apps.map((info) => ({
|
|
|
1755
2133
|
...channel === "production" ? productionChoice(info) : previewChoice(info)
|
|
1756
2134
|
}));
|
|
1757
2135
|
//#endregion
|
|
1758
|
-
//#region src/application/readScope.ts
|
|
1759
|
-
const MANIFEST = "package.json";
|
|
1760
|
-
const unitRefs = (units) => units.map(({ name, packageName }) => ({
|
|
1761
|
-
name,
|
|
1762
|
-
packageName
|
|
1763
|
-
}));
|
|
1764
|
-
/** The units the pending changesets name. */
|
|
1765
|
-
const namedUnits = async ({ release, services }) => new Set((await services.versioning.pending()).flatMap(({ text }) => changesetApps(text, unitRefs(release.units))));
|
|
1766
|
-
/** Units whose folder moved since their current version, that no changeset or bump ships. */
|
|
1767
|
-
const findUnreleased = async ({ release, services: { sourceControl: source } }, named) => {
|
|
1768
|
-
if (!release.releasesCommits) return [];
|
|
1769
|
-
return unreleasedApps((await Promise.all(release.units.map(async ({ name, dir, version }) => {
|
|
1770
|
-
const since = await source.tagCommit(tagName(name, version, release.tagFormat)) ?? (await source.versionCommit(dir, "package.json", version))?.sha;
|
|
1771
|
-
if (!since) return [];
|
|
1772
|
-
return [{
|
|
1773
|
-
app: name,
|
|
1774
|
-
version,
|
|
1775
|
-
commits: await source.subjectsSince(since, dir, UNIT_FILES)
|
|
1776
|
-
}];
|
|
1777
|
-
}))).flat(), named);
|
|
1778
|
-
};
|
|
1779
|
-
/** A tag's deploy on an environment, from every record the host keeps. */
|
|
1780
|
-
const deployedOn = (history, tag, environment) => {
|
|
1781
|
-
const states = history.filter(({ title }) => title === deployRunTitle(tag, environment)).map(({ state }) => state);
|
|
1782
|
-
if (states.includes("done")) return "done";
|
|
1783
|
-
return states.includes("running") ? "running" : "none";
|
|
1784
|
-
};
|
|
1785
|
-
/**
|
|
1786
|
-
* Each unit as the first question sees it: git for what is new, the host's deploy records for what
|
|
1787
|
-
* each environment runs (offline, nothing counts as deployed).
|
|
1788
|
-
*/
|
|
1789
|
-
const readScope = async (context, environment) => {
|
|
1790
|
-
const { release, services } = context;
|
|
1791
|
-
const pending = await services.versioning.pending();
|
|
1792
|
-
const refs = unitRefs(release.units);
|
|
1793
|
-
const named = pending.map(({ text }) => changesetApps(text, refs));
|
|
1794
|
-
const unreleased = await findUnreleased(context, new Set(named.flat()));
|
|
1795
|
-
const [deployed, tags] = await Promise.all([services.codeHost.deployments().catch(() => []), services.sourceControl.tags()]);
|
|
1796
|
-
return Promise.all(release.units.map(async (unit) => {
|
|
1797
|
-
const tag = tagName(unit.name, unit.version, context.release.tagFormat);
|
|
1798
|
-
const target = moduleOf(context, unit);
|
|
1799
|
-
const decidedBy = target?.decidedBy;
|
|
1800
|
-
const commit = await services.sourceControl.versionCommit(unit.dir, MANIFEST, unit.version);
|
|
1801
|
-
const tagged = await services.sourceControl.tagCommit(tag) !== null;
|
|
1802
|
-
const live = async (on) => {
|
|
1803
|
-
if (!target?.live || !tagged) return deployedOn(deployed, tag, on) === "done";
|
|
1804
|
-
const { head } = await services.sourceControl.position();
|
|
1805
|
-
const input = jobInput(context, target, unit, {
|
|
1806
|
-
tag,
|
|
1807
|
-
environment: on,
|
|
1808
|
-
commit: head
|
|
1809
|
-
});
|
|
1810
|
-
return target.live(decideContext(context), input).catch(() => false);
|
|
1811
|
-
};
|
|
1812
|
-
return {
|
|
1813
|
-
app: unit.name,
|
|
1814
|
-
version: unit.version,
|
|
1815
|
-
changesets: named.filter((apps) => apps.includes(unit.name)).length,
|
|
1816
|
-
commits: unreleased.find((entry) => entry.app === unit.name)?.commits.length ?? 0,
|
|
1817
|
-
tagged,
|
|
1818
|
-
versioned: commit !== null && cameWithRelease({
|
|
1819
|
-
app: unit.name,
|
|
1820
|
-
version: unit.version,
|
|
1821
|
-
commit
|
|
1822
|
-
}),
|
|
1823
|
-
firstRelease: !tagged && commit !== null && firstRelease(unit.name, unit.version, tags, context.release.tagFormat),
|
|
1824
|
-
onChannel: await live(environment),
|
|
1825
|
-
onPreview: await live("preview"),
|
|
1826
|
-
...decidedBy ? { decidedBy } : {},
|
|
1827
|
-
...target?.releaseOnly ? { releaseOnly: true } : {}
|
|
1828
|
-
};
|
|
1829
|
-
}));
|
|
1830
|
-
};
|
|
1831
|
-
//#endregion
|
|
1832
2136
|
//#region src/application/pickScope.ts
|
|
1833
2137
|
/** Every unit with something to release here: what --yes and a run without a terminal cover. */
|
|
1834
2138
|
const defaultScope = (info, environment) => new Set(scopeChoices(info, environment).filter(({ pending }) => pending).map(({ app }) => app));
|
|
@@ -1920,196 +2224,26 @@ const planShips = async (context, environment) => {
|
|
|
1920
2224
|
tag,
|
|
1921
2225
|
environment
|
|
1922
2226
|
});
|
|
1923
|
-
const plan = shipPlanOf(context, module, jobInput(context, module, unit, {
|
|
1924
|
-
tag,
|
|
1925
|
-
environment,
|
|
1926
|
-
commit: head
|
|
1927
|
-
}));
|
|
1928
|
-
output.line();
|
|
1929
|
-
output.line(` ${paint("bold", tag)} → ${plan.where}${tagged ? "" : paint("yellow", " (not tagged yet: release first)")}`);
|
|
1930
|
-
plan.jobs.forEach((job) => {
|
|
1931
|
-
output.line(` ${paint("dim", "this machine")}`);
|
|
1932
|
-
job.local.forEach((command) => output.line(` ${commandLine(command)}`));
|
|
1933
|
-
if (job.record) output.line(` ${paint("dim", `then record ${tag} on ${environment} in GitHub Deployments`)}`);
|
|
1934
|
-
if (job.ci) {
|
|
1935
|
-
const workflow = services.ciPipeline.shipWorkflow;
|
|
1936
|
-
output.line(` ${paint("dim", "GitHub Actions")}`);
|
|
1937
|
-
output.line(` gh workflow run ${workflow} --ref ${job.ci.ref} -f units=${unit.name} -f environment=${environment}`);
|
|
1938
|
-
}
|
|
1939
|
-
});
|
|
1940
|
-
}
|
|
1941
|
-
await planFollowUps(context, shipped);
|
|
1942
|
-
output.line();
|
|
1943
|
-
};
|
|
1944
|
-
//#endregion
|
|
1945
|
-
//#region src/domain/companions.ts
|
|
1946
|
-
/** The shortest chain of moving packages from `from` to one a changeset names, breadth first. */
|
|
1947
|
-
const chainTo = (from, dependencies, moving, named) => {
|
|
1948
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1949
|
-
let paths = [[from]];
|
|
1950
|
-
while (paths.length > 0) {
|
|
1951
|
-
const next = [];
|
|
1952
|
-
for (const path of paths) {
|
|
1953
|
-
const last = path[path.length - 1] ?? from;
|
|
1954
|
-
for (const dependency of dependencies[last] ?? []) {
|
|
1955
|
-
if (!moving.has(dependency) || seen.has(dependency)) continue;
|
|
1956
|
-
seen.add(dependency);
|
|
1957
|
-
const chain = [...path, dependency];
|
|
1958
|
-
if (named.has(dependency)) return chain.slice(1);
|
|
1959
|
-
next.push(chain);
|
|
1960
|
-
}
|
|
1961
|
-
}
|
|
1962
|
-
paths = next;
|
|
1963
|
-
}
|
|
1964
|
-
return [];
|
|
1965
|
-
};
|
|
1966
|
-
/**
|
|
1967
|
-
* Preview: the units a release moves that the person did not pick. changesets moves a unit whenever
|
|
1968
|
-
* a workspace package it uses moves, so it cannot stay behind; this says through which package.
|
|
1969
|
-
*/
|
|
1970
|
-
const draggedUnits = (plan, dependencies, units, scope) => {
|
|
1971
|
-
const moving = new Set(plan.releases.map(({ name }) => name));
|
|
1972
|
-
const named = new Set(plan.releases.filter(({ changesets }) => changesets.length > 0).map(({ name }) => name));
|
|
1973
|
-
const picked = units.filter(({ name }) => scope.has(name));
|
|
1974
|
-
return units.flatMap(({ name: app, packageName }) => {
|
|
1975
|
-
const release = plan.releases.find(({ name }) => name === packageName);
|
|
1976
|
-
if (scope.has(app) || !release) return [];
|
|
1977
|
-
const chain = chainTo(packageName, dependencies, moving, named);
|
|
1978
|
-
const source = chain[chain.length - 1];
|
|
1979
|
-
const movers = picked.filter((unit) => plan.changesets.some(({ releases }) => releases.some(({ name }) => name === source) && releases.some(({ name }) => name === unit.packageName))).map(({ name }) => name);
|
|
1980
|
-
const whose = movers.length > 0 ? `${movers.join(", ")}'s changes move` : "this release moves";
|
|
1981
|
-
return [{
|
|
1982
|
-
app,
|
|
1983
|
-
version: release.newVersion,
|
|
1984
|
-
with: movers,
|
|
1985
|
-
why: chain.length > 0 ? `uses ${chain.join(" → ")}, which ${whose}` : "moves with this release"
|
|
1986
|
-
}];
|
|
1987
|
-
});
|
|
1988
|
-
};
|
|
1989
|
-
const OWN_CHANGE = /^- ([0-9a-f]{7,40}): /gm;
|
|
1990
|
-
const DEPENDENCY_CHANGES = /^- Updated dependencies \[([^\]]+)\]/gm;
|
|
1991
|
-
/** The changes a version carries: its own, and those a package it uses moved for. */
|
|
1992
|
-
const changeIds = (notes) => new Set([...[...notes.matchAll(OWN_CHANGE)].flatMap(([, id]) => id ? [id] : []), ...[...notes.matchAll(DEPENDENCY_CHANGES)].flatMap(([, ids]) => (ids ?? "").split(",").map((id) => id.trim()))]);
|
|
1993
|
-
/** A change's first line in these notes, with an ellipsis when it goes on. */
|
|
1994
|
-
const summaryOf = (notes, id) => {
|
|
1995
|
-
const lines = notes.split("\n");
|
|
1996
|
-
const index = lines.findIndex((line) => line.startsWith(`- ${id}: `));
|
|
1997
|
-
const first = lines[index]?.slice(`- ${id}: `.length).trim();
|
|
1998
|
-
if (index < 0 || !first) return null;
|
|
1999
|
-
return /^ {2}\S/.test(lines[index + 1] ?? "") ? `${first}…` : first;
|
|
2000
|
-
};
|
|
2001
|
-
/** The packages listed under the `Updated dependencies` line that names this change. */
|
|
2002
|
-
const packagesMovedFor = (notes, id) => {
|
|
2003
|
-
const lines = notes.split("\n");
|
|
2004
|
-
const start = lines.findIndex((line) => line.startsWith("- Updated dependencies [") && line.includes(id));
|
|
2005
|
-
if (start < 0) return [];
|
|
2006
|
-
const listed = lines.slice(start + 1);
|
|
2007
|
-
const end = listed.findIndex((line) => !/^ {2}- \S+@/.test(line));
|
|
2008
|
-
return (end < 0 ? listed : listed.slice(0, end)).map((line) => line.trim().slice(2).replace(/@[^@]*$/, ""));
|
|
2009
|
-
};
|
|
2010
|
-
/** Why two versions went out together: the change they share, or the package both moved for. */
|
|
2011
|
-
const sharedReason = (partner, other, id) => {
|
|
2012
|
-
const summary = summaryOf(partner.notes, id) ?? summaryOf(other.notes, id);
|
|
2013
|
-
if (summary) return ` for: ${summary}`;
|
|
2014
|
-
const theirs = new Set(packagesMovedFor(partner.notes, id));
|
|
2015
|
-
const both = packagesMovedFor(other.notes, id).filter((name) => theirs.has(name));
|
|
2016
|
-
return both.length > 0 ? `: both use ${both.join(", ")}, which moved` : "";
|
|
2017
|
-
};
|
|
2018
|
-
/**
|
|
2019
|
-
* Production: the units preview runs with the picked ones that are not picked. Two versions went to
|
|
2020
|
-
* preview together when their notes share a change, their own or one a package they use moved for.
|
|
2021
|
-
*/
|
|
2022
|
-
const releasedTogether = (picked, others) => others.flatMap((other) => {
|
|
2023
|
-
const ids = changeIds(other.notes);
|
|
2024
|
-
const partners = picked.flatMap((partner) => {
|
|
2025
|
-
const shared = [...changeIds(partner.notes)].find((id) => ids.has(id));
|
|
2026
|
-
return shared ? [{
|
|
2027
|
-
partner,
|
|
2028
|
-
shared
|
|
2029
|
-
}] : [];
|
|
2030
|
-
});
|
|
2031
|
-
const [first] = partners;
|
|
2032
|
-
if (!first) return [];
|
|
2033
|
-
const names = partners.map(({ partner }) => `${partner.app} ${partner.version}`).join(", ");
|
|
2034
|
-
return [{
|
|
2035
|
-
app: other.app,
|
|
2036
|
-
version: other.version,
|
|
2037
|
-
with: partners.map(({ partner }) => partner.app),
|
|
2038
|
-
why: `went to preview with ${names}${sharedReason(first.partner, other, first.shared)}`
|
|
2039
|
-
}];
|
|
2040
|
-
});
|
|
2041
|
-
//#endregion
|
|
2042
|
-
//#region src/application/prepareRelease.ts
|
|
2043
|
-
const NOTHING_HELD = {
|
|
2044
|
-
ships: [],
|
|
2045
|
-
waits: []
|
|
2046
|
-
};
|
|
2047
|
-
/** The person's answer to a plugin's choice; the suggestion without a terminal or with --yes. */
|
|
2048
|
-
const choose = async ({ prompter, options }, choice) => {
|
|
2049
|
-
if (!choice) return null;
|
|
2050
|
-
if (options.yes || !prompter.interactive) return choice.suggested;
|
|
2051
|
-
return prompter.select(choice.question, choice.options, choice.suggested);
|
|
2052
|
-
};
|
|
2053
|
-
/** What each picked unit's plugin adds, given the unit's bump so far. One at a time: it may ask. */
|
|
2054
|
-
const contributionsOf = async (context, scope, bumps) => {
|
|
2055
|
-
const { head } = await context.services.sourceControl.position();
|
|
2056
|
-
const contributions = {};
|
|
2057
|
-
for (const unit of context.release.units.filter(({ name }) => scope.has(name))) {
|
|
2058
|
-
const module = moduleOf(context, unit);
|
|
2059
|
-
const version = module?.version?.bind(module);
|
|
2060
|
-
if (!module || !version) continue;
|
|
2061
|
-
const input = jobInput(context, module, unit, {
|
|
2062
|
-
tag: tagName(unit.name, unit.version, context.release.tagFormat),
|
|
2063
|
-
environment: "preview",
|
|
2064
|
-
commit: head
|
|
2065
|
-
});
|
|
2066
|
-
const bump = bumps.find(({ app }) => app === unit.name);
|
|
2067
|
-
const contribute = (chosen) => version(decideContext(context), {
|
|
2068
|
-
...input,
|
|
2069
|
-
bump,
|
|
2070
|
-
chosen
|
|
2071
|
-
});
|
|
2072
|
-
const suggested = await contribute();
|
|
2073
|
-
const chosen = await choose(context, suggested.choice);
|
|
2074
|
-
contributions[unit.name] = chosen && chosen !== suggested.choice?.suggested ? await contribute(chosen) : suggested;
|
|
2227
|
+
const plan = shipPlanOf(context, module, jobInput(context, module, unit, {
|
|
2228
|
+
tag,
|
|
2229
|
+
environment,
|
|
2230
|
+
commit: head
|
|
2231
|
+
}));
|
|
2232
|
+
output.line();
|
|
2233
|
+
output.line(` ${paint("bold", tag)} → ${plan.where}${tagged ? "" : paint("yellow", " (not tagged yet: release first)")}`);
|
|
2234
|
+
plan.jobs.forEach((job) => {
|
|
2235
|
+
output.line(` ${paint("dim", "this machine")}`);
|
|
2236
|
+
job.local.forEach((command) => output.line(` ${commandLine(command)}`));
|
|
2237
|
+
if (job.record) output.line(` ${paint("dim", `then record ${tag} on ${environment} in GitHub Deployments`)}`);
|
|
2238
|
+
if (job.ci) {
|
|
2239
|
+
const workflow = services.ciPipeline.shipWorkflow;
|
|
2240
|
+
output.line(` ${paint("dim", "GitHub Actions")}`);
|
|
2241
|
+
output.line(` gh workflow run ${workflow} --ref ${job.ci.ref} -f units=${unit.name} -f environment=${environment}`);
|
|
2242
|
+
}
|
|
2243
|
+
});
|
|
2075
2244
|
}
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
/** What a release PR covering `scope` would version, computed without writing anything. */
|
|
2079
|
-
const prepareRelease = async (context, scope) => {
|
|
2080
|
-
const { release, services } = context;
|
|
2081
|
-
const refs = unitRefs(release.units);
|
|
2082
|
-
const [dependencies, named, base, pendingFiles] = await Promise.all([
|
|
2083
|
-
services.versioning.dependencies(),
|
|
2084
|
-
namedUnits(context),
|
|
2085
|
-
services.versioning.plan([], []),
|
|
2086
|
-
services.versioning.pending()
|
|
2087
|
-
]);
|
|
2088
|
-
const baseBumps = appBumps(base, dependencies, refs);
|
|
2089
|
-
const unreleased = await findUnreleased(context, new Set([...named, ...baseBumps.map(({ app }) => app)]));
|
|
2090
|
-
const held = [...named].filter((app) => !scope.has(app));
|
|
2091
|
-
const adopted = unreleased.filter(({ app }) => scope.has(app)).flatMap(({ app, version, commits }) => {
|
|
2092
|
-
const ref = refs.find(({ name }) => name === app);
|
|
2093
|
-
return ref ? unreleasedChangesets(ref, version, commits) : [];
|
|
2094
|
-
});
|
|
2095
|
-
const split = held.length > 0 ? splitChangesets(base.changesets, held, refs) : NOTHING_HELD;
|
|
2096
|
-
const picked = held.length > 0 || adopted.length > 0 ? await services.versioning.plan(adopted, split.waits) : base;
|
|
2097
|
-
const contributions = await contributionsOf(context, scope, appBumps(picked, dependencies, refs));
|
|
2098
|
-
const contributed = Object.values(contributions).flatMap(({ added }) => added);
|
|
2099
|
-
const added = [...adopted, ...contributed];
|
|
2100
|
-
const plan = contributed.length > 0 ? await services.versioning.plan(added, split.waits) : picked;
|
|
2101
|
-
return {
|
|
2102
|
-
pending: (held.length > 0 ? split.ships.length : pendingFiles.length) + added.length,
|
|
2103
|
-
held,
|
|
2104
|
-
unreleased: unreleased.filter(({ app }) => !scope.has(app)),
|
|
2105
|
-
split,
|
|
2106
|
-
bumps: appBumps(plan, dependencies, refs),
|
|
2107
|
-
companions: draggedUnits(plan, dependencies, refs, scope),
|
|
2108
|
-
packages: packageBumps(plan, refs),
|
|
2109
|
-
added,
|
|
2110
|
-
shipped: plan.changesets,
|
|
2111
|
-
contributions
|
|
2112
|
-
};
|
|
2245
|
+
await planFollowUps(context, shipped);
|
|
2246
|
+
output.line();
|
|
2113
2247
|
};
|
|
2114
2248
|
//#endregion
|
|
2115
2249
|
//#region src/application/askPath.ts
|
|
@@ -2167,11 +2301,6 @@ const askPaths = async (context, environment, shipments) => {
|
|
|
2167
2301
|
//#endregion
|
|
2168
2302
|
//#region src/application/waitForMerge.ts
|
|
2169
2303
|
const POLL_MS = 15e3;
|
|
2170
|
-
const KEYS = [
|
|
2171
|
-
"d",
|
|
2172
|
-
"m",
|
|
2173
|
-
"o"
|
|
2174
|
-
];
|
|
2175
2304
|
/** Merges the pull request with the method the person picks. GitHub refuses approving your own PR. */
|
|
2176
2305
|
const mergeHere = async (context, pr) => {
|
|
2177
2306
|
const { choices, initial } = mergeChoices(await context.services.codeHost.mergeMethods());
|
|
@@ -2194,20 +2323,55 @@ const ACTIONS = {
|
|
|
2194
2323
|
merge: mergeHere,
|
|
2195
2324
|
open: (context, pr) => context.services.codeHost.openInBrowser(pr)
|
|
2196
2325
|
};
|
|
2326
|
+
/** The keys a wait offers. Someone else approves a release that requires it: no merge from here. */
|
|
2327
|
+
const hintsFor = (approvalRequired) => [
|
|
2328
|
+
{
|
|
2329
|
+
key: "d",
|
|
2330
|
+
label: "see the diff"
|
|
2331
|
+
},
|
|
2332
|
+
...approvalRequired ? [] : [{
|
|
2333
|
+
key: "m",
|
|
2334
|
+
label: "merge it from here"
|
|
2335
|
+
}],
|
|
2336
|
+
{
|
|
2337
|
+
key: "o",
|
|
2338
|
+
label: "open it on GitHub"
|
|
2339
|
+
},
|
|
2340
|
+
{
|
|
2341
|
+
key: "Ctrl-C",
|
|
2342
|
+
label: "leave, continue later"
|
|
2343
|
+
}
|
|
2344
|
+
];
|
|
2197
2345
|
/**
|
|
2198
|
-
*
|
|
2199
|
-
*
|
|
2346
|
+
* Polls the host until the PR merges or closes; in a terminal the person can also read the diff
|
|
2347
|
+
* (d), merge from here (m, unless approval is required) or open it in the browser (o). Without a
|
|
2348
|
+
* terminal, a release waiting on someone's approval is left for a later run instead.
|
|
2200
2349
|
*/
|
|
2201
2350
|
const waitForMerge = async (context, pr) => {
|
|
2202
2351
|
const { output, prompter, services } = context;
|
|
2352
|
+
const approvalRequired = context.release.flow.approval === "required";
|
|
2203
2353
|
output.line(` ${paint("green", "✓")} Release PR ${paint("cyan", pr.url)}`);
|
|
2204
|
-
|
|
2205
|
-
|
|
2354
|
+
if (approvalRequired) {
|
|
2355
|
+
output.line(` Waiting for approval on #${pr.number}. This can take a while.`);
|
|
2356
|
+
output.line(paint("dim", " It's safe to leave: run shiplane later and it picks up here."));
|
|
2357
|
+
} else output.line(paint("dim", " Review and merge it here or on GitHub; this carries on by itself once merged."));
|
|
2358
|
+
if (approvalRequired && !prompter.interactive) {
|
|
2359
|
+
const state = await services.codeHost.prState(pr).catch(() => "OPEN");
|
|
2360
|
+
if (state === "OPEN") return "left";
|
|
2361
|
+
return state === "MERGED" ? "merged" : "closed";
|
|
2362
|
+
}
|
|
2363
|
+
const hints = hintsFor(approvalRequired);
|
|
2364
|
+
if (prompter.interactive) {
|
|
2365
|
+
output.line();
|
|
2366
|
+
output.line(` ${keyHints(hints)}`);
|
|
2367
|
+
}
|
|
2206
2368
|
output.line();
|
|
2369
|
+
const keys = prompter.interactive ? hints.map(({ key }) => key).filter((key) => key.length === 1) : [];
|
|
2207
2370
|
for (;;) {
|
|
2208
2371
|
const state = await services.codeHost.prState(pr).catch(() => "OPEN");
|
|
2209
|
-
if (state !== "OPEN") return state === "MERGED";
|
|
2210
|
-
const
|
|
2372
|
+
if (state !== "OPEN") return state === "MERGED" ? "merged" : "closed";
|
|
2373
|
+
const key = await prompter.waitForKey(approvalRequired ? `Waiting for #${pr.number} to be approved and merged` : `Waiting for #${pr.number} to merge`, POLL_MS, keys);
|
|
2374
|
+
const action = key && keys.includes(key) ? waitKey(key) : null;
|
|
2211
2375
|
if (action) await ACTIONS[action](context, pr);
|
|
2212
2376
|
}
|
|
2213
2377
|
};
|
|
@@ -2703,6 +2867,38 @@ const tagRelease = async (context, tags) => {
|
|
|
2703
2867
|
};
|
|
2704
2868
|
//#endregion
|
|
2705
2869
|
//#region src/application/releaseToPreview.ts
|
|
2870
|
+
const plural = (count, word) => `${count} ${word}${count === 1 ? "" : "s"}`;
|
|
2871
|
+
/** The commits main gained since a release PR's branch, or none when the host did not say. */
|
|
2872
|
+
const movedPast = async (context, pr, originMain) => {
|
|
2873
|
+
if (!pr.head) return [];
|
|
2874
|
+
return context.services.sourceControl.commitsBetween(pr.head, originMain).catch(() => []);
|
|
2875
|
+
};
|
|
2876
|
+
/** Why a stale release PR closed, said on it, so a reviewer landing there knows where to go. */
|
|
2877
|
+
const closedComment = (replacement, subjects) => [
|
|
2878
|
+
`Closed by shiplane: ${plural(subjects.length, "commit")} ${subjects.length === 1 ? "was" : "were"} merged into main after this release PR was opened, so its changelog no longer matched what would ship.`,
|
|
2879
|
+
`Replaced by ${listed(replacement.map(({ number }) => `#${number}`))}, which versions everything merged so far. Please review that one.`,
|
|
2880
|
+
"",
|
|
2881
|
+
...subjects.map((subject) => `- ${subject}`)
|
|
2882
|
+
].join("\n");
|
|
2883
|
+
/**
|
|
2884
|
+
* Release PRs main moved past are replaced: a fresh one versions everything merged, then each
|
|
2885
|
+
* stale one closes with a comment pointing to it. The open ones, or null when that failed.
|
|
2886
|
+
*/
|
|
2887
|
+
const refreshStale = async (context, prs, scope) => {
|
|
2888
|
+
const { originMain } = await context.services.sourceControl.position();
|
|
2889
|
+
const moved = await Promise.all(prs.map((pr) => movedPast(context, pr, originMain)));
|
|
2890
|
+
const subjects = [...new Set(moved.flat().map(({ subject }) => subject))];
|
|
2891
|
+
if (subjects.length === 0) return prs;
|
|
2892
|
+
const { output, progress } = context;
|
|
2893
|
+
const names = listed(prs.map(({ number }) => `#${number}`));
|
|
2894
|
+
progress.say("thinking", `↻ Release ${names} is out of date: ${plural(subjects.length, "commit")} landed on main since.`);
|
|
2895
|
+
output.line(paint("dim", " Replacing it so the changelog matches what ships."));
|
|
2896
|
+
const opened = await openReleasePr(context, await prepareRelease(context, scope), prs);
|
|
2897
|
+
if (!opened) return null;
|
|
2898
|
+
for (const pr of prs) await context.services.codeHost.closePr(pr, closedComment(opened, subjects));
|
|
2899
|
+
output.line(` ${paint("green", "✓")} Opened ${listed(opened.map(({ number }) => `#${number}`))}${context.release.flow.approval === "required" ? " (needs approval again)" : ""} ${paint("green", "✓")} Closed ${names}, with a comment pointing to it`);
|
|
2900
|
+
return opened;
|
|
2901
|
+
};
|
|
2706
2902
|
const STAGES = [
|
|
2707
2903
|
"What to release",
|
|
2708
2904
|
"Versions",
|
|
@@ -2747,13 +2943,31 @@ const releaseToPreview = async (context) => {
|
|
|
2747
2943
|
const opened = await openReleasePr(context, prepared);
|
|
2748
2944
|
if (!opened) return false;
|
|
2749
2945
|
prs = opened;
|
|
2750
|
-
} else if (step.step === "wait-merge")
|
|
2946
|
+
} else if (step.step === "wait-merge") {
|
|
2947
|
+
const fresh = await refreshStale(context, step.prs, picked.scope);
|
|
2948
|
+
if (!fresh) return false;
|
|
2949
|
+
if (fresh === step.prs) {
|
|
2950
|
+
const waiting = context.release.flow.approval === "required" ? "approval" : "a merge";
|
|
2951
|
+
progress.say("thinking", `↻ Picking up release ${listed(fresh.map(({ number }) => `#${number}`))}: still waiting for ${waiting}`);
|
|
2952
|
+
output.line(paint("dim", " To cancel it, close it on GitHub."));
|
|
2953
|
+
}
|
|
2954
|
+
prs = fresh;
|
|
2955
|
+
} else if (missing.length > 0) {
|
|
2956
|
+
progress.say("thinking", `↻ Picking up a merged release`);
|
|
2957
|
+
output.line(paint("dim", ` Left to do: tag ${plural(missing.length, "version")} → ship to preview`));
|
|
2958
|
+
}
|
|
2751
2959
|
if (prs.length > 0) stage("Merge");
|
|
2752
2960
|
for (const pr of prs) {
|
|
2753
2961
|
output.line();
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2962
|
+
const outcome = await waitForMerge(context, pr);
|
|
2963
|
+
if (outcome === "closed") {
|
|
2964
|
+
progress.say("resting", `○ Release #${pr.number} was closed: nothing shipped.`);
|
|
2965
|
+
output.line(paint("dim", " Run shiplane to open a new release with everything pending."));
|
|
2966
|
+
return true;
|
|
2967
|
+
}
|
|
2968
|
+
if (outcome === "left") {
|
|
2969
|
+
output.line(paint("dim", ` Left #${pr.number} waiting. Run shiplane once it's approved.`));
|
|
2970
|
+
return true;
|
|
2757
2971
|
}
|
|
2758
2972
|
progress.say("happy", `${paint("green", "✓")} Release PR #${pr.number} merged`);
|
|
2759
2973
|
}
|
|
@@ -2777,56 +2991,710 @@ const releaseToPreview = async (context) => {
|
|
|
2777
2991
|
return shipTo(current, "preview", { scope: new Set([...picked.scope, ...tags.map(({ app }) => app)]) });
|
|
2778
2992
|
};
|
|
2779
2993
|
//#endregion
|
|
2994
|
+
//#region src/application/customAdapter.ts
|
|
2995
|
+
const CUSTOM_PORTS = {
|
|
2996
|
+
sourceControl: {
|
|
2997
|
+
key: "sourceControl",
|
|
2998
|
+
type: "SourceControlPort",
|
|
2999
|
+
label: "source control",
|
|
3000
|
+
kind: "flow",
|
|
3001
|
+
subject: `head: async () => (await port.position()).head,
|
|
3002
|
+
// TODO: write a file the repository does not track yet.
|
|
3003
|
+
change: () => Promise.resolve(),`
|
|
3004
|
+
},
|
|
3005
|
+
codeHost: {
|
|
3006
|
+
key: "codeHost",
|
|
3007
|
+
type: "CodeHostPort",
|
|
3008
|
+
label: "code host",
|
|
3009
|
+
kind: "flow",
|
|
3010
|
+
subject: `// TODO: a branch pushed with one commit, a tag, an issue comments can go on.
|
|
3011
|
+
branch: (name) => Promise.resolve(name),
|
|
3012
|
+
tag: () => Promise.resolve("app@1.0.0"),
|
|
3013
|
+
issue: { repository: "acme/repo", number: 1 },`
|
|
3014
|
+
},
|
|
3015
|
+
ciPipeline: {
|
|
3016
|
+
key: "ciPipeline",
|
|
3017
|
+
type: "CiPipelinePort",
|
|
3018
|
+
label: "CI pipeline",
|
|
3019
|
+
kind: "flow",
|
|
3020
|
+
subject: `// TODO: a workflow that exists and has never run.
|
|
3021
|
+
idle: "ship.yml",`
|
|
3022
|
+
},
|
|
3023
|
+
versioning: {
|
|
3024
|
+
key: "versioning",
|
|
3025
|
+
type: "VersioningPort",
|
|
3026
|
+
label: "versioning",
|
|
3027
|
+
kind: "flow",
|
|
3028
|
+
subject: `// TODO: a package this workspace holds, and its folder.
|
|
3029
|
+
workspace: { name: "@acme/api", folder: "apps/api" },`
|
|
3030
|
+
},
|
|
3031
|
+
serverHosting: {
|
|
3032
|
+
key: "serverHosting",
|
|
3033
|
+
type: "ServerHostingPort",
|
|
3034
|
+
label: "server hosting",
|
|
3035
|
+
kind: "delivery",
|
|
3036
|
+
subject: `{}`
|
|
3037
|
+
},
|
|
3038
|
+
staticHosting: {
|
|
3039
|
+
key: "staticHosting",
|
|
3040
|
+
type: "StaticHostingPort",
|
|
3041
|
+
label: "static hosting",
|
|
3042
|
+
kind: "delivery",
|
|
3043
|
+
subject: `{}`
|
|
3044
|
+
},
|
|
3045
|
+
mobileDistribution: {
|
|
3046
|
+
key: "mobileDistribution",
|
|
3047
|
+
type: "MobileDistributionPort",
|
|
3048
|
+
label: "mobile distribution",
|
|
3049
|
+
kind: "delivery",
|
|
3050
|
+
subject: `{}`
|
|
3051
|
+
},
|
|
3052
|
+
packageRegistry: {
|
|
3053
|
+
key: "packageRegistry",
|
|
3054
|
+
type: "PackageRegistryPort",
|
|
3055
|
+
label: "package registry",
|
|
3056
|
+
kind: "delivery",
|
|
3057
|
+
subject: `{}`
|
|
3058
|
+
}
|
|
3059
|
+
};
|
|
3060
|
+
/** `jenkinsCiPipeline` → `jenkins-ci-pipeline`. */
|
|
3061
|
+
const kebab = (name) => name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
3062
|
+
/** A factory name a person can type: a letter, then letters and digits. */
|
|
3063
|
+
const isFactoryName = (name) => /^[a-z][a-zA-Z0-9]*$/.test(name);
|
|
3064
|
+
/** The name offered first: `customCiPipeline`. */
|
|
3065
|
+
const suggestedName = (port) => `custom${port.charAt(0).toUpperCase()}${port.slice(1)}`;
|
|
3066
|
+
/** Where a custom adapter lives, and what the config imports it from. */
|
|
3067
|
+
const customFiles = (name) => ({
|
|
3068
|
+
file: `shiplane/adapters/${kebab(name)}.ts`,
|
|
3069
|
+
test: `shiplane/adapters/${kebab(name)}.test.ts`,
|
|
3070
|
+
from: `./shiplane/adapters/${kebab(name)}`
|
|
3071
|
+
});
|
|
3072
|
+
const share = (name) => ` * Works? Share it: publish it as shiplane-${kebab(name)}, or open a pull request at
|
|
3073
|
+
* https://github.com/arnaud-zg/packages so everyone gets it.`;
|
|
3074
|
+
/** The adapter's file: shiplane's in-memory one under your name, ready to be replaced. */
|
|
3075
|
+
const renderCustomAdapter = (port, name, pkg) => {
|
|
3076
|
+
const { type, label, kind } = CUSTOM_PORTS[port];
|
|
3077
|
+
const memory = `${port}Memory`;
|
|
3078
|
+
if (kind === "delivery") return `import type { DeliveryAdapter, ${type} } from "${pkg}";
|
|
3079
|
+
import { z } from "${pkg}";
|
|
3080
|
+
import { ${memory} } from "${pkg}/memory";
|
|
3081
|
+
|
|
3082
|
+
/**
|
|
3083
|
+
* ${name}: your own ${label}. It starts in memory: it records each delivery it is asked for and
|
|
3084
|
+
* ships nothing, so the release runs end to end while you write it. To make it real, replace the
|
|
3085
|
+
* spread with define${type.replace(/Port$/, "")}({ ... }) from "${pkg}" (see: shiplane docs ${port}).
|
|
3086
|
+
* ${kebab(name)}.test.ts runs the contract every ${label} passes.
|
|
3087
|
+
${share(name)}
|
|
3088
|
+
*/
|
|
3089
|
+
export const ${name} = (): DeliveryAdapter<${type}> => ({
|
|
3090
|
+
...${memory}(),
|
|
3091
|
+
name: "${name}",
|
|
3092
|
+
// The keys an app's unit file gives it: add yours, such as z.object({ service: z.string() }).
|
|
3093
|
+
settings: z.object({}),
|
|
3094
|
+
});
|
|
3095
|
+
`;
|
|
3096
|
+
return `import type { ${type}, ServiceAdapter } from "${pkg}";
|
|
3097
|
+
import { ${memory} } from "${pkg}/memory";
|
|
3098
|
+
|
|
3099
|
+
/**
|
|
3100
|
+
* ${name}: your own ${label}. It starts in memory: it records each call and does nothing real, so
|
|
3101
|
+
* the release runs end to end while you write it. Replace its methods one at a time;
|
|
3102
|
+
* ${kebab(name)}.test.ts runs the contract every ${label} passes.
|
|
3103
|
+
${share(name)}
|
|
3104
|
+
*/
|
|
3105
|
+
export const ${name} = (): ServiceAdapter<${type}> => ({
|
|
3106
|
+
name: "${name}",
|
|
3107
|
+
create: (context) => {
|
|
3108
|
+
const port: ${type} = ${memory}().create(context);
|
|
3109
|
+
// TODO: replace what it does with your own calls, for example:
|
|
3110
|
+
// port.someMethod = async (...args) => { ... };
|
|
3111
|
+
return port;
|
|
3112
|
+
},
|
|
3113
|
+
});
|
|
3114
|
+
`;
|
|
3115
|
+
};
|
|
3116
|
+
/** Its test: the port's contract, run on it. */
|
|
3117
|
+
const renderCustomTest = (port, name, pkg) => {
|
|
3118
|
+
const { kind, subject } = CUSTOM_PORTS[port];
|
|
3119
|
+
const contract = `${port}Contract`;
|
|
3120
|
+
const file = `./${kebab(name)}`;
|
|
3121
|
+
if (kind === "delivery") return `import { ${contract} } from "${pkg}/testing";
|
|
3122
|
+
|
|
3123
|
+
import { ${name} } from "${file}";
|
|
3124
|
+
|
|
3125
|
+
// The contract every ${CUSTOM_PORTS[port].label} passes. TODO: the settings an app gives it.
|
|
3126
|
+
${contract}([{ adapter: ${name}(), settings: ${subject} }]);
|
|
3127
|
+
`;
|
|
3128
|
+
return `import { ${contract}, systemShell } from "${pkg}/testing";
|
|
3129
|
+
|
|
3130
|
+
import { ${name} } from "${file}";
|
|
3131
|
+
|
|
3132
|
+
// The contract every ${CUSTOM_PORTS[port].label} passes: green means ${name} is done.
|
|
3133
|
+
${contract}("${name}", () => {
|
|
3134
|
+
const port = ${name}().create({ root: process.cwd(), shell: systemShell });
|
|
3135
|
+
return Promise.resolve({
|
|
3136
|
+
port,
|
|
3137
|
+
${subject}
|
|
3138
|
+
});
|
|
3139
|
+
});
|
|
3140
|
+
`;
|
|
3141
|
+
};
|
|
3142
|
+
//#endregion
|
|
3143
|
+
//#region src/application/rehearse.ts
|
|
3144
|
+
var StepFailed = class extends Error {};
|
|
3145
|
+
/** One rehearsal check under a spinner when there is one: true when `work` says it passed. */
|
|
3146
|
+
const check = async (context, label, work) => {
|
|
3147
|
+
const run = async () => {
|
|
3148
|
+
if (!await work()) throw new StepFailed();
|
|
3149
|
+
};
|
|
3150
|
+
try {
|
|
3151
|
+
if (context.progress) await context.progress.during(label, "working", run);
|
|
3152
|
+
else {
|
|
3153
|
+
await run();
|
|
3154
|
+
context.output.line(` ${paint("green", "✓")} ${label}`);
|
|
3155
|
+
}
|
|
3156
|
+
return true;
|
|
3157
|
+
} catch (error) {
|
|
3158
|
+
if (!(error instanceof StepFailed)) {
|
|
3159
|
+
context.output.line(` ${paint("red", "✗")} ${label}`);
|
|
3160
|
+
context.output.line(` ${paint("dim", error instanceof Error ? error.message : String(error))}`);
|
|
3161
|
+
} else if (!context.progress) context.output.line(` ${paint("red", "✗")} ${label}`);
|
|
3162
|
+
return false;
|
|
3163
|
+
}
|
|
3164
|
+
};
|
|
3165
|
+
/** The package manager this repository runs scripts with. */
|
|
3166
|
+
const runner = (context) => context.files.exists("pnpm-lock.yaml") ? "pnpm" : context.files.exists("yarn.lock") ? "yarn" : context.files.exists("bun.lock") || context.files.exists("bun.lockb") ? "bun" : "npm";
|
|
3167
|
+
/** How a unit builds: its `buildCommand:`, else its package.json "build" script, else nothing. */
|
|
3168
|
+
const buildCommandOf = (context, unit) => {
|
|
3169
|
+
if (unit.buildCommand) return {
|
|
3170
|
+
command: "sh",
|
|
3171
|
+
args: ["-c", unit.buildCommand],
|
|
3172
|
+
shown: unit.buildCommand
|
|
3173
|
+
};
|
|
3174
|
+
if (!JSON.parse(context.files.read(path.posix.join(unit.dir, "package.json")) ?? "{}").scripts?.build) return null;
|
|
3175
|
+
const pm = runner(context);
|
|
3176
|
+
return {
|
|
3177
|
+
command: pm,
|
|
3178
|
+
args: ["run", "build"],
|
|
3179
|
+
shown: `${pm} run build`
|
|
3180
|
+
};
|
|
3181
|
+
};
|
|
3182
|
+
/**
|
|
3183
|
+
* A release played through with nothing pushed, published or deployed: the config loads, every app
|
|
3184
|
+
* builds, every ship plan resolves, every sign-in is there. Each failure says how to fix it.
|
|
3185
|
+
*/
|
|
3186
|
+
const rehearse = async (context) => {
|
|
3187
|
+
const { output, shell, root } = context;
|
|
3188
|
+
output.line();
|
|
3189
|
+
output.line(` ${paint("bold", "Rehearsal")} ${paint("dim", "· nothing is pushed, published or deployed")}`);
|
|
3190
|
+
const release = await context.load();
|
|
3191
|
+
if (release.problems.length > 0) {
|
|
3192
|
+
release.problems.forEach(({ file, line, message, hint }) => {
|
|
3193
|
+
output.line(` ${paint("red", "✗")} ${line === void 0 ? file : `${file}:${line}`} ${message}`);
|
|
3194
|
+
if (hint) output.line(` ${paint("dim", hint)}`);
|
|
3195
|
+
});
|
|
3196
|
+
return false;
|
|
3197
|
+
}
|
|
3198
|
+
const builds = release.units.flatMap((unit) => {
|
|
3199
|
+
const build = buildCommandOf(context, unit);
|
|
3200
|
+
return build ? [{
|
|
3201
|
+
unit,
|
|
3202
|
+
build
|
|
3203
|
+
}] : [];
|
|
3204
|
+
});
|
|
3205
|
+
const results = [];
|
|
3206
|
+
const built = builds.length === 0 || await check(context, `build ${builds.length} app${builds.length === 1 ? "" : "s"}`, async () => {
|
|
3207
|
+
results.push(...await Promise.all(builds.map(async ({ unit, build }) => {
|
|
3208
|
+
const started = Date.now();
|
|
3209
|
+
const result = await shell.capture(build.command, build.args, { cwd: path.join(root, unit.dir) });
|
|
3210
|
+
return {
|
|
3211
|
+
unit,
|
|
3212
|
+
shown: build.shown,
|
|
3213
|
+
failed: result.status !== 0,
|
|
3214
|
+
seconds: `${((Date.now() - started) / 1e3).toFixed(1)}s`,
|
|
3215
|
+
tail: `${result.stderr}${result.stdout}`.trim().split("\n").slice(-3)
|
|
3216
|
+
};
|
|
3217
|
+
})));
|
|
3218
|
+
return results.every(({ failed }) => !failed);
|
|
3219
|
+
});
|
|
3220
|
+
for (const { unit, shown, failed, seconds, tail } of results) {
|
|
3221
|
+
output.line(` ${failed ? paint("red", "✗") : paint("green", "✓")} ${unit.dir.padEnd(18)}${paint("dim", `${shown} ${seconds}`)}`);
|
|
3222
|
+
if (!failed) continue;
|
|
3223
|
+
tail.forEach((line) => output.line(` ${paint("dim", line)}`));
|
|
3224
|
+
output.line(` ${paint("dim", `fix the build, or set buildCommand: in ${unit.file}`)}`);
|
|
3225
|
+
}
|
|
3226
|
+
const releaseContext = context.compose?.(release);
|
|
3227
|
+
const planned = !releaseContext || await check(context, `plan ${release.units.length} apps, nothing runs`, async () => {
|
|
3228
|
+
const { head } = await releaseContext.services.sourceControl.position();
|
|
3229
|
+
for (const unit of release.units) {
|
|
3230
|
+
const module = moduleOf(releaseContext, unit);
|
|
3231
|
+
if (!module) continue;
|
|
3232
|
+
shipPlanOf(releaseContext, module, jobInput(releaseContext, module, unit, {
|
|
3233
|
+
tag: tagName(unit.name, unit.version, release.tagFormat),
|
|
3234
|
+
environment: "preview",
|
|
3235
|
+
commit: head
|
|
3236
|
+
}));
|
|
3237
|
+
}
|
|
3238
|
+
return true;
|
|
3239
|
+
});
|
|
3240
|
+
let signedIn = true;
|
|
3241
|
+
for (const requirement of requirementsOf(release)) {
|
|
3242
|
+
const status = await checkStatus(shell, root, requirement);
|
|
3243
|
+
if (await check(context, requirement.label, () => Promise.resolve(status === 0))) continue;
|
|
3244
|
+
signedIn = false;
|
|
3245
|
+
const fix = status === 127 ? `not installed: ${requirement.check.command}` : requirement.fix ? `run ${commandLine(requirement.fix)}, then shiplane setup` : "not available here";
|
|
3246
|
+
output.line(` ${paint("dim", fix)}`);
|
|
3247
|
+
}
|
|
3248
|
+
return built && planned && signedIn;
|
|
3249
|
+
};
|
|
3250
|
+
//#endregion
|
|
3251
|
+
//#region src/application/setup.ts
|
|
3252
|
+
const ok = paint("green", "✓");
|
|
3253
|
+
const unsure = paint("yellow", "?");
|
|
3254
|
+
/** What a flow port is called, and what proves the ready-made adapter fits. */
|
|
3255
|
+
const FLOW_LABEL = {
|
|
3256
|
+
sourceControl: {
|
|
3257
|
+
label: "Source control",
|
|
3258
|
+
ready: "git"
|
|
3259
|
+
},
|
|
3260
|
+
codeHost: {
|
|
3261
|
+
label: "Code host",
|
|
3262
|
+
ready: "GitHub"
|
|
3263
|
+
},
|
|
3264
|
+
ciPipeline: {
|
|
3265
|
+
label: "CI pipeline",
|
|
3266
|
+
ready: "GitHub Actions"
|
|
3267
|
+
},
|
|
3268
|
+
versioning: {
|
|
3269
|
+
label: "Versioning",
|
|
3270
|
+
ready: "Changesets"
|
|
3271
|
+
}
|
|
3272
|
+
};
|
|
3273
|
+
/** The kinds of app a person picks from, in their words, and the delivery each one needs. */
|
|
3274
|
+
const APP_KINDS = [
|
|
3275
|
+
{
|
|
3276
|
+
value: "server-hosting",
|
|
3277
|
+
label: "Backend service",
|
|
3278
|
+
hint: "a server that runs"
|
|
3279
|
+
},
|
|
3280
|
+
{
|
|
3281
|
+
value: "static-hosting",
|
|
3282
|
+
label: "Web application",
|
|
3283
|
+
hint: "static files on a CDN"
|
|
3284
|
+
},
|
|
3285
|
+
{
|
|
3286
|
+
value: "mobile-distribution",
|
|
3287
|
+
label: "Mobile application",
|
|
3288
|
+
hint: "store builds and updates"
|
|
3289
|
+
},
|
|
3290
|
+
{
|
|
3291
|
+
value: "package-registry",
|
|
3292
|
+
label: "Published package",
|
|
3293
|
+
hint: "a library others install"
|
|
3294
|
+
},
|
|
3295
|
+
{
|
|
3296
|
+
value: "skip",
|
|
3297
|
+
label: "Internal tool",
|
|
3298
|
+
hint: "versioned, never deployed"
|
|
3299
|
+
}
|
|
3300
|
+
];
|
|
3301
|
+
const CUSTOM_PORT_OF = {
|
|
3302
|
+
"server-hosting": "serverHosting",
|
|
3303
|
+
"static-hosting": "staticHosting",
|
|
3304
|
+
"mobile-distribution": "mobileDistribution",
|
|
3305
|
+
"package-registry": "packageRegistry"
|
|
3306
|
+
};
|
|
3307
|
+
const MODULE_OF = {
|
|
3308
|
+
sourceControl: "",
|
|
3309
|
+
codeHost: "",
|
|
3310
|
+
ciPipeline: "",
|
|
3311
|
+
versioning: "",
|
|
3312
|
+
serverHosting: "backendService",
|
|
3313
|
+
staticHosting: "webApp",
|
|
3314
|
+
mobileDistribution: "mobileApp",
|
|
3315
|
+
packageRegistry: "publishedPackage"
|
|
3316
|
+
};
|
|
3317
|
+
/** What proves each ready-made flow adapter fits this repository: hard evidence only. */
|
|
3318
|
+
const flowEvidence = async (context) => {
|
|
3319
|
+
const { files, shell, root } = context;
|
|
3320
|
+
const remote = files.exists(".git") ? (await shell.capture("git", [
|
|
3321
|
+
"remote",
|
|
3322
|
+
"get-url",
|
|
3323
|
+
"origin"
|
|
3324
|
+
], { cwd: root })).stdout.trim() : "";
|
|
3325
|
+
const github = /github\.com[:/]([^/]+\/[^/.]+)/.exec(remote)?.[1];
|
|
3326
|
+
const workflows = files.list(".github/workflows").filter((file) => /\.ya?ml$/.test(file));
|
|
3327
|
+
return {
|
|
3328
|
+
sourceControl: files.exists(".git") ? ".git" : null,
|
|
3329
|
+
codeHost: github ? `remote github.com/${github}` : null,
|
|
3330
|
+
ciPipeline: workflows[0] ? `.github/workflows/${workflows[0]}` : null,
|
|
3331
|
+
versioning: files.exists(".changeset/config.json") ? ".changeset/config.json" : null
|
|
3332
|
+
};
|
|
3333
|
+
};
|
|
3334
|
+
/** A name for a custom adapter: asked, checked, unused. Null when cancelled. */
|
|
3335
|
+
const askName = async (context, port, initial) => {
|
|
3336
|
+
const { prompter, output, files } = context;
|
|
3337
|
+
for (;;) {
|
|
3338
|
+
const name = await prompter.text("Name it (you can rename it later)", initial);
|
|
3339
|
+
if (name === null) return null;
|
|
3340
|
+
if (!isFactoryName(name)) {
|
|
3341
|
+
output.line(` ${paint("red", "✗")} ${name}: a name like ${suggestedName(port)}`);
|
|
3342
|
+
continue;
|
|
3343
|
+
}
|
|
3344
|
+
if (files.exists(customFiles(name).file)) {
|
|
3345
|
+
output.line(` ${paint("red", "✗")} ${customFiles(name).file} already exists`);
|
|
3346
|
+
continue;
|
|
3347
|
+
}
|
|
3348
|
+
return name;
|
|
3349
|
+
}
|
|
3350
|
+
};
|
|
3351
|
+
/** The custom adapter's two files. */
|
|
3352
|
+
const customWrites = (port, name, pkg) => [{
|
|
3353
|
+
file: customFiles(name).file,
|
|
3354
|
+
text: renderCustomAdapter(port, name, pkg),
|
|
3355
|
+
created: true
|
|
3356
|
+
}, {
|
|
3357
|
+
file: customFiles(name).test,
|
|
3358
|
+
text: renderCustomTest(port, name, pkg),
|
|
3359
|
+
created: true
|
|
3360
|
+
}];
|
|
3361
|
+
/** The flow, from what the repository proves; asked part by part when unsure or when asked to. */
|
|
3362
|
+
const chooseFlow = async (context, yes, needsPerson, writes, pkg) => {
|
|
3363
|
+
const { output, prompter } = context;
|
|
3364
|
+
const evidence = await flowEvidence(context);
|
|
3365
|
+
output.line(paint("bold", " Flow"));
|
|
3366
|
+
FLOW_PORTS.forEach((port) => {
|
|
3367
|
+
const proof = evidence[port];
|
|
3368
|
+
const { label, ready } = FLOW_LABEL[port];
|
|
3369
|
+
output.line(proof ? ` ${ok} ${ready.padEnd(16)}${paint("dim", proof)}` : ` ${unsure} ${label.padEnd(16)}${paint("dim", "not sure: nothing here proves one")}`);
|
|
3370
|
+
});
|
|
3371
|
+
if (FLOW_PORTS.every((port) => evidence[port] !== null)) return DEFAULT_FLOW;
|
|
3372
|
+
if (yes) {
|
|
3373
|
+
needsPerson.push(...FLOW_PORTS.filter((port) => !evidence[port]).map((port) => `the ${FLOW_LABEL[port].label.toLowerCase()} (nothing proves one)`));
|
|
3374
|
+
return null;
|
|
3375
|
+
}
|
|
3376
|
+
const flow = { ...DEFAULT_FLOW };
|
|
3377
|
+
for (const port of FLOW_PORTS) {
|
|
3378
|
+
const { label, ready } = FLOW_LABEL[port];
|
|
3379
|
+
const picked = await prompter.select(`${label}?`, [{
|
|
3380
|
+
value: "ready",
|
|
3381
|
+
label: ready,
|
|
3382
|
+
hint: `${DEFAULT_FLOW[port].from}${evidence[port] ? "" : ", not found here"}`
|
|
3383
|
+
}, {
|
|
3384
|
+
value: "custom",
|
|
3385
|
+
label: "Custom",
|
|
3386
|
+
hint: "a no-op in memory you implement"
|
|
3387
|
+
}], evidence[port] ? "ready" : "custom");
|
|
3388
|
+
if (picked === null) return null;
|
|
3389
|
+
if (picked === "custom") {
|
|
3390
|
+
const name = await askName(context, port, suggestedName(port));
|
|
3391
|
+
if (name === null) return null;
|
|
3392
|
+
flow[port] = {
|
|
3393
|
+
factory: name,
|
|
3394
|
+
from: customFiles(name).from
|
|
3395
|
+
};
|
|
3396
|
+
writes.push(...customWrites(port, name, pkg));
|
|
3397
|
+
}
|
|
3398
|
+
}
|
|
3399
|
+
return flow;
|
|
3400
|
+
};
|
|
3401
|
+
/** Where the apps live: prefilled from the workspace when those folders exist, else typed. */
|
|
3402
|
+
const chooseFolders = async (context, yes, needsPerson) => {
|
|
3403
|
+
const { prompter, output, files } = context;
|
|
3404
|
+
const known = workspacePatterns(files).filter((pattern) => pattern.startsWith("!") || expandPatterns(files, [pattern]).length > 0);
|
|
3405
|
+
const found = expandPatterns(files, known).filter((dir) => dir !== ".");
|
|
3406
|
+
output.line();
|
|
3407
|
+
output.line(paint("bold", " Apps"));
|
|
3408
|
+
if (found.length > 0) {
|
|
3409
|
+
const patterns = known.filter((pattern) => !pattern.startsWith("!")).join(", ");
|
|
3410
|
+
if (yes || await prompter.confirm(`Your apps and packages are in ${patterns} (${found.length} folders)?`, true)) return known;
|
|
3411
|
+
} else if (yes) {
|
|
3412
|
+
needsPerson.push("where the apps are (no workspace folders found)");
|
|
3413
|
+
return null;
|
|
3414
|
+
}
|
|
3415
|
+
for (;;) {
|
|
3416
|
+
const typed = await prompter.text("Where are your apps and packages? (e.g. apps/*, web)");
|
|
3417
|
+
if (typed === null) return null;
|
|
3418
|
+
const patterns = typed.split(",").map((part) => part.trim()).filter(Boolean);
|
|
3419
|
+
const empty = patterns.filter((pattern) => expandPatterns(files, [pattern]).length === 0);
|
|
3420
|
+
if (patterns.length > 0 && empty.length === 0) return patterns;
|
|
3421
|
+
output.line(` ${paint("red", "✗")} ${empty.join(", ") || "nothing typed"} matches no folder: try again`);
|
|
3422
|
+
}
|
|
3423
|
+
};
|
|
3424
|
+
/** Folders under these patterns with a manifest and no unit file yet. */
|
|
3425
|
+
const newFolders = (context, patterns) => expandPatterns(context.files, patterns).filter((dir) => dir !== "." && context.files.exists(path.posix.join(dir, "package.json"))).filter((dir) => !UNIT_FILES.some((name) => context.files.exists(path.posix.join(dir, name)))).map((dir) => folderView(context.files, dir));
|
|
3426
|
+
/** How a folder ships: taken when an adapter is sure, asked otherwise. Null: not shipped. */
|
|
3427
|
+
const placeFolder = async (context, folder, state) => {
|
|
3428
|
+
const { prompter, output, adapters } = context;
|
|
3429
|
+
const sure = adapters.map((adapter) => ({
|
|
3430
|
+
adapter,
|
|
3431
|
+
detection: adapter.detect?.(folder) ?? null
|
|
3432
|
+
})).find(({ detection }) => detection?.certainty === "found");
|
|
3433
|
+
const place = (adapter) => {
|
|
3434
|
+
const { name, entry } = placeModule(adapter, state.modules, state.pkg);
|
|
3435
|
+
if (entry) {
|
|
3436
|
+
state.entries.push(entry);
|
|
3437
|
+
state.modules.push(moduleFor(adapter, name));
|
|
3438
|
+
}
|
|
3439
|
+
return name;
|
|
3440
|
+
};
|
|
3441
|
+
if (sure?.detection) {
|
|
3442
|
+
const kind = APP_KINDS.find(({ value }) => value === sure.adapter.capability)?.label ?? "";
|
|
3443
|
+
output.line(` ${ok} ${folder.dir.padEnd(18)}${kind} → ${sure.adapter.name} ${paint("dim", `proof: ${sure.detection.reason}`)}`);
|
|
3444
|
+
const options = await askOptions(context, folder, sure.adapter, sure.detection.options, state.yes);
|
|
3445
|
+
return {
|
|
3446
|
+
folder,
|
|
3447
|
+
module: place(sure.adapter),
|
|
3448
|
+
options,
|
|
3449
|
+
reason: sure.detection.reason
|
|
3450
|
+
};
|
|
3451
|
+
}
|
|
3452
|
+
if (state.yes) {
|
|
3453
|
+
state.needsPerson.push(`${folder.dir} (no adapter is sure what it is)`);
|
|
3454
|
+
return null;
|
|
3455
|
+
}
|
|
3456
|
+
output.line(` ${unsure} ${folder.dir.padEnd(18)}${paint("dim", "not sure what this is")}`);
|
|
3457
|
+
const answer = await prompter.select(`What is ${folder.dir}?`, [...state.modules.map((module) => ({
|
|
3458
|
+
value: `module:${module.name}`,
|
|
3459
|
+
label: `Like ${module.name}`,
|
|
3460
|
+
hint: `${module.kind} on ${module.provider}, already in your config`
|
|
3461
|
+
})), ...APP_KINDS.map(({ value, label, hint }) => ({
|
|
3462
|
+
value,
|
|
3463
|
+
label,
|
|
3464
|
+
hint
|
|
3465
|
+
}))]);
|
|
3466
|
+
if (answer === null) return null;
|
|
3467
|
+
if (answer.startsWith("module:")) return {
|
|
3468
|
+
folder,
|
|
3469
|
+
module: answer.slice(7),
|
|
3470
|
+
options: {}
|
|
3471
|
+
};
|
|
3472
|
+
const kind = answer;
|
|
3473
|
+
if (kind === "skip") return "skip";
|
|
3474
|
+
const fitting = adapters.filter((a) => a.capability === kind);
|
|
3475
|
+
const picked = fitting.length === 0 ? "custom" : await prompter.select(`Where does ${folder.dir} go?`, [...fitting.map((adapter) => ({
|
|
3476
|
+
value: adapter.name,
|
|
3477
|
+
label: adapter.name
|
|
3478
|
+
})), {
|
|
3479
|
+
value: "custom",
|
|
3480
|
+
label: "Custom",
|
|
3481
|
+
hint: "a no-op adapter you implement"
|
|
3482
|
+
}], fitting[0]?.name);
|
|
3483
|
+
if (picked === null) return null;
|
|
3484
|
+
const adapter = fitting.find(({ name }) => name === picked);
|
|
3485
|
+
if (adapter) {
|
|
3486
|
+
const options = await askOptions(context, folder, adapter, {}, false);
|
|
3487
|
+
return {
|
|
3488
|
+
folder,
|
|
3489
|
+
module: place(adapter),
|
|
3490
|
+
options
|
|
3491
|
+
};
|
|
3492
|
+
}
|
|
3493
|
+
const port = CUSTOM_PORT_OF[kind];
|
|
3494
|
+
const name = await askName(context, port, `${path.posix.basename(folder.dir)}Delivery`.replace(/-([a-z])/g, (_m, c) => c.toUpperCase()));
|
|
3495
|
+
if (name === null) return null;
|
|
3496
|
+
const module = kebab(name);
|
|
3497
|
+
state.entries.push({
|
|
3498
|
+
factory: MODULE_OF[port],
|
|
3499
|
+
port,
|
|
3500
|
+
adapter: name,
|
|
3501
|
+
name: module,
|
|
3502
|
+
from: customFiles(name).from
|
|
3503
|
+
});
|
|
3504
|
+
state.writes.push(...customWrites(port, name, state.pkg));
|
|
3505
|
+
return {
|
|
3506
|
+
folder,
|
|
3507
|
+
module,
|
|
3508
|
+
options: {}
|
|
3509
|
+
};
|
|
3510
|
+
};
|
|
3511
|
+
/** The command that builds a folder: its unit's, its package.json script's, or one asked once. */
|
|
3512
|
+
const buildFor = async (context, folder, yes) => {
|
|
3513
|
+
if (JSON.parse(context.files.read(path.posix.join(folder.dir, "package.json")) ?? "{}").scripts?.build) return null;
|
|
3514
|
+
if (yes) return null;
|
|
3515
|
+
const typed = await context.prompter.text(`${folder.dir} has no "build" script. Command to build it? (empty: nothing to build)`);
|
|
3516
|
+
return typed?.trim() ? typed.trim() : null;
|
|
3517
|
+
};
|
|
3518
|
+
/**
|
|
3519
|
+
* `shiplane setup`: the one command to set releases up and keep them right. It reads the
|
|
3520
|
+
* repository, takes what it can prove, asks only the rest, then rehearses a release (builds, plan,
|
|
3521
|
+
* sign-ins) with nothing pushed or deployed. Files are kept only when the rehearsal passes. Run
|
|
3522
|
+
* again, it says all is set or offers what changed.
|
|
3523
|
+
*/
|
|
3524
|
+
const setup = async (context, { yes }) => {
|
|
3525
|
+
const { output, prompter, files } = context;
|
|
3526
|
+
const pkg = releasePackage(files);
|
|
3527
|
+
const needsPerson = [];
|
|
3528
|
+
const writes = [];
|
|
3529
|
+
output.line();
|
|
3530
|
+
output.line(` ${paint("bold", "shiplane setup")} ${paint("dim", path.basename(context.root))}`);
|
|
3531
|
+
output.line();
|
|
3532
|
+
const existing = files.exists("shiplane.config.ts") ? await context.load() : null;
|
|
3533
|
+
if (existing && existing.problems.length > 0) {
|
|
3534
|
+
existing.problems.forEach(({ file, line, message, hint }) => {
|
|
3535
|
+
output.line(` ${paint("red", "✗")} ${paint("bold", line === void 0 ? file : `${file}:${line}`)} ${message}`);
|
|
3536
|
+
if (hint) output.line(` ${paint("dim", hint)}`);
|
|
3537
|
+
});
|
|
3538
|
+
output.line(` ${paint("dim", "Fix these, then run shiplane setup again. Nothing written.")}`);
|
|
3539
|
+
return false;
|
|
3540
|
+
}
|
|
3541
|
+
const flow = existing ? null : await chooseFlow(context, yes, needsPerson, writes, pkg);
|
|
3542
|
+
if (existing) output.line(` ${ok} flow ${paint("dim", CONFIG_FILE)}`);
|
|
3543
|
+
else if (!flow && needsPerson.length === 0) return cancelled(context);
|
|
3544
|
+
const patterns = existing ? existing.units.length > 0 ? workspacePatterns(files) : await chooseFolders(context, yes, needsPerson) : await chooseFolders(context, yes, needsPerson);
|
|
3545
|
+
if (!patterns && needsPerson.length === 0) return cancelled(context);
|
|
3546
|
+
if (existing && existing.units.length > 0) output.line(` ${ok} ${existing.units.length} apps ${paint("dim", "unchanged, your edits kept")}`);
|
|
3547
|
+
const modules = [...existing?.modules ?? []];
|
|
3548
|
+
const entries = [];
|
|
3549
|
+
const placed = [];
|
|
3550
|
+
for (const folder of patterns ? newFolders(context, patterns) : []) {
|
|
3551
|
+
const result = await placeFolder(context, folder, {
|
|
3552
|
+
yes,
|
|
3553
|
+
needsPerson,
|
|
3554
|
+
modules,
|
|
3555
|
+
entries,
|
|
3556
|
+
writes,
|
|
3557
|
+
pkg
|
|
3558
|
+
});
|
|
3559
|
+
if (result === null && needsPerson.length === 0) return cancelled(context);
|
|
3560
|
+
if (result && result !== "skip") {
|
|
3561
|
+
const buildCommand = await buildFor(context, folder, yes);
|
|
3562
|
+
placed.push(buildCommand ? {
|
|
3563
|
+
...result,
|
|
3564
|
+
options: {
|
|
3565
|
+
buildCommand,
|
|
3566
|
+
...result.options
|
|
3567
|
+
}
|
|
3568
|
+
} : result);
|
|
3569
|
+
}
|
|
3570
|
+
}
|
|
3571
|
+
if (needsPerson.length > 0) {
|
|
3572
|
+
output.line();
|
|
3573
|
+
output.line(` ${paint("red", "✗")} ${needsPerson.length} thing${needsPerson.length === 1 ? "" : "s"} need${needsPerson.length === 1 ? "s" : ""} a person:`);
|
|
3574
|
+
needsPerson.forEach((item) => output.line(` ${item}`));
|
|
3575
|
+
output.line(` ${paint("dim", "Run shiplane setup without --yes. Nothing written.")}`);
|
|
3576
|
+
return false;
|
|
3577
|
+
}
|
|
3578
|
+
if (!existing) {
|
|
3579
|
+
const units = patterns && patterns.join() !== workspacePatterns(files).join() ? patterns : void 0;
|
|
3580
|
+
writes.unshift({
|
|
3581
|
+
file: CONFIG_FILE,
|
|
3582
|
+
text: renderConfig(entries, pkg, flow ?? DEFAULT_FLOW, units),
|
|
3583
|
+
created: true
|
|
3584
|
+
});
|
|
3585
|
+
} else if (entries.length > 0) {
|
|
3586
|
+
let config = files.read("shiplane.config.ts") ?? "";
|
|
3587
|
+
for (const entry of entries) config = addToConfig(config, entry, pkg) ?? config;
|
|
3588
|
+
writes.unshift({
|
|
3589
|
+
file: CONFIG_FILE,
|
|
3590
|
+
text: config,
|
|
3591
|
+
created: false
|
|
3592
|
+
});
|
|
3593
|
+
}
|
|
3594
|
+
placed.forEach(({ folder, module, options, reason }) => writes.push({
|
|
3595
|
+
file: path.posix.join(folder.dir, UNIT_FILE),
|
|
3596
|
+
text: renderUnit(module, options, {
|
|
3597
|
+
reason,
|
|
3598
|
+
schemaLine: schemaLineFor(folder.dir)
|
|
3599
|
+
}),
|
|
3600
|
+
created: true
|
|
3601
|
+
}));
|
|
3602
|
+
if (writes.length === 0) {
|
|
3603
|
+
const passed = await rehearse(context);
|
|
3604
|
+
if (passed) output.line(` ${ok} all set`);
|
|
3605
|
+
return passed;
|
|
3606
|
+
}
|
|
3607
|
+
const before = [...writes.map(({ file }) => file), SCHEMA_FILE].map((file) => ({
|
|
3608
|
+
file,
|
|
3609
|
+
text: files.read(file)
|
|
3610
|
+
}));
|
|
3611
|
+
writes.forEach(({ file, text }) => files.write(file, text));
|
|
3612
|
+
if (existing === null || entries.length > 0) {
|
|
3613
|
+
const release = await context.load();
|
|
3614
|
+
if (release.modules.length > 0) files.write(SCHEMA_FILE, schemaText(release.modules));
|
|
3615
|
+
}
|
|
3616
|
+
const passed = await rehearse(context);
|
|
3617
|
+
if (!(passed && (yes || await prompter.confirm("Releasable. Write it?", true)))) {
|
|
3618
|
+
before.forEach(({ file, text }) => text === null ? files.remove(file) : files.write(file, text));
|
|
3619
|
+
output.line(` ${paint("dim", passed ? "Nothing written." : "Fix it, then run shiplane setup again. Nothing written.")}`);
|
|
3620
|
+
return false;
|
|
3621
|
+
}
|
|
3622
|
+
writes.forEach(({ file, created }) => output.line(` ${created ? paint("green", "+") : paint("yellow", "~")} ${file}`));
|
|
3623
|
+
if (writes.some(({ file }) => file.startsWith("shiplane/adapters/"))) {
|
|
3624
|
+
output.line(` ${paint("dim", "Custom adapters start in memory: fill them in until their contract test passes.")}`);
|
|
3625
|
+
output.line(` ${paint("dim", "Works? Share it as shiplane-<name>, or open a pull request at github.com/arnaud-zg/packages.")}`);
|
|
3626
|
+
}
|
|
3627
|
+
output.line();
|
|
3628
|
+
output.line(` ${ok} ${paint("bold", "Ready.")} Add a changeset, merge, and run ${paint("cyan", "shiplane")}`);
|
|
3629
|
+
return true;
|
|
3630
|
+
};
|
|
3631
|
+
const cancelled = (context) => {
|
|
3632
|
+
context.output.line(` ${paint("dim", "Nothing written.")}`);
|
|
3633
|
+
return false;
|
|
3634
|
+
};
|
|
3635
|
+
//#endregion
|
|
2780
3636
|
//#region src/adapters/terminal/live-line.ts
|
|
2781
|
-
const CLEAR = "\r\x1B[2K";
|
|
2782
3637
|
const TICK_MS = 140;
|
|
2783
3638
|
/**
|
|
2784
|
-
* The one line the release redraws in place
|
|
2785
|
-
*
|
|
3639
|
+
* The one line the release redraws in place, an ora spinner. Anything else printed goes above it,
|
|
3640
|
+
* and a prompt or a child process holds it so the terminal is theirs meanwhile.
|
|
2786
3641
|
*/
|
|
2787
3642
|
var LiveLine = class {
|
|
2788
|
-
|
|
2789
|
-
timer = null;
|
|
2790
|
-
tick = 0;
|
|
3643
|
+
spinner = null;
|
|
2791
3644
|
held = 0;
|
|
2792
3645
|
get busy() {
|
|
2793
|
-
return this.
|
|
2794
|
-
}
|
|
2795
|
-
show(
|
|
2796
|
-
this.
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
3646
|
+
return this.spinner !== null;
|
|
3647
|
+
}
|
|
3648
|
+
show({ frames, text, suffix }, animate) {
|
|
3649
|
+
this.spinner = ora({
|
|
3650
|
+
text,
|
|
3651
|
+
suffixText: suffix,
|
|
3652
|
+
stream: process.stdout,
|
|
3653
|
+
discardStdin: false,
|
|
3654
|
+
isEnabled: animate,
|
|
3655
|
+
...frames && frames.length > 0 ? { spinner: {
|
|
3656
|
+
interval: TICK_MS,
|
|
3657
|
+
frames: [...frames]
|
|
3658
|
+
} } : { spinner: "dots" }
|
|
3659
|
+
});
|
|
3660
|
+
if (this.held === 0) this.spinner.start();
|
|
3661
|
+
}
|
|
3662
|
+
/** Ends the live line with a symbol kept on screen: ✓, ✗ or !. */
|
|
3663
|
+
finish(symbol, text) {
|
|
3664
|
+
const spinner = this.spinner;
|
|
3665
|
+
this.spinner = null;
|
|
3666
|
+
if (!spinner) return;
|
|
3667
|
+
if (this.held > 0) {
|
|
3668
|
+
process.stdout.write(`${symbol} ${text ?? spinner.text}\n`);
|
|
3669
|
+
return;
|
|
3670
|
+
}
|
|
3671
|
+
spinner.stopAndPersist({
|
|
3672
|
+
symbol,
|
|
3673
|
+
...text === void 0 ? {} : { text }
|
|
3674
|
+
});
|
|
2803
3675
|
}
|
|
2804
3676
|
clear() {
|
|
2805
|
-
|
|
2806
|
-
this.
|
|
2807
|
-
if (this.render && this.held === 0) process.stdout.write(CLEAR);
|
|
2808
|
-
this.render = null;
|
|
3677
|
+
this.spinner?.stop();
|
|
3678
|
+
this.spinner = null;
|
|
2809
3679
|
}
|
|
2810
3680
|
/** Prints a line above the live one. */
|
|
2811
3681
|
above(text) {
|
|
2812
|
-
|
|
3682
|
+
const live = this.spinner && this.held === 0 ? this.spinner : null;
|
|
3683
|
+
live?.clear();
|
|
2813
3684
|
process.stdout.write(`${text}\n`);
|
|
2814
|
-
|
|
3685
|
+
live?.render();
|
|
2815
3686
|
}
|
|
2816
3687
|
/** Gives the terminal to `work`, a prompt or a child process, then draws the live line again. */
|
|
2817
3688
|
async hold(work) {
|
|
2818
|
-
if (this.
|
|
3689
|
+
if (this.spinner && this.held === 0) this.spinner.stop();
|
|
2819
3690
|
this.held += 1;
|
|
2820
3691
|
try {
|
|
2821
3692
|
return await work();
|
|
2822
3693
|
} finally {
|
|
2823
3694
|
this.held -= 1;
|
|
2824
|
-
this.
|
|
3695
|
+
if (this.spinner && this.held === 0) this.spinner.start();
|
|
2825
3696
|
}
|
|
2826
3697
|
}
|
|
2827
|
-
draw() {
|
|
2828
|
-
if (this.render && this.held === 0) process.stdout.write(`${CLEAR}${this.render(this.tick)}`);
|
|
2829
|
-
}
|
|
2830
3698
|
};
|
|
2831
3699
|
const liveLine = new LiveLine();
|
|
2832
3700
|
//#endregion
|
|
@@ -2916,6 +3784,6 @@ const readStatus = async (context, environment) => {
|
|
|
2916
3784
|
};
|
|
2917
3785
|
};
|
|
2918
3786
|
//#endregion
|
|
2919
|
-
export {
|
|
3787
|
+
export { refreshEditorSchema as C, nodeFiles as D, keysAt as E, CONFIG_FILE as S, ENVIRONMENTS as T, loadRelease as _, releaseToPreview as a, initRelease as b, promote as c, pickScope as d, openReleasePr as f, findConfig as g, docsFor as h, setup as i, shipTo as l, newAdapter as m, systemShell as n, missingTags as o, prepareRelease as p, liveLine as r, tagRelease as s, readStatus as t, planShips as u, addUnit as v, optionsFor as w, doctor as x, removeUnit as y };
|
|
2920
3788
|
|
|
2921
|
-
//# sourceMappingURL=readStatus-
|
|
3789
|
+
//# sourceMappingURL=readStatus-YTZXH_Hh.js.map
|