@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,10 @@
|
|
|
1
|
+
/** `git args` in `cwd`: its trimmed stdout; throws with its stderr when it exits non-zero. */
|
|
2
|
+
export declare function gitOutput(args: string[], cwd: string): Promise<string>;
|
|
3
|
+
/** `git args` in `cwd`, for its effect; throws with its stderr when it exits non-zero. */
|
|
4
|
+
export declare function gitRun(args: string[], cwd: string): Promise<void>;
|
|
5
|
+
/** `git args` in `cwd`: its exit code, whatever it is. */
|
|
6
|
+
export declare function gitExitCode(args: string[], cwd: string): Promise<number>;
|
|
7
|
+
/** The commit `branch` points at on the remote `mirrorUrl`; undefined when the remote or the branch is not there. */
|
|
8
|
+
export declare function getRemoteTip(mirrorUrl: string, branch: string, cwd: string): Promise<string | undefined>;
|
|
9
|
+
/** A GitHub SSH remote as the token-authenticated https URL every push uses; any other URL is left as it is. */
|
|
10
|
+
export declare function sshToHttps(sshUrl: string, token: string): string;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
/*
|
|
3
|
+
* The variables git exports to a hook, which every child process inherits. A `cwd` does not
|
|
4
|
+
* override them: with GIT_DIR set, `git init` in a sandbox re-initialises the enclosing repository
|
|
5
|
+
* and a commit lands there. The pre-push hook runs this package's tests, so they have to be
|
|
6
|
+
* cleared or a test's sandbox writes into the repository being pushed.
|
|
7
|
+
*/
|
|
8
|
+
const INHERITED_GIT_VARS = [
|
|
9
|
+
"GIT_ALTERNATE_OBJECT_DIRECTORIES",
|
|
10
|
+
"GIT_COMMON_DIR",
|
|
11
|
+
"GIT_DIR",
|
|
12
|
+
"GIT_INDEX_FILE",
|
|
13
|
+
"GIT_NAMESPACE",
|
|
14
|
+
"GIT_OBJECT_DIRECTORY",
|
|
15
|
+
"GIT_PREFIX",
|
|
16
|
+
"GIT_WORK_TREE",
|
|
17
|
+
];
|
|
18
|
+
function envForCwd() {
|
|
19
|
+
const env = { ...process.env };
|
|
20
|
+
for (const key of INHERITED_GIT_VARS)
|
|
21
|
+
delete env[key];
|
|
22
|
+
return env;
|
|
23
|
+
}
|
|
24
|
+
function runGit(args, cwd) {
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
const proc = spawn("git", args, { cwd, env: envForCwd(), stdio: ["ignore", "pipe", "pipe"] });
|
|
27
|
+
let stdout = "";
|
|
28
|
+
let stderr = "";
|
|
29
|
+
proc.stdout.on("data", (chunk) => (stdout += chunk));
|
|
30
|
+
proc.stderr.on("data", (chunk) => (stderr += chunk));
|
|
31
|
+
proc.on("error", reject);
|
|
32
|
+
proc.on("close", (code) => resolve({ exitCode: code ?? 1, stderr, stdout }));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/** `git args` in `cwd`: its trimmed stdout; throws with its stderr when it exits non-zero. */
|
|
36
|
+
export async function gitOutput(args, cwd) {
|
|
37
|
+
const result = await runGit(args, cwd);
|
|
38
|
+
if (result.exitCode !== 0) {
|
|
39
|
+
throw new Error(`git ${args.join(" ")} failed: ${result.stderr.trim()}`);
|
|
40
|
+
}
|
|
41
|
+
return result.stdout.trim();
|
|
42
|
+
}
|
|
43
|
+
/** `git args` in `cwd`, for its effect; throws with its stderr when it exits non-zero. */
|
|
44
|
+
export async function gitRun(args, cwd) {
|
|
45
|
+
await gitOutput(args, cwd);
|
|
46
|
+
}
|
|
47
|
+
/** `git args` in `cwd`: its exit code, whatever it is. */
|
|
48
|
+
export async function gitExitCode(args, cwd) {
|
|
49
|
+
return (await runGit(args, cwd)).exitCode;
|
|
50
|
+
}
|
|
51
|
+
/** The commit `branch` points at on the remote `mirrorUrl`; undefined when the remote or the branch is not there. */
|
|
52
|
+
export async function getRemoteTip(mirrorUrl, branch, cwd) {
|
|
53
|
+
const result = await runGit(["ls-remote", mirrorUrl, `refs/heads/${branch}`], cwd);
|
|
54
|
+
if (result.exitCode !== 0)
|
|
55
|
+
return undefined;
|
|
56
|
+
const line = result.stdout.trim();
|
|
57
|
+
if (!line)
|
|
58
|
+
return undefined;
|
|
59
|
+
return line.split("\t")[0];
|
|
60
|
+
}
|
|
61
|
+
/** A GitHub SSH remote as the token-authenticated https URL every push uses; any other URL is left as it is. */
|
|
62
|
+
export function sshToHttps(sshUrl, token) {
|
|
63
|
+
return sshUrl.replace(/^git@github\.com:/, `https://x-access-token:${token}@github.com/`);
|
|
64
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@workerstack/clients/release`: what a product's `release.config.ts` imports, and the loader the release commands
|
|
3
|
+
* read it with.
|
|
4
|
+
*/
|
|
5
|
+
export { defineRelease, RELEASE_VERSIONS_ENV } from "./manifest.ts";
|
|
6
|
+
export { loadRelease } from "./load.ts";
|
|
7
|
+
export type { Committer, HoneyRun, ManifestPackage, ManifestPackageInput, PackageMetadata, PublicPackage, Registry, Release, ReleaseManifestInput, SpecSource, } from "./types.ts";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type RegisterHooks } from "../installers/config/hooks/node.ts";
|
|
2
|
+
import { type RuntimeInfo } from "../installers/config/load.ts";
|
|
3
|
+
import type { Release } from "./types.ts";
|
|
4
|
+
/** The specifier a release config imports `defineRelease` from, resolved to the running package. */
|
|
5
|
+
export declare const RELEASE_SPECIFIER = "@workerstack/clients/release";
|
|
6
|
+
type Importer = (url: string) => Promise<Record<string, unknown>>;
|
|
7
|
+
/** What a load runs on beside the config's path; each defaults to the running process's own. */
|
|
8
|
+
export type LoadReleaseOptions = {
|
|
9
|
+
/** The runtime the config is imported on: Node needs 22.18 (23.6 on 23) for a `.ts` config. */
|
|
10
|
+
readonly runtime?: RuntimeInfo;
|
|
11
|
+
/** The entry the config's `@workerstack/clients/release` import resolves to: this package's `release/index`. */
|
|
12
|
+
readonly selfUrl?: string;
|
|
13
|
+
/** Imports a module by URL: `import()`. */
|
|
14
|
+
readonly importModule?: Importer;
|
|
15
|
+
/** Node's `module.registerHooks`. */
|
|
16
|
+
readonly registerHooks?: RegisterHooks;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* The release `configPath` (relative to the working directory) describes, imported on `options`' runtime: its
|
|
20
|
+
* packages placed beside it, in the repo whose git toplevel holds it. Throws naming the config when it is not there,
|
|
21
|
+
* sits outside a git repository, has no default export, or is invalid.
|
|
22
|
+
*/
|
|
23
|
+
export declare function readRelease(configPath: string, options: LoadReleaseOptions): Promise<Release>;
|
|
24
|
+
/**
|
|
25
|
+
* The release `configPath` (relative to the working directory) describes: its packages placed beside it, in the repo
|
|
26
|
+
* whose git toplevel holds it. Throws naming the config when it is not there, sits outside a git repository, has no
|
|
27
|
+
* default export, or is invalid.
|
|
28
|
+
*/
|
|
29
|
+
export declare function loadRelease(configPath: string): Promise<Release>;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Loads a `release.config.ts` the way an installgen config loads: a config outside any install (a fixture dir, a repo
|
|
11
|
+
* that runs `bunx`) has no `node_modules` to resolve `@workerstack/clients/release` from, so that one import is
|
|
12
|
+
* mapped to the running package's own entry while the config is imported (a Node resolve hook, deregistered after;
|
|
13
|
+
* a Bun virtual module). jiti would resolve it against a local install, which is exactly what is missing.
|
|
14
|
+
*/
|
|
15
|
+
import { existsSync, realpathSync } from "node:fs";
|
|
16
|
+
import { dirname, extname, resolve } from "node:path";
|
|
17
|
+
import { pathToFileURL } from "node:url";
|
|
18
|
+
import { registerBunHook } from "../installers/config/hooks/bun.js";
|
|
19
|
+
import { registerNodeHook } from "../installers/config/hooks/node.js";
|
|
20
|
+
import { detectRuntime, stripsTypes } from "../installers/config/load.js";
|
|
21
|
+
import { gitOutput } from "./git.js";
|
|
22
|
+
import { placeRelease } from "./manifest.js";
|
|
23
|
+
/** The specifier a release config imports `defineRelease` from, resolved to the running package. */
|
|
24
|
+
export const RELEASE_SPECIFIER = "@workerstack/clients/release";
|
|
25
|
+
/* the config's default export, imported with the self-resolve hook in place for the import alone */
|
|
26
|
+
async function importConfig(path, options) {
|
|
27
|
+
const runtime = options.runtime ?? detectRuntime();
|
|
28
|
+
const ext = extname(path);
|
|
29
|
+
if (runtime.runtime === "node" && (ext === ".ts" || ext === ".mts") && !stripsTypes(runtime.nodeVersion)) {
|
|
30
|
+
throw new Error(`${path}: a TypeScript release config needs Node >= 22.18 (23.6 on Node 23; this is ${runtime.nodeVersion}); ` +
|
|
31
|
+
"run honey-clients with Bun, or upgrade Node");
|
|
32
|
+
}
|
|
33
|
+
const importModule = options.importModule ?? ((url) => import(__rewriteRelativeImportExtension(url)));
|
|
34
|
+
/* the sibling entry in this module's own form: index.ts from a checkout's source, index.js from an install */
|
|
35
|
+
const selfUrl = options.selfUrl ?? new URL(`./index${extname(new URL(import.meta.url).pathname)}`, import.meta.url).href;
|
|
36
|
+
let hook;
|
|
37
|
+
if (runtime.bun)
|
|
38
|
+
await registerBunHook(runtime.bun, RELEASE_SPECIFIER, selfUrl, importModule);
|
|
39
|
+
else
|
|
40
|
+
hook = registerNodeHook(RELEASE_SPECIFIER, selfUrl, options.registerHooks);
|
|
41
|
+
try {
|
|
42
|
+
return (await importModule(pathToFileURL(path).href)).default;
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
throw new Error(`failed to load ${path}: ${error instanceof Error ? error.message : String(error)}`, {
|
|
46
|
+
cause: error,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
hook?.deregister();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The release `configPath` (relative to the working directory) describes, imported on `options`' runtime: its
|
|
55
|
+
* packages placed beside it, in the repo whose git toplevel holds it. Throws naming the config when it is not there,
|
|
56
|
+
* sits outside a git repository, has no default export, or is invalid.
|
|
57
|
+
*/
|
|
58
|
+
export async function readRelease(configPath, options) {
|
|
59
|
+
if (!existsSync(configPath))
|
|
60
|
+
throw new Error(`${configPath}: no such release config`);
|
|
61
|
+
/* git reports its toplevel with symlinks resolved, so the config's path is too: one is made relative to the other */
|
|
62
|
+
const path = realpathSync(resolve(configPath));
|
|
63
|
+
const root = await gitOutput(["rev-parse", "--show-toplevel"], dirname(path)).catch((error) => {
|
|
64
|
+
throw new Error(`${configPath}: not inside a git repository`, { cause: error });
|
|
65
|
+
});
|
|
66
|
+
const raw = await importConfig(path, options);
|
|
67
|
+
if (raw === undefined)
|
|
68
|
+
throw new Error(`${configPath} has no default export; write \`export default defineRelease({ ... })\``);
|
|
69
|
+
return placeRelease(raw, root, path);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The release `configPath` (relative to the working directory) describes: its packages placed beside it, in the repo
|
|
73
|
+
* whose git toplevel holds it. Throws naming the config when it is not there, sits outside a git repository, has no
|
|
74
|
+
* default export, or is invalid.
|
|
75
|
+
*/
|
|
76
|
+
export function loadRelease(configPath) {
|
|
77
|
+
return readRelease(configPath, {});
|
|
78
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PublicPackage, Release, ReleaseManifestInput } from "./types.ts";
|
|
2
|
+
/** The one shape of a public repo's remote that sync pushes to: an SSH URL on github.com. */
|
|
3
|
+
export declare const MIRROR_ALLOWLIST: RegExp;
|
|
4
|
+
/** Env var bump sets for codegen: JSON `{ [packageName]: version }`, the version each package generates at. */
|
|
5
|
+
export declare const RELEASE_VERSIONS_ENV = "RELEASE_VERSIONS";
|
|
6
|
+
/** Types a product's `release.config.ts`; `loadRelease` parses it. */
|
|
7
|
+
export declare function defineRelease(manifest: ReleaseManifestInput): ReleaseManifestInput;
|
|
8
|
+
/** A package's `<project>/<name>`, unique across products; `--only` takes it as well as the bare name. */
|
|
9
|
+
export declare function packageKey(pkg: PublicPackage): string;
|
|
10
|
+
/**
|
|
11
|
+
* The packages `raw`, a release config's default export, places in the repo whose git toplevel is `root`; the config
|
|
12
|
+
* lives at the absolute `configPath`, and each package's dir sits beside it. Throws naming the config on a config
|
|
13
|
+
* that is invalid, a committed spec or a package dir that is not there, or a dir beside the config it does not list.
|
|
14
|
+
*/
|
|
15
|
+
export declare function placeRelease(raw: unknown, root: string, configPath: string): Release;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A product lists its public packages in one `release.config.ts`. A package's dir is `<config dir>/<name>` and its
|
|
3
|
+
* public repo is `github.com/<repo>`; both are derived here, so the config never repeats them. The schemas are built
|
|
4
|
+
* on use, each checked against the shapes `types.ts` publishes.
|
|
5
|
+
*/
|
|
6
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
7
|
+
import { dirname, join, relative } from "node:path";
|
|
8
|
+
import * as z from "zod";
|
|
9
|
+
import { TARGETS } from "../gen/targets.js";
|
|
10
|
+
import { DEFAULT_COMMITTER, DESCRIPTION_MAX, HTTP_PROTOCOL, HTTPS_PROTOCOL, TOPICS_MAX } from "./constants.js";
|
|
11
|
+
const SLUG = /^[a-z][a-z0-9-]*$/;
|
|
12
|
+
/* a topic is GitHub's lowercase slug of up to 50 characters */
|
|
13
|
+
const TOPIC = /^[a-z0-9][a-z0-9-]{0,49}$/;
|
|
14
|
+
/* https, or http on loopback for tests */
|
|
15
|
+
const LOOPBACK = ["127.0.0.1", "localhost", "[::1]"];
|
|
16
|
+
/** The one shape of a public repo's remote that sync pushes to: an SSH URL on github.com. */
|
|
17
|
+
export const MIRROR_ALLOWLIST = /^git@github\.com:[a-z0-9-]+\/[a-z0-9-]+\.git$/;
|
|
18
|
+
/** Env var bump sets for codegen: JSON `{ [packageName]: version }`, the version each package generates at. */
|
|
19
|
+
export const RELEASE_VERSIONS_ENV = "RELEASE_VERSIONS";
|
|
20
|
+
/* one entry per METADATA_FIELDS name */
|
|
21
|
+
function packageMetadata() {
|
|
22
|
+
const text = z.string().min(1).optional();
|
|
23
|
+
const list = z.array(z.string().min(1)).optional();
|
|
24
|
+
return z.strictObject({
|
|
25
|
+
authors: list,
|
|
26
|
+
changelog: text,
|
|
27
|
+
copyright: text,
|
|
28
|
+
description: text,
|
|
29
|
+
documentation: text,
|
|
30
|
+
homepage: text,
|
|
31
|
+
icon: text,
|
|
32
|
+
keywords: list,
|
|
33
|
+
license: text,
|
|
34
|
+
licenseFile: text,
|
|
35
|
+
readme: text,
|
|
36
|
+
repository: text,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/* names come from the package's own files, so a registry carries only what those files cannot say */
|
|
40
|
+
function registry() {
|
|
41
|
+
return z.discriminatedUnion("kind", [
|
|
42
|
+
z.object({ kind: z.enum(["crates", "go", "jsr", "maven", "npm", "nuget", "pypi"]) }),
|
|
43
|
+
z.object({ assets: z.array(z.string().min(1)).min(1), kind: z.literal("github") }),
|
|
44
|
+
]);
|
|
45
|
+
}
|
|
46
|
+
function manifestPackage() {
|
|
47
|
+
return z.object({
|
|
48
|
+
bootstrapExclude: z.array(z.string()).optional(),
|
|
49
|
+
branch: z.string().default("main"),
|
|
50
|
+
commitMessage: z.string().min(1),
|
|
51
|
+
description: z.string().min(1).max(DESCRIPTION_MAX),
|
|
52
|
+
honey: z.object({ options: z.record(z.string(), z.string()).default({}), target: z.enum(TARGETS) }).optional(),
|
|
53
|
+
metadata: packageMetadata().optional(),
|
|
54
|
+
name: z.string().regex(SLUG),
|
|
55
|
+
registries: z.array(registry()).default([]),
|
|
56
|
+
repo: z.string().regex(/^[a-z0-9-]+\/[a-z0-9-]+$/, "repo must be owner/name on github.com"),
|
|
57
|
+
topics: z.array(z.string().regex(TOPIC, "a topic is a lowercase slug")).min(1).max(TOPICS_MAX),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function specSource() {
|
|
61
|
+
return z.object({
|
|
62
|
+
committedPath: z.string().min(1),
|
|
63
|
+
deployedUrl: z.url().refine((value) => {
|
|
64
|
+
const url = new URL(value);
|
|
65
|
+
return url.protocol === HTTPS_PROTOCOL || (url.protocol === HTTP_PROTOCOL && LOOPBACK.includes(url.hostname));
|
|
66
|
+
}, "deployedUrl must be https (http only on a loopback host)"),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function releaseManifest() {
|
|
70
|
+
return z
|
|
71
|
+
.object({
|
|
72
|
+
codegen: z.array(z.string().min(1)).min(1),
|
|
73
|
+
/* git takes any address; a GitHub App's bot address (`123+app[bot]@users.noreply.github.com`) is no RFC email */
|
|
74
|
+
committer: z
|
|
75
|
+
.strictObject({ email: z.string().regex(/^[^\s@]+@[^\s@]+$/, "an email address"), name: z.string().min(1) })
|
|
76
|
+
.default(DEFAULT_COMMITTER),
|
|
77
|
+
homepage: z.url({ protocol: /^https$/ }),
|
|
78
|
+
metadata: packageMetadata().optional(),
|
|
79
|
+
packages: z.array(manifestPackage()).min(1),
|
|
80
|
+
project: z.string().regex(SLUG),
|
|
81
|
+
spec: specSource(),
|
|
82
|
+
toolchains: z
|
|
83
|
+
.array(z.string().regex(SLUG, "a toolchain is a system.config.ts dep name (a lowercase slug)"))
|
|
84
|
+
.default([]),
|
|
85
|
+
})
|
|
86
|
+
.superRefine((manifest, ctx) => {
|
|
87
|
+
for (const key of ["name", "repo"]) {
|
|
88
|
+
const seen = new Set();
|
|
89
|
+
for (const pkg of manifest.packages) {
|
|
90
|
+
if (seen.has(pkg[key]))
|
|
91
|
+
ctx.addIssue({ code: "custom", message: `duplicate ${key}: ${pkg[key]}` });
|
|
92
|
+
seen.add(pkg[key]);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/** Types a product's `release.config.ts`; `loadRelease` parses it. */
|
|
98
|
+
export function defineRelease(manifest) {
|
|
99
|
+
return manifest;
|
|
100
|
+
}
|
|
101
|
+
/** A package's `<project>/<name>`, unique across products; `--only` takes it as well as the bare name. */
|
|
102
|
+
export function packageKey(pkg) {
|
|
103
|
+
return `${pkg.project}/${pkg.name}`;
|
|
104
|
+
}
|
|
105
|
+
/** A package's metadata: the product's, then its own over it, its keywords added to the product's. */
|
|
106
|
+
function metadataOf(product, own) {
|
|
107
|
+
const keywords = [...(product?.keywords ?? []), ...(own?.keywords ?? [])];
|
|
108
|
+
return { ...product, ...own, ...(keywords.length === 0 ? {} : { keywords }) };
|
|
109
|
+
}
|
|
110
|
+
/* the slug the config names, read before the rest: every package's key and the codegen's filter depend on it */
|
|
111
|
+
function projectOf(file, raw) {
|
|
112
|
+
const project = typeof raw === "object" && raw !== null ? raw.project : undefined;
|
|
113
|
+
if (typeof project === "string" && SLUG.test(project))
|
|
114
|
+
return project;
|
|
115
|
+
throw new Error(`${file}: project: expected a slug, got ${JSON.stringify(project) ?? "undefined"}`);
|
|
116
|
+
}
|
|
117
|
+
/* the dirs beside the config that are neither a listed package nor hidden: a package the config forgot */
|
|
118
|
+
function unlistedDirs(configDir, listed) {
|
|
119
|
+
return readdirSync(configDir, { withFileTypes: true })
|
|
120
|
+
.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !listed.has(entry.name))
|
|
121
|
+
.map((entry) => join(configDir, entry.name));
|
|
122
|
+
}
|
|
123
|
+
/* the config's schema-checked contents; throws listing every issue, naming the config */
|
|
124
|
+
function parsed(file, raw) {
|
|
125
|
+
const result = releaseManifest().safeParse(raw);
|
|
126
|
+
if (result.success)
|
|
127
|
+
return result.data;
|
|
128
|
+
const issues = result.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("\n ");
|
|
129
|
+
throw new Error(`${file} is invalid:\n ${issues}`);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The packages `raw`, a release config's default export, places in the repo whose git toplevel is `root`; the config
|
|
133
|
+
* lives at the absolute `configPath`, and each package's dir sits beside it. Throws naming the config on a config
|
|
134
|
+
* that is invalid, a committed spec or a package dir that is not there, or a dir beside the config it does not list.
|
|
135
|
+
*/
|
|
136
|
+
export function placeRelease(raw, root, configPath) {
|
|
137
|
+
const file = relative(root, configPath);
|
|
138
|
+
const project = projectOf(file, raw);
|
|
139
|
+
const data = parsed(file, raw);
|
|
140
|
+
const committedPath = join(root, data.spec.committedPath);
|
|
141
|
+
if (!existsSync(committedPath)) {
|
|
142
|
+
throw new Error(`${file}: spec.committedPath ${data.spec.committedPath} does not exist`);
|
|
143
|
+
}
|
|
144
|
+
const spec = { committedPath, deployedUrl: data.spec.deployedUrl };
|
|
145
|
+
const configDir = dirname(configPath);
|
|
146
|
+
const packages = data.packages.map((pkg) => ({
|
|
147
|
+
...pkg,
|
|
148
|
+
codegen: data.codegen,
|
|
149
|
+
committer: data.committer,
|
|
150
|
+
homepage: data.homepage,
|
|
151
|
+
metadata: metadataOf(data.metadata, pkg.metadata),
|
|
152
|
+
mirror: `git@github.com:${pkg.repo}.git`,
|
|
153
|
+
path: relative(root, join(configDir, pkg.name)),
|
|
154
|
+
project,
|
|
155
|
+
spec,
|
|
156
|
+
}));
|
|
157
|
+
const missing = packages.filter((pkg) => !existsSync(join(root, pkg.path))).map((pkg) => pkg.path);
|
|
158
|
+
if (missing.length > 0)
|
|
159
|
+
throw new Error(`${file} lists packages with no dir: ${missing.join(", ")}`);
|
|
160
|
+
const unlisted = unlistedDirs(configDir, new Set(packages.map((pkg) => pkg.name)));
|
|
161
|
+
if (unlisted.length > 0)
|
|
162
|
+
throw new Error(`${file} does not list: ${unlisted.map((dir) => relative(root, dir)).join(", ")}`);
|
|
163
|
+
return { codegen: data.codegen, packages, project, root, spec, toolchains: data.toolchains };
|
|
164
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
/** The oasdiff module `go run` builds and caches: the breaking-change rules a bump's level comes from. */
|
|
3
|
+
export declare const OASDIFF = "github.com/oasdiff/oasdiff@v1.35.0";
|
|
4
|
+
/** One oasdiff changelog entry: level 1 INFO, 2 WARN, 3 ERR (breaking). */
|
|
5
|
+
declare function apiChangeSchema(): z.ZodObject<{
|
|
6
|
+
id: z.ZodString;
|
|
7
|
+
level: z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<2>, z.ZodLiteral<3>]>;
|
|
8
|
+
operation: z.ZodOptional<z.ZodString>;
|
|
9
|
+
operationId: z.ZodOptional<z.ZodString>;
|
|
10
|
+
path: z.ZodOptional<z.ZodString>;
|
|
11
|
+
text: z.ZodString;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
/** One change oasdiff reports between two specs. */
|
|
14
|
+
export type ApiChange = z.infer<ReturnType<typeof apiChangeSchema>>;
|
|
15
|
+
/**
|
|
16
|
+
* Every change oasdiff finds from `baseFile` to `revisionFile`, run through `go run` in `env` (the Go on its PATH, its
|
|
17
|
+
* GOTOOLCHAIN honored); throws with oasdiff's stderr when it fails, and says so when Go cannot start.
|
|
18
|
+
*/
|
|
19
|
+
export declare function apiChanges(baseFile: string, revisionFile: string, env?: NodeJS.ProcessEnv): readonly ApiChange[];
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
import { MAX_OUTPUT_BYTES, OASDIFF_LEVEL } from "./constants.js";
|
|
4
|
+
/** The oasdiff module `go run` builds and caches: the breaking-change rules a bump's level comes from. */
|
|
5
|
+
export const OASDIFF = "github.com/oasdiff/oasdiff@v1.35.0";
|
|
6
|
+
/** One oasdiff changelog entry: level 1 INFO, 2 WARN, 3 ERR (breaking). */
|
|
7
|
+
function apiChangeSchema() {
|
|
8
|
+
return z.object({
|
|
9
|
+
id: z.string(),
|
|
10
|
+
level: z.union([z.literal(OASDIFF_LEVEL.INFO), z.literal(OASDIFF_LEVEL.WARN), z.literal(OASDIFF_LEVEL.ERR)]),
|
|
11
|
+
operation: z.string().optional(),
|
|
12
|
+
operationId: z.string().optional(),
|
|
13
|
+
path: z.string().optional(),
|
|
14
|
+
text: z.string(),
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
/* the Go on the caller's PATH, in its environment: a test hands in go-env's, whose GOTOOLCHAIN pins it */
|
|
18
|
+
const GO_BINARY = "go";
|
|
19
|
+
/**
|
|
20
|
+
* Every change oasdiff finds from `baseFile` to `revisionFile`, run through `go run` in `env` (the Go on its PATH, its
|
|
21
|
+
* GOTOOLCHAIN honored); throws with oasdiff's stderr when it fails, and says so when Go cannot start.
|
|
22
|
+
*/
|
|
23
|
+
export function apiChanges(baseFile, revisionFile, env = process.env) {
|
|
24
|
+
const result = spawnSync(GO_BINARY, ["run", OASDIFF, "changelog", baseFile, revisionFile, "--format", "json"], {
|
|
25
|
+
encoding: "utf8",
|
|
26
|
+
env,
|
|
27
|
+
maxBuffer: MAX_OUTPUT_BYTES,
|
|
28
|
+
});
|
|
29
|
+
if (result.error)
|
|
30
|
+
throw new Error(`oasdiff could not start (it runs through Go on PATH): ${result.error.message}`);
|
|
31
|
+
if (result.status !== 0) {
|
|
32
|
+
throw new Error(`oasdiff failed (${result.status}): ${result.stderr.trim()}`);
|
|
33
|
+
}
|
|
34
|
+
/* `[]` when the specs do not differ */
|
|
35
|
+
return z.array(apiChangeSchema()).parse(JSON.parse(result.stdout));
|
|
36
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How each registry kind names the package, reads its version, publishes, and shows it is live: the steps the
|
|
3
|
+
* rendered `release.yml` runs for it.
|
|
4
|
+
*/
|
|
5
|
+
import type { Registry } from "./types.ts";
|
|
6
|
+
export declare const ACTIONS: {
|
|
7
|
+
readonly checkout: "actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1";
|
|
8
|
+
readonly cratesAuth: "rust-lang/crates-io-auth-action@3268eb413133e2960fa4ae0e963ca76380c54cd9 # v1.0.6";
|
|
9
|
+
readonly nugetLogin: "NuGet/login@8d196754b4036150537f80ac539e15c2f1028841 # v1.2.0";
|
|
10
|
+
readonly pypiPublish: "pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3";
|
|
11
|
+
readonly rustToolchain: "dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8";
|
|
12
|
+
readonly setupDotnet: "actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0";
|
|
13
|
+
readonly setupGradle: "gradle/actions/setup-gradle@3f5f9adaf7d9fecd50b5935e54106014257a94e6 # v6.4.0";
|
|
14
|
+
readonly setupJava: "actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad # v6.1.0";
|
|
15
|
+
readonly setupNode: "actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0";
|
|
16
|
+
readonly setupPython: "actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0";
|
|
17
|
+
};
|
|
18
|
+
export declare const TOOLS: {
|
|
19
|
+
readonly build: "1.6.1";
|
|
20
|
+
readonly dotnet: "10.0.403";
|
|
21
|
+
readonly gradle: "9.8.2";
|
|
22
|
+
readonly java: "21";
|
|
23
|
+
readonly jsr: "0.14.3";
|
|
24
|
+
readonly node: "24";
|
|
25
|
+
readonly npm: "12.2.1";
|
|
26
|
+
readonly python: "3.12";
|
|
27
|
+
readonly rust: "1.99.0";
|
|
28
|
+
};
|
|
29
|
+
/** How one registry kind names the package, reads its version, publishes, and shows it is live. */
|
|
30
|
+
export type Kind = {
|
|
31
|
+
/** The package's own file the registry publishes the version of. */
|
|
32
|
+
file: string;
|
|
33
|
+
/** Shell that prints that version. */
|
|
34
|
+
version: string;
|
|
35
|
+
/** Shell that prints the name the registry knows the package by. */
|
|
36
|
+
name: string;
|
|
37
|
+
/** Publish steps (YAML list items, indented for `steps:`). */
|
|
38
|
+
publish: string;
|
|
39
|
+
/** A shell condition, true once the registry serves `$NAME` at `$VERSION`. */
|
|
40
|
+
live: string;
|
|
41
|
+
/** Environment the live check needs (YAML `env:` lines, indented for a step). */
|
|
42
|
+
liveEnv?: string;
|
|
43
|
+
oidc: boolean;
|
|
44
|
+
/** How many 10 s waits the live check allows (60 unless the registry lags longer). */
|
|
45
|
+
tries?: number;
|
|
46
|
+
};
|
|
47
|
+
/** The steps the release workflow runs for `registry`. */
|
|
48
|
+
export declare function kind(registry: Registry): Kind;
|