@workerstack/clients 1.0.0-rc.24 → 1.0.0-rc.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -0
- package/assets/installers/examples/github.config.ts +21 -0
- package/assets/installers/examples/goreleaser.config.ts +21 -0
- package/assets/installers/examples/raw.config.ts +17 -0
- package/assets/installers/templates/install.ps1 +426 -0
- package/assets/installers/templates/install.sh +412 -0
- package/bin/installgen.js +19 -0
- package/dist/cli.js +4 -0
- package/dist/emit/cli/install.d.ts +8 -5
- package/dist/emit/cli/install.js +14 -7
- package/dist/emit/cli/release.js +8 -7
- package/dist/gen/args.js +4 -0
- package/dist/installers/cli.d.ts +21 -0
- package/dist/installers/cli.js +170 -0
- package/dist/installers/commands/build.d.ts +15 -0
- package/dist/installers/commands/build.js +34 -0
- package/dist/installers/commands/check.d.ts +10 -0
- package/dist/installers/commands/check.js +161 -0
- package/dist/installers/commands/init.d.ts +9 -0
- package/dist/installers/commands/init.js +32 -0
- package/dist/installers/config/define-config.d.ts +100 -0
- package/dist/installers/config/define-config.js +10 -0
- package/dist/installers/config/hooks/bun.d.ts +21 -0
- package/dist/installers/config/hooks/bun.js +21 -0
- package/dist/installers/config/hooks/node.d.ts +9 -0
- package/dist/installers/config/hooks/node.js +16 -0
- package/dist/installers/config/load.d.ts +35 -0
- package/dist/installers/config/load.js +97 -0
- package/dist/installers/config/resolve.d.ts +4 -0
- package/dist/installers/config/resolve.js +281 -0
- package/dist/installers/config/types.d.ts +45 -0
- package/dist/installers/config/types.js +1 -0
- package/dist/installers/errors.d.ts +5 -0
- package/dist/installers/errors.js +5 -0
- package/dist/installers/index.d.ts +11 -0
- package/dist/installers/index.js +11 -0
- package/dist/installers/render/quote.d.ts +7 -0
- package/dist/installers/render/quote.js +34 -0
- package/dist/installers/render/render.d.ts +24 -0
- package/dist/installers/render/render.js +133 -0
- package/dist/installers/ui.d.ts +15 -0
- package/dist/installers/ui.js +14 -0
- package/dist/release/bootstrap.d.ts +61 -0
- package/dist/release/bootstrap.js +191 -0
- package/dist/release/bump-args.d.ts +17 -0
- package/dist/release/bump-args.js +35 -0
- package/dist/release/bump-command.d.ts +18 -0
- package/dist/release/bump-command.js +186 -0
- package/dist/release/bump.d.ts +33 -0
- package/dist/release/bump.js +72 -0
- package/dist/release/cli.d.ts +23 -0
- package/dist/release/cli.js +85 -0
- package/dist/release/codegen.d.ts +6 -0
- package/dist/release/codegen.js +25 -0
- package/dist/release/constants.d.ts +39 -0
- package/dist/release/constants.js +35 -0
- package/dist/release/context.d.ts +33 -0
- package/dist/release/context.js +31 -0
- package/dist/release/digest.d.ts +11 -0
- package/dist/release/digest.js +59 -0
- package/dist/release/git.d.ts +10 -0
- package/dist/release/git.js +64 -0
- package/dist/release/index.d.ts +7 -0
- package/dist/release/index.js +6 -0
- package/dist/release/load.d.ts +30 -0
- package/dist/release/load.js +78 -0
- package/dist/release/manifest.d.ts +15 -0
- package/dist/release/manifest.js +164 -0
- package/dist/release/oasdiff.d.ts +20 -0
- package/dist/release/oasdiff.js +36 -0
- package/dist/release/registries.d.ts +48 -0
- package/dist/release/registries.js +246 -0
- package/dist/release/release-state.d.ts +15 -0
- package/dist/release/release-state.js +21 -0
- package/dist/release/release-workflow.d.ts +5 -0
- package/dist/release/release-workflow.js +72 -0
- package/dist/release/repo-settings.d.ts +22 -0
- package/dist/release/repo-settings.js +53 -0
- package/dist/release/spec-gate.d.ts +28 -0
- package/dist/release/spec-gate.js +107 -0
- package/dist/release/sync-command.d.ts +31 -0
- package/dist/release/sync-command.js +122 -0
- package/dist/release/sync-tree.d.ts +30 -0
- package/dist/release/sync-tree.js +123 -0
- package/dist/release/sync.d.ts +46 -0
- package/dist/release/sync.js +172 -0
- package/dist/release/types.d.ts +149 -0
- package/dist/release/types.js +1 -0
- package/dist/release/version-files.d.ts +16 -0
- package/dist/release/version-files.js +74 -0
- package/dist/version.d.ts +5 -0
- package/dist/version.js +8 -0
- package/package.json +19 -9
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/** `release sync`: mirror each package of a release into its public repo, or only validate the release config. */
|
|
2
|
+
import { SHORT_SHA_LENGTH } from "./constants.js";
|
|
3
|
+
import { ReleaseUsageError, requireConfig } from "./context.js";
|
|
4
|
+
import { repoSettingsSyncer } from "./repo-settings.js";
|
|
5
|
+
import { memoizedSpecGate } from "./spec-gate.js";
|
|
6
|
+
import { syncAll } from "./sync.js";
|
|
7
|
+
const MIN_NAME_WIDTH = 4;
|
|
8
|
+
/** What `release sync --help` prints. */
|
|
9
|
+
export const HELP = `Usage: honey-clients release sync --config <path> [options]
|
|
10
|
+
|
|
11
|
+
Options:
|
|
12
|
+
--config <path> The release config (required)
|
|
13
|
+
--only <names> Comma-separated package filter. Accepts short "name" (if unique) or "project/name"
|
|
14
|
+
--dry-run Log push commands without executing them
|
|
15
|
+
--validate-only Validate the release config and exit 0/1
|
|
16
|
+
--help Show this message
|
|
17
|
+
|
|
18
|
+
Env:
|
|
19
|
+
GH_TOKEN GitHub token (required unless --validate-only or --dry-run)
|
|
20
|
+
`;
|
|
21
|
+
/* Unknown arguments are ignored. */
|
|
22
|
+
const SWITCHES = {
|
|
23
|
+
"--dry-run": "dryRun",
|
|
24
|
+
"--help": "help",
|
|
25
|
+
"--validate-only": "validateOnly",
|
|
26
|
+
"-h": "help",
|
|
27
|
+
};
|
|
28
|
+
const VALUE_FLAGS = { "--config": "config", "--only": "only" };
|
|
29
|
+
const VALUE_REQUIRED = {
|
|
30
|
+
config: "--config requires a value (the release config's path)",
|
|
31
|
+
only: "--only requires a value (comma-separated names or project/name)",
|
|
32
|
+
};
|
|
33
|
+
const isSwitch = (arg) => Object.hasOwn(SWITCHES, arg);
|
|
34
|
+
const isValueFlag = (arg) => Object.hasOwn(VALUE_FLAGS, arg);
|
|
35
|
+
/** `release sync`'s flags; a value flag with no value is an error, any unknown argument is ignored. */
|
|
36
|
+
export function parseArgs(argv) {
|
|
37
|
+
const options = {
|
|
38
|
+
config: undefined,
|
|
39
|
+
dryRun: false,
|
|
40
|
+
help: false,
|
|
41
|
+
only: undefined,
|
|
42
|
+
validateOnly: false,
|
|
43
|
+
};
|
|
44
|
+
for (let i = 0; i < argv.length; i++) {
|
|
45
|
+
const arg = argv[i];
|
|
46
|
+
if (isSwitch(arg)) {
|
|
47
|
+
options[SWITCHES[arg]] = true;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (!isValueFlag(arg))
|
|
51
|
+
continue;
|
|
52
|
+
const key = VALUE_FLAGS[arg];
|
|
53
|
+
const next = argv[i + 1];
|
|
54
|
+
if (!next || next.startsWith("--"))
|
|
55
|
+
return { error: VALUE_REQUIRED[key], ok: false };
|
|
56
|
+
if (key === "only") {
|
|
57
|
+
options.only = next
|
|
58
|
+
.split(",")
|
|
59
|
+
.map((name) => name.trim())
|
|
60
|
+
.filter(Boolean);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
options.config = next;
|
|
64
|
+
}
|
|
65
|
+
i++;
|
|
66
|
+
}
|
|
67
|
+
return { ok: true, options };
|
|
68
|
+
}
|
|
69
|
+
/** The run's report: a header, a rule, and one line per package with its status and detail. */
|
|
70
|
+
export function formatResults(items) {
|
|
71
|
+
const nameWidth = Math.max(MIN_NAME_WIDTH, ...items.map((result) => result.name.length));
|
|
72
|
+
const statusWidth = 7;
|
|
73
|
+
const header = `${"NAME".padEnd(nameWidth)} ${"STATUS".padEnd(statusWidth)} DETAIL`;
|
|
74
|
+
return [
|
|
75
|
+
header,
|
|
76
|
+
"-".repeat(header.length),
|
|
77
|
+
...items.map((result) => {
|
|
78
|
+
const detail = [
|
|
79
|
+
result.reason ?? (result.mirrorSha ? `mirror=${result.mirrorSha.slice(0, SHORT_SHA_LENGTH)}` : ""),
|
|
80
|
+
result.tag === undefined ? "" : `tag=${result.tag}`,
|
|
81
|
+
result.settings ?? "",
|
|
82
|
+
]
|
|
83
|
+
.filter((part) => part !== "")
|
|
84
|
+
.join(" ");
|
|
85
|
+
return `${result.name.padEnd(nameWidth)} ${result.status.padEnd(statusWidth)} ${detail}`;
|
|
86
|
+
}),
|
|
87
|
+
];
|
|
88
|
+
}
|
|
89
|
+
/** Runs `release sync <argv>`: the exit code it ends with, 1 when any package failed. */
|
|
90
|
+
export async function sync(argv, ctx) {
|
|
91
|
+
const parsed = parseArgs(argv);
|
|
92
|
+
if (!parsed.ok)
|
|
93
|
+
throw new ReleaseUsageError(parsed.error);
|
|
94
|
+
const { options } = parsed;
|
|
95
|
+
if (options.help) {
|
|
96
|
+
ctx.out(`${HELP}\n`);
|
|
97
|
+
return 0;
|
|
98
|
+
}
|
|
99
|
+
const config = requireConfig(options.config);
|
|
100
|
+
if (options.validateOnly) {
|
|
101
|
+
const { packages } = await ctx.load(config);
|
|
102
|
+
ctx.out(`Manifests valid: ${packages.length} package(s)\n`);
|
|
103
|
+
return 0;
|
|
104
|
+
}
|
|
105
|
+
const token = ctx.env.GH_TOKEN ?? "";
|
|
106
|
+
if (!token && !options.dryRun) {
|
|
107
|
+
ctx.err("GH_TOKEN env is required (or use --dry-run)\n");
|
|
108
|
+
return 1;
|
|
109
|
+
}
|
|
110
|
+
const release = await ctx.load(config);
|
|
111
|
+
const results = await syncAll(release.packages, {
|
|
112
|
+
dryRun: options.dryRun,
|
|
113
|
+
only: options.only,
|
|
114
|
+
repoRoot: release.root,
|
|
115
|
+
repoSettings: repoSettingsSyncer({ dryRun: options.dryRun, fetch: ctx.fetch, token }),
|
|
116
|
+
specGate: memoizedSpecGate(ctx.fetch),
|
|
117
|
+
token,
|
|
118
|
+
});
|
|
119
|
+
for (const line of formatResults(results))
|
|
120
|
+
ctx.out(`${line}\n`);
|
|
121
|
+
return results.some((result) => result.status === "failed") ? 1 : 0;
|
|
122
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { PublicPackage } from "./types.ts";
|
|
2
|
+
export declare function prepareWorktree(worktree: string, httpsUrl: string, { branch, committer }: PublicPackage, remoteTip: string | undefined): Promise<void>;
|
|
3
|
+
export declare function replaceTreeWithSource(args: {
|
|
4
|
+
excludes: string[];
|
|
5
|
+
repoRoot: string;
|
|
6
|
+
sourcePath: string;
|
|
7
|
+
worktree: string;
|
|
8
|
+
}): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* The release tag the public commit equal to the source still needs: `v<version>` from the source's
|
|
11
|
+
* `.release-state.json`, when the synced tree carries the release workflow and the public repo has no
|
|
12
|
+
* such tag. An existing tag is never moved, wherever it points.
|
|
13
|
+
*/
|
|
14
|
+
export declare function pendingTag(entry: PublicPackage, repoRoot: string, worktree: string, httpsUrl: string): Promise<string | undefined>;
|
|
15
|
+
export declare function pushTag(worktree: string, httpsUrl: string, tag: string): Promise<void>;
|
|
16
|
+
export declare function isTreeUnchanged(worktree: string): Promise<boolean>;
|
|
17
|
+
export declare function readSidecar(repoRoot: string, sourcePath: string): string | undefined;
|
|
18
|
+
export declare function buildCommitMessage(args: {
|
|
19
|
+
initialMessage: string | undefined;
|
|
20
|
+
isInitial: boolean;
|
|
21
|
+
sidecarMessage: string | undefined;
|
|
22
|
+
templateMessage: string;
|
|
23
|
+
}): string;
|
|
24
|
+
export declare function commitAndPush(args: {
|
|
25
|
+
branch: string;
|
|
26
|
+
expectedRemote: string;
|
|
27
|
+
httpsUrl: string;
|
|
28
|
+
message: string;
|
|
29
|
+
worktree: string;
|
|
30
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/** The temporary worktree sync builds each public commit in, and the message that commit carries. */
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { existsSync, readFileSync, unlinkSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { MANIFEST } from "../gen/write.js";
|
|
6
|
+
import { RELEASE_STATE } from "./constants.js";
|
|
7
|
+
import { gitExitCode, gitOutput, gitRun } from "./git.js";
|
|
8
|
+
import { RELEASE_WORKFLOW } from "./release-workflow.js";
|
|
9
|
+
const DATE_PART_DIGITS = 2;
|
|
10
|
+
const SIDECAR_FILE = ".publicsync-message";
|
|
11
|
+
export async function prepareWorktree(worktree, httpsUrl, { branch, committer }, remoteTip) {
|
|
12
|
+
await gitRun(["init", "--quiet", "--initial-branch", branch, worktree], worktree);
|
|
13
|
+
await gitRun(["-C", worktree, "config", "user.name", committer.name], worktree);
|
|
14
|
+
await gitRun(["-C", worktree, "config", "user.email", committer.email], worktree);
|
|
15
|
+
await gitRun(["-C", worktree, "remote", "add", "origin", httpsUrl], worktree);
|
|
16
|
+
if (remoteTip) {
|
|
17
|
+
await gitRun(["-C", worktree, "fetch", "--depth=1", "origin", branch], worktree);
|
|
18
|
+
await gitRun(["-C", worktree, "reset", "--hard", "FETCH_HEAD"], worktree);
|
|
19
|
+
const tracked = await gitOutput(["-C", worktree, "ls-files"], worktree);
|
|
20
|
+
if (tracked) {
|
|
21
|
+
await gitRun(["-C", worktree, "rm", "-rf", "--quiet", "."], worktree);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export async function replaceTreeWithSource(args) {
|
|
26
|
+
const sourceFull = join(args.repoRoot, args.sourcePath);
|
|
27
|
+
await runRsync(`${sourceFull}/`, `${args.worktree}/`, args.excludes);
|
|
28
|
+
/* the sidecar message file is the source's note to sync; it never lands in the public repo */
|
|
29
|
+
const sidecarPath = join(args.worktree, SIDECAR_FILE);
|
|
30
|
+
if (existsSync(sidecarPath)) {
|
|
31
|
+
unlinkSync(sidecarPath);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async function runRsync(src, dst, excludes) {
|
|
35
|
+
/* honey's manifest is the source repo's record of what it generated, not part of the package */
|
|
36
|
+
const args = ["-a", "--delete", "--exclude=.git", `--exclude=${MANIFEST}`];
|
|
37
|
+
for (const glob of excludes) {
|
|
38
|
+
args.push(`--exclude=${glob}`);
|
|
39
|
+
}
|
|
40
|
+
args.push(src, dst);
|
|
41
|
+
await new Promise((resolve, reject) => {
|
|
42
|
+
const child = spawn("rsync", args, { stdio: ["ignore", "ignore", "pipe"] });
|
|
43
|
+
let stderr = "";
|
|
44
|
+
child.stderr.on("data", (chunk) => {
|
|
45
|
+
stderr += chunk.toString("utf8");
|
|
46
|
+
});
|
|
47
|
+
child.on("error", reject);
|
|
48
|
+
child.on("close", (code) => {
|
|
49
|
+
if (code === 0)
|
|
50
|
+
resolve();
|
|
51
|
+
else
|
|
52
|
+
reject(new Error(`rsync exit ${code}: ${stderr.trim()}`));
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The release tag the public commit equal to the source still needs: `v<version>` from the source's
|
|
58
|
+
* `.release-state.json`, when the synced tree carries the release workflow and the public repo has no
|
|
59
|
+
* such tag. An existing tag is never moved, wherever it points.
|
|
60
|
+
*/
|
|
61
|
+
export async function pendingTag(entry, repoRoot, worktree, httpsUrl) {
|
|
62
|
+
if (!existsSync(join(worktree, RELEASE_WORKFLOW)))
|
|
63
|
+
return undefined;
|
|
64
|
+
const statePath = join(repoRoot, entry.path, RELEASE_STATE);
|
|
65
|
+
if (!existsSync(statePath))
|
|
66
|
+
return undefined;
|
|
67
|
+
const { version } = JSON.parse(readFileSync(statePath, "utf8"));
|
|
68
|
+
if (typeof version !== "string" || version === "")
|
|
69
|
+
throw new Error(`${join(entry.path, RELEASE_STATE)} records no version`);
|
|
70
|
+
const tag = `v${version}`;
|
|
71
|
+
const existing = await gitOutput(["ls-remote", "--tags", httpsUrl, `refs/tags/${tag}`], worktree);
|
|
72
|
+
return existing === "" ? tag : undefined;
|
|
73
|
+
}
|
|
74
|
+
/* No force: a tag someone pushed in between makes this fail rather than move theirs. */
|
|
75
|
+
export async function pushTag(worktree, httpsUrl, tag) {
|
|
76
|
+
await gitRun(["-C", worktree, "tag", tag, "HEAD"], worktree);
|
|
77
|
+
await gitRun(["-C", worktree, "push", httpsUrl, `refs/tags/${tag}`], worktree);
|
|
78
|
+
}
|
|
79
|
+
export async function isTreeUnchanged(worktree) {
|
|
80
|
+
/* -Af forces past the package's own .gitignore: a generated SDK may ship one that keeps its generated source out
|
|
81
|
+
of the source repo's git, and that filter must not apply here, where those files are what is published */
|
|
82
|
+
await gitRun(["-C", worktree, "add", "-Af"], worktree);
|
|
83
|
+
const diffCode = await gitExitCode(["-C", worktree, "diff", "--cached", "--quiet"], worktree);
|
|
84
|
+
return diffCode === 0;
|
|
85
|
+
}
|
|
86
|
+
export function readSidecar(repoRoot, sourcePath) {
|
|
87
|
+
const sidecar = join(repoRoot, sourcePath, SIDECAR_FILE);
|
|
88
|
+
if (!existsSync(sidecar))
|
|
89
|
+
return undefined;
|
|
90
|
+
const raw = readFileSync(sidecar, "utf8").trim();
|
|
91
|
+
return raw.length > 0 ? raw : undefined;
|
|
92
|
+
}
|
|
93
|
+
export function buildCommitMessage(args) {
|
|
94
|
+
const stamp = formatUtcStamp(new Date());
|
|
95
|
+
if (args.sidecarMessage) {
|
|
96
|
+
return `${args.sidecarMessage} [${stamp}]`;
|
|
97
|
+
}
|
|
98
|
+
if (args.isInitial) {
|
|
99
|
+
const initial = args.initialMessage ?? "chore: initial release";
|
|
100
|
+
return `${initial} [${stamp}]`;
|
|
101
|
+
}
|
|
102
|
+
return `${args.templateMessage} [${stamp}]`;
|
|
103
|
+
}
|
|
104
|
+
function formatUtcStamp(d) {
|
|
105
|
+
const yyyy = d.getUTCFullYear();
|
|
106
|
+
const mm = String(d.getUTCMonth() + 1).padStart(DATE_PART_DIGITS, "0");
|
|
107
|
+
const dd = String(d.getUTCDate()).padStart(DATE_PART_DIGITS, "0");
|
|
108
|
+
const hh = String(d.getUTCHours()).padStart(DATE_PART_DIGITS, "0");
|
|
109
|
+
const mi = String(d.getUTCMinutes()).padStart(DATE_PART_DIGITS, "0");
|
|
110
|
+
return `${yyyy}-${mm}-${dd} ${hh}:${mi} UTC`;
|
|
111
|
+
}
|
|
112
|
+
export async function commitAndPush(args) {
|
|
113
|
+
await gitRun(["-C", args.worktree, "commit", "--quiet", "--message", args.message], args.worktree);
|
|
114
|
+
await gitRun([
|
|
115
|
+
"-C",
|
|
116
|
+
args.worktree,
|
|
117
|
+
"push",
|
|
118
|
+
`--force-with-lease=refs/heads/${args.branch}:${args.expectedRemote}`,
|
|
119
|
+
"--force-if-includes",
|
|
120
|
+
args.httpsUrl,
|
|
121
|
+
`HEAD:refs/heads/${args.branch}`,
|
|
122
|
+
], args.worktree);
|
|
123
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { PublicPackage, SpecSource } from "./types.ts";
|
|
2
|
+
import type { RepoSettingsSync } from "./repo-settings.ts";
|
|
3
|
+
import { type SpecGate } from "./spec-gate.ts";
|
|
4
|
+
/** How one sync run behaves: the repo it reads, what it may push, and the steps it is handed. */
|
|
5
|
+
export interface SyncOptions {
|
|
6
|
+
/** When true, use entry.bootstrapExclude globs as rsync excludes. Caller opts-in per run. */
|
|
7
|
+
applyBootstrapExclude?: boolean;
|
|
8
|
+
/** Report what would be pushed and push nothing. */
|
|
9
|
+
dryRun?: boolean;
|
|
10
|
+
/** The message of the first commit to an empty public repo; `chore: initial release` by default. */
|
|
11
|
+
initialMessage?: string;
|
|
12
|
+
/** Package names (`name` or `project/name`) to sync; every package when absent or empty. */
|
|
13
|
+
only?: string[];
|
|
14
|
+
/** Push over a tip the sync bot did not commit. Bootstrap only: it has already judged the repo. */
|
|
15
|
+
overwriteForeignTip?: boolean;
|
|
16
|
+
/** The git toplevel every package path is relative to. */
|
|
17
|
+
repoRoot: string;
|
|
18
|
+
/** Keeps the public repo's description, website and topics equal to the package's. */
|
|
19
|
+
repoSettings: RepoSettingsSync;
|
|
20
|
+
/** Compares prod's spec with the committed one; asked only when a package's generated output changed. */
|
|
21
|
+
specGate: (spec: SpecSource) => Promise<SpecGate>;
|
|
22
|
+
/** The GitHub token every push and API call authenticates with. */
|
|
23
|
+
token: string;
|
|
24
|
+
}
|
|
25
|
+
/** What syncing one package did: pushed, skipped as unchanged, or failed, and why. */
|
|
26
|
+
export interface PackageResult {
|
|
27
|
+
mirrorSha?: string;
|
|
28
|
+
name: string;
|
|
29
|
+
reason?: string;
|
|
30
|
+
/** What the repo settings step found or changed. */
|
|
31
|
+
settings?: string;
|
|
32
|
+
sourceSha?: string;
|
|
33
|
+
status: "failed" | "skipped" | "synced";
|
|
34
|
+
/** The release tag pushed (or, on a dry run, that would be) at the public commit equal to the source. */
|
|
35
|
+
tag?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Mirrors one package into its public repo: a snapshot commit when its tree changed (generated output only when prod
|
|
39
|
+
* serves the committed spec), the release tag its state records, and its repo settings. Refuses a public tip another
|
|
40
|
+
* committer pushed unless `overwriteForeignTip`.
|
|
41
|
+
*/
|
|
42
|
+
export declare function syncPackage(entry: PublicPackage, options: SyncOptions): Promise<PackageResult>;
|
|
43
|
+
/** Syncs each of `packages` that `options.only` keeps, one after another; a package that throws fails alone. */
|
|
44
|
+
export declare function syncAll(packages: readonly PublicPackage[], options: SyncOptions): Promise<PackageResult[]>;
|
|
45
|
+
/** The packages `--only` keeps, by short "name" or full "project/name"; every package when it names none. */
|
|
46
|
+
export declare function filterPackages(packages: readonly PublicPackage[], options: Pick<SyncOptions, "only">): PublicPackage[];
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mirrors packages into their public repos: each package's source tree becomes one snapshot commit by the release's
|
|
3
|
+
* committer, with the release tag its state records and the repo settings its config names.
|
|
4
|
+
*/
|
|
5
|
+
import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { tmpdir } from "node:os";
|
|
7
|
+
import { dirname, join } from "node:path";
|
|
8
|
+
import { gitOutput, getRemoteTip, sshToHttps } from "./git.js";
|
|
9
|
+
import { packageKey } from "./manifest.js";
|
|
10
|
+
import { RELEASE_WORKFLOW, releaseWorkflow } from "./release-workflow.js";
|
|
11
|
+
import { describeDrift, generatedPaths } from "./spec-gate.js";
|
|
12
|
+
import { buildCommitMessage, commitAndPush, isTreeUnchanged, pendingTag, prepareWorktree, pushTag, readSidecar, replaceTreeWithSource, } from "./sync-tree.js";
|
|
13
|
+
function describeSettings(result, dryRun) {
|
|
14
|
+
if (result.status !== "checked")
|
|
15
|
+
return `settings ${result.status}`;
|
|
16
|
+
if (result.changed.length === 0)
|
|
17
|
+
return "settings in step";
|
|
18
|
+
return `settings ${dryRun ? "would change" : "changed"}: ${result.changed.join(", ")}`;
|
|
19
|
+
}
|
|
20
|
+
/* Applies the repo settings after the tree step, whatever it did: a failure there fails the package but keeps
|
|
21
|
+
* what already landed (the pushed commit and tag) in the result. */
|
|
22
|
+
async function withSettings(entry, options, result) {
|
|
23
|
+
try {
|
|
24
|
+
return {
|
|
25
|
+
...result,
|
|
26
|
+
settings: describeSettings(await options.repoSettings(entry), options.dryRun === true),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
31
|
+
return {
|
|
32
|
+
...result,
|
|
33
|
+
reason: result.reason === undefined ? reason : `${result.reason}; ${reason}`,
|
|
34
|
+
status: "failed",
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const tagged = (tag) => (tag === undefined ? {} : { tag });
|
|
39
|
+
/* Only the bot commits to a public repo. Any other committer is a hand edit there that a snapshot would silently
|
|
40
|
+
erase: its reason, or undefined when the tip is the bot's, there is none, or bootstrap judged it already. */
|
|
41
|
+
async function foreignTip({ entry, options, remoteTip, worktree }) {
|
|
42
|
+
if (!remoteTip || options.overwriteForeignTip)
|
|
43
|
+
return undefined;
|
|
44
|
+
const committer = await gitOutput(["-C", worktree, "log", "-1", "--format=%ce", "FETCH_HEAD"], worktree);
|
|
45
|
+
if (committer === entry.committer.email)
|
|
46
|
+
return undefined;
|
|
47
|
+
return `external push detected on mirror; reconcile manually (tip=${remoteTip}, committer=${committer})`;
|
|
48
|
+
}
|
|
49
|
+
/* The source's tree over the public tip, with the release workflow its registries render (a package that ships its
|
|
50
|
+
own lists none): why it cannot be, or undefined. */
|
|
51
|
+
async function stageTree({ entry, options, worktree }) {
|
|
52
|
+
await replaceTreeWithSource({
|
|
53
|
+
excludes: options.applyBootstrapExclude && entry.bootstrapExclude ? [...entry.bootstrapExclude] : [],
|
|
54
|
+
repoRoot: options.repoRoot,
|
|
55
|
+
sourcePath: entry.path,
|
|
56
|
+
worktree,
|
|
57
|
+
});
|
|
58
|
+
if (entry.registries.length === 0)
|
|
59
|
+
return undefined;
|
|
60
|
+
const workflow = join(worktree, RELEASE_WORKFLOW);
|
|
61
|
+
if (existsSync(workflow)) {
|
|
62
|
+
return `${join(entry.path, RELEASE_WORKFLOW)} exists and the package lists registries: drop one, the other writes it`;
|
|
63
|
+
}
|
|
64
|
+
mkdirSync(dirname(workflow), { recursive: true });
|
|
65
|
+
writeFileSync(workflow, releaseWorkflow(entry.registries));
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
/* Generated output prod does not serve must not ship; hand files go out regardless: the refusal, or undefined. */
|
|
69
|
+
async function drift({ entry, key, options, worktree }) {
|
|
70
|
+
const generated = generatedPaths(join(options.repoRoot, entry.path));
|
|
71
|
+
const changed = (await gitOutput(["-C", worktree, "diff", "--cached", "--name-only"], worktree)).split("\n");
|
|
72
|
+
if (!changed.some((path) => generated.has(path)))
|
|
73
|
+
return undefined;
|
|
74
|
+
const gate = await options.specGate(entry.spec);
|
|
75
|
+
return gate.status === "drift" ? describeDrift(key, gate) : undefined;
|
|
76
|
+
}
|
|
77
|
+
/* the tip is the bot's and equals the source, so a tag a stopped run never pushed goes on it */
|
|
78
|
+
async function skipUnchanged(run) {
|
|
79
|
+
const { entry, httpsUrl, key, options, worktree } = run;
|
|
80
|
+
const tag = await pendingTag(entry, options.repoRoot, worktree, httpsUrl);
|
|
81
|
+
if (tag !== undefined && !options.dryRun)
|
|
82
|
+
await pushTag(worktree, httpsUrl, tag);
|
|
83
|
+
return withSettings(entry, options, {
|
|
84
|
+
name: key,
|
|
85
|
+
reason: "content identical to mirror tip",
|
|
86
|
+
status: "skipped",
|
|
87
|
+
...tagged(tag),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/* the snapshot committed and pushed, then its tag; on a dry run, what would be */
|
|
91
|
+
async function push(run) {
|
|
92
|
+
const { entry, headSha, httpsUrl, key, message, options, remoteTip, worktree } = run;
|
|
93
|
+
const tag = await pendingTag(entry, options.repoRoot, worktree, httpsUrl);
|
|
94
|
+
if (options.dryRun) {
|
|
95
|
+
return withSettings(entry, options, {
|
|
96
|
+
name: key,
|
|
97
|
+
reason: `dry-run: would push to ${entry.branch} with message "${message}"${tag === undefined ? "" : ` and tag ${tag}`}`,
|
|
98
|
+
sourceSha: headSha,
|
|
99
|
+
status: "synced",
|
|
100
|
+
...tagged(tag),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
await commitAndPush({ branch: entry.branch, expectedRemote: remoteTip ?? "", httpsUrl, message, worktree });
|
|
104
|
+
const mirrorSha = await gitOutput(["-C", worktree, "rev-parse", "HEAD"], options.repoRoot);
|
|
105
|
+
if (tag !== undefined)
|
|
106
|
+
await pushTag(worktree, httpsUrl, tag);
|
|
107
|
+
return withSettings(entry, options, { mirrorSha, name: key, sourceSha: headSha, status: "synced", ...tagged(tag) });
|
|
108
|
+
}
|
|
109
|
+
/* each step in turn; the first that refuses fails the package */
|
|
110
|
+
async function syncIn(run) {
|
|
111
|
+
await prepareWorktree(run.worktree, run.httpsUrl, run.entry, run.remoteTip);
|
|
112
|
+
const foreign = await foreignTip(run);
|
|
113
|
+
if (foreign !== undefined)
|
|
114
|
+
return { name: run.key, reason: foreign, status: "failed" };
|
|
115
|
+
const conflict = await stageTree(run);
|
|
116
|
+
if (conflict !== undefined)
|
|
117
|
+
return { name: run.key, reason: conflict, status: "failed" };
|
|
118
|
+
if (await isTreeUnchanged(run.worktree))
|
|
119
|
+
return skipUnchanged(run);
|
|
120
|
+
const refused = await drift(run);
|
|
121
|
+
if (refused !== undefined)
|
|
122
|
+
return { name: run.key, reason: refused, status: "failed" };
|
|
123
|
+
return push(run);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Mirrors one package into its public repo: a snapshot commit when its tree changed (generated output only when prod
|
|
127
|
+
* serves the committed spec), the release tag its state records, and its repo settings. Refuses a public tip another
|
|
128
|
+
* committer pushed unless `overwriteForeignTip`.
|
|
129
|
+
*/
|
|
130
|
+
export async function syncPackage(entry, options) {
|
|
131
|
+
const key = packageKey(entry);
|
|
132
|
+
const headSha = await gitOutput(["rev-parse", "HEAD"], options.repoRoot);
|
|
133
|
+
const httpsUrl = sshToHttps(entry.mirror, options.token);
|
|
134
|
+
const remoteTip = await getRemoteTip(httpsUrl, entry.branch, options.repoRoot);
|
|
135
|
+
const message = buildCommitMessage({
|
|
136
|
+
initialMessage: options.initialMessage,
|
|
137
|
+
isInitial: !remoteTip,
|
|
138
|
+
sidecarMessage: readSidecar(options.repoRoot, entry.path),
|
|
139
|
+
templateMessage: entry.commitMessage,
|
|
140
|
+
});
|
|
141
|
+
const worktree = mkdtempSync(join(tmpdir(), `public-sync-${key.replace(/\//g, "-")}-`));
|
|
142
|
+
try {
|
|
143
|
+
return await syncIn({ entry, headSha, httpsUrl, key, message, options, remoteTip, worktree });
|
|
144
|
+
}
|
|
145
|
+
finally {
|
|
146
|
+
rmSync(worktree, { force: true, recursive: true });
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/** Syncs each of `packages` that `options.only` keeps, one after another; a package that throws fails alone. */
|
|
150
|
+
export async function syncAll(packages, options) {
|
|
151
|
+
const results = [];
|
|
152
|
+
for (const entry of filterPackages(packages, options)) {
|
|
153
|
+
try {
|
|
154
|
+
results.push(await syncPackage(entry, options));
|
|
155
|
+
}
|
|
156
|
+
catch (err) {
|
|
157
|
+
results.push({
|
|
158
|
+
name: packageKey(entry),
|
|
159
|
+
reason: err instanceof Error ? err.message : String(err),
|
|
160
|
+
status: "failed",
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return results;
|
|
165
|
+
}
|
|
166
|
+
/** The packages `--only` keeps, by short "name" or full "project/name"; every package when it names none. */
|
|
167
|
+
export function filterPackages(packages, options) {
|
|
168
|
+
if (!options.only || options.only.length === 0)
|
|
169
|
+
return [...packages];
|
|
170
|
+
const set = new Set(options.only);
|
|
171
|
+
return packages.filter((p) => set.has(p.name) || set.has(packageKey(p)));
|
|
172
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shapes a `release.config.ts` is written in and a loaded release is read in. `manifest.ts` holds the schemas
|
|
3
|
+
* that parse a config into them, each checked against these at compile time.
|
|
4
|
+
*/
|
|
5
|
+
import type { Target } from "../gen/targets.ts";
|
|
6
|
+
/** The package metadata honey-clients writes into each generated package's manifest; every field is optional. */
|
|
7
|
+
export type PackageMetadata = {
|
|
8
|
+
/** Authors, as `Name <email>`. */
|
|
9
|
+
readonly authors?: readonly string[];
|
|
10
|
+
/** The changelog's URL. */
|
|
11
|
+
readonly changelog?: string;
|
|
12
|
+
/** The copyright line. */
|
|
13
|
+
readonly copyright?: string;
|
|
14
|
+
/** A one-line description. */
|
|
15
|
+
readonly description?: string;
|
|
16
|
+
/** The documentation's URL. */
|
|
17
|
+
readonly documentation?: string;
|
|
18
|
+
/** The project's site. */
|
|
19
|
+
readonly homepage?: string;
|
|
20
|
+
/** The package icon's path, relative to the repo root. */
|
|
21
|
+
readonly icon?: string;
|
|
22
|
+
/** Registry search keywords. */
|
|
23
|
+
readonly keywords?: readonly string[];
|
|
24
|
+
/** The SPDX license expression. */
|
|
25
|
+
readonly license?: string;
|
|
26
|
+
/** The license file's path, relative to the repo root. */
|
|
27
|
+
readonly licenseFile?: string;
|
|
28
|
+
/** The README's path, relative to the repo root. */
|
|
29
|
+
readonly readme?: string;
|
|
30
|
+
/** The source repository's URL. */
|
|
31
|
+
readonly repository?: string;
|
|
32
|
+
};
|
|
33
|
+
/** How honey-clients generates a package: its target, and that target's options by name. */
|
|
34
|
+
export type HoneyRun = {
|
|
35
|
+
/** The target's options, as `--<target>-<option>` takes them; none by default. */
|
|
36
|
+
readonly options?: Readonly<Record<string, string>>;
|
|
37
|
+
/** The honey-clients target the package is generated with. */
|
|
38
|
+
readonly target: Target;
|
|
39
|
+
};
|
|
40
|
+
/** A registry a package's public repo publishes it to; names come from the package's own files. */
|
|
41
|
+
export type Registry = {
|
|
42
|
+
/** The registry, which the package's own manifest names the package on. */
|
|
43
|
+
readonly kind: "crates" | "go" | "jsr" | "maven" | "npm" | "nuget" | "pypi";
|
|
44
|
+
} | {
|
|
45
|
+
/** The files of the package attached to the tag's release, at least one. */
|
|
46
|
+
readonly assets: readonly string[];
|
|
47
|
+
/** A GitHub Release of the tag. */
|
|
48
|
+
readonly kind: "github";
|
|
49
|
+
};
|
|
50
|
+
/** One public package a config lists. */
|
|
51
|
+
export type ManifestPackageInput = {
|
|
52
|
+
/** Globs bootstrap leaves out of the first push, so the next sync adds them as their own commit. */
|
|
53
|
+
readonly bootstrapExclude?: readonly string[];
|
|
54
|
+
/** The public repo's branch sync pushes to; `main` by default. */
|
|
55
|
+
readonly branch?: string;
|
|
56
|
+
/** The message of each snapshot commit, unless the package's `.publicsync-message` names one. */
|
|
57
|
+
readonly commitMessage: string;
|
|
58
|
+
/** The package's one description: its public repo's, every registry's, and its first CHANGELOG entry. */
|
|
59
|
+
readonly description: string;
|
|
60
|
+
/** How honey-clients generates it; absent for a package honey does not generate (the spec itself). */
|
|
61
|
+
readonly honey?: HoneyRun;
|
|
62
|
+
/** This package's metadata over the product's; its keywords add to the product's. */
|
|
63
|
+
readonly metadata?: PackageMetadata;
|
|
64
|
+
/** The package's slug: its dir beside the config, and the key bump's `RELEASE_VERSIONS` uses. */
|
|
65
|
+
readonly name: string;
|
|
66
|
+
/** The registries its release workflow publishes to; none for a package that ships its own workflow. */
|
|
67
|
+
readonly registries?: readonly Registry[];
|
|
68
|
+
/** The public repo, `owner/name` on github.com. */
|
|
69
|
+
readonly repo: string;
|
|
70
|
+
/** The public repo's GitHub topics, 1 to 20 lowercase slugs. */
|
|
71
|
+
readonly topics: readonly string[];
|
|
72
|
+
};
|
|
73
|
+
/** Where a product's public spec is served, and the committed spec its generated code is built from. */
|
|
74
|
+
export type SpecSource = {
|
|
75
|
+
/** The committed spec: as a config gives it, relative to the repo root; once loaded, absolute. */
|
|
76
|
+
readonly committedPath: string;
|
|
77
|
+
/** Where prod serves the spec: https, or http on a loopback host. */
|
|
78
|
+
readonly deployedUrl: string;
|
|
79
|
+
};
|
|
80
|
+
/** A git identity: the committer of every snapshot sync pushes. */
|
|
81
|
+
export type Committer = {
|
|
82
|
+
/** The committer's email; a public repo tip with any other committer was pushed by hand. */
|
|
83
|
+
readonly email: string;
|
|
84
|
+
/** The committer's name. */
|
|
85
|
+
readonly name: string;
|
|
86
|
+
};
|
|
87
|
+
/** What a product's `release.config.ts` default-exports. */
|
|
88
|
+
export type ReleaseManifestInput = {
|
|
89
|
+
/** The command that regenerates every package of the product, run from the repo root; it honors `RELEASE_VERSIONS`. */
|
|
90
|
+
readonly codegen: readonly string[];
|
|
91
|
+
/** The identity sync commits as; `public-sync[bot]` by default, so another org's GitHub App can sync. */
|
|
92
|
+
readonly committer?: Committer;
|
|
93
|
+
/** The product's site: every public repo's website and every registry's homepage. */
|
|
94
|
+
readonly homepage: string;
|
|
95
|
+
/** The metadata every generated package of the product carries. */
|
|
96
|
+
readonly metadata?: PackageMetadata;
|
|
97
|
+
/** The product's public packages, at least one; each name and repo once. */
|
|
98
|
+
readonly packages: readonly ManifestPackageInput[];
|
|
99
|
+
/** The product's slug: the `<project>/<name>` key of each package, and what its codegen filters on. */
|
|
100
|
+
readonly project: string;
|
|
101
|
+
/** The product's spec. */
|
|
102
|
+
readonly spec: SpecSource;
|
|
103
|
+
/**
|
|
104
|
+
* The tools codegen needs, each a dep name in the repo root's `system.config.ts`; the release workflows install
|
|
105
|
+
* them in this order before codegen runs. None by default.
|
|
106
|
+
*/
|
|
107
|
+
readonly toolchains?: readonly string[];
|
|
108
|
+
};
|
|
109
|
+
/** A listed package with its defaults applied. */
|
|
110
|
+
export type ManifestPackage = ManifestPackageInput & {
|
|
111
|
+
/** The public repo's branch. */
|
|
112
|
+
readonly branch: string;
|
|
113
|
+
/** The package's metadata: the product's, then its own over it. */
|
|
114
|
+
readonly metadata?: PackageMetadata;
|
|
115
|
+
/** The registries its release workflow publishes to, possibly none. */
|
|
116
|
+
readonly registries: readonly Registry[];
|
|
117
|
+
};
|
|
118
|
+
/** A config package placed in the repo. */
|
|
119
|
+
export type PublicPackage = ManifestPackage & {
|
|
120
|
+
/** The product's codegen command (argv, run from the repo root). */
|
|
121
|
+
readonly codegen: readonly string[];
|
|
122
|
+
/** The identity sync commits this package's snapshots as. */
|
|
123
|
+
readonly committer: Committer;
|
|
124
|
+
/** The product's site. */
|
|
125
|
+
readonly homepage: string;
|
|
126
|
+
/** The public repo's SSH remote, `git@github.com:<repo>.git`. */
|
|
127
|
+
readonly mirror: string;
|
|
128
|
+
/** The package's source dir, relative to the repo root (the git toplevel). */
|
|
129
|
+
readonly path: string;
|
|
130
|
+
/** The product's slug. */
|
|
131
|
+
readonly project: string;
|
|
132
|
+
/** The product's spec; `committedPath` is absolute. */
|
|
133
|
+
readonly spec: SpecSource;
|
|
134
|
+
};
|
|
135
|
+
/** A loaded release config: the repo it lives in and the packages it places there. */
|
|
136
|
+
export type Release = {
|
|
137
|
+
/** The product's codegen command (argv, run from the repo root); it honors `RELEASE_VERSIONS`. */
|
|
138
|
+
readonly codegen: readonly string[];
|
|
139
|
+
/** The product's packages, in the order the config lists them. */
|
|
140
|
+
readonly packages: readonly PublicPackage[];
|
|
141
|
+
/** The product's slug. */
|
|
142
|
+
readonly project: string;
|
|
143
|
+
/** The git toplevel of the config's dir, which every package path and the committed spec are relative to. */
|
|
144
|
+
readonly root: string;
|
|
145
|
+
/** The product's spec; `committedPath` is absolute. */
|
|
146
|
+
readonly spec: SpecSource;
|
|
147
|
+
/** The `system.config.ts` dep names codegen needs, in install order; possibly none. */
|
|
148
|
+
readonly toolchains: readonly string[];
|
|
149
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
type VersionFile = {
|
|
2
|
+
read(text: string): string;
|
|
3
|
+
write(text: string, version: string): string;
|
|
4
|
+
};
|
|
5
|
+
/** The version files bump keeps in step with `.release-state.json`, by file name. */
|
|
6
|
+
export declare const VERSION_FILES: {
|
|
7
|
+
readonly "jsr.json": VersionFile;
|
|
8
|
+
readonly "package.json": VersionFile;
|
|
9
|
+
readonly "pyproject.toml": VersionFile;
|
|
10
|
+
};
|
|
11
|
+
export type VersionFileName = keyof typeof VERSION_FILES;
|
|
12
|
+
/** Each version file present in `dir` with the version it holds; throws naming the file whose version line is missing or doubled. */
|
|
13
|
+
export declare function readVersions(dir: string): Partial<Record<VersionFileName, string>>;
|
|
14
|
+
/** Writes `version` into every version file present in `dir`; returns the paths written. */
|
|
15
|
+
export declare function writeVersions(dir: string, version: string): string[];
|
|
16
|
+
export {};
|