Files
openclaw/scripts/release-check.ts

129 lines
3.6 KiB
TypeScript
Raw Normal View History

2026-01-18 18:46:18 +00:00
#!/usr/bin/env -S node --import tsx
2025-12-27 19:35:39 +01:00
import { execSync } from "node:child_process";
2026-01-15 07:08:33 +00:00
import { readdirSync, readFileSync } from "node:fs";
import { join, resolve } from "node:path";
2025-12-27 19:35:39 +01:00
type PackFile = { path: string };
type PackResult = { files?: PackFile[] };
const requiredPathGroups = [
["dist/index.js", "dist/index.mjs"],
["dist/entry.js", "dist/entry.mjs"],
"dist/plugin-sdk/index.js",
"dist/plugin-sdk/index.d.ts",
"dist/build-info.json",
];
2026-01-30 03:15:10 +01:00
const forbiddenPrefixes = ["dist/OpenClaw.app/"];
2025-12-27 19:35:39 +01:00
2026-01-15 07:08:33 +00:00
type PackageJson = {
name?: string;
version?: string;
};
function normalizePluginSyncVersion(version: string): string {
const normalized = version.trim().replace(/^v/, "");
const base = /^([0-9]+\.[0-9]+\.[0-9]+)/.exec(normalized)?.[1];
if (base) {
return base;
}
return normalized.replace(/[-+].*$/, "");
}
2025-12-27 19:35:39 +01:00
function runPackDry(): PackResult[] {
2026-01-15 07:46:51 +00:00
const raw = execSync("npm pack --dry-run --json --ignore-scripts", {
2025-12-27 19:35:39 +01:00
encoding: "utf8",
stdio: ["ignore", "pipe", "pipe"],
2026-01-28 01:35:58 +01:00
maxBuffer: 1024 * 1024 * 100,
2025-12-27 19:35:39 +01:00
});
return JSON.parse(raw) as PackResult[];
}
2026-01-15 07:08:33 +00:00
function checkPluginVersions() {
const rootPackagePath = resolve("package.json");
const rootPackage = JSON.parse(readFileSync(rootPackagePath, "utf8")) as PackageJson;
const targetVersion = rootPackage.version;
const targetBaseVersion = targetVersion ? normalizePluginSyncVersion(targetVersion) : null;
2026-01-15 07:08:33 +00:00
if (!targetVersion || !targetBaseVersion) {
2026-01-15 07:08:33 +00:00
console.error("release-check: root package.json missing version.");
process.exit(1);
}
const extensionsDir = resolve("extensions");
const entries = readdirSync(extensionsDir, { withFileTypes: true }).filter((entry) =>
entry.isDirectory(),
);
const mismatches: string[] = [];
for (const entry of entries) {
const packagePath = join(extensionsDir, entry.name, "package.json");
let pkg: PackageJson;
try {
pkg = JSON.parse(readFileSync(packagePath, "utf8")) as PackageJson;
} catch {
continue;
}
if (!pkg.name || !pkg.version) {
continue;
}
if (normalizePluginSyncVersion(pkg.version) !== targetBaseVersion) {
2026-01-15 07:08:33 +00:00
mismatches.push(`${pkg.name} (${pkg.version})`);
}
}
if (mismatches.length > 0) {
console.error(
`release-check: plugin versions must match release base ${targetBaseVersion} (root ${targetVersion}):`,
);
2026-01-15 07:08:33 +00:00
for (const item of mismatches) {
console.error(` - ${item}`);
}
2026-01-16 02:58:08 +00:00
console.error("release-check: run `pnpm plugins:sync` to align plugin versions.");
2026-01-15 07:08:33 +00:00
process.exit(1);
}
}
2025-12-27 19:35:39 +01:00
function main() {
2026-01-15 07:08:33 +00:00
checkPluginVersions();
2025-12-27 19:35:39 +01:00
const results = runPackDry();
const files = results.flatMap((entry) => entry.files ?? []);
const paths = new Set(files.map((file) => file.path));
const missing = requiredPathGroups
.flatMap((group) => {
if (Array.isArray(group)) {
return group.some((path) => paths.has(path)) ? [] : [group.join(" or ")];
}
return paths.has(group) ? [] : [group];
})
.toSorted();
2025-12-27 19:35:39 +01:00
const forbidden = [...paths].filter((path) =>
forbiddenPrefixes.some((prefix) => path.startsWith(prefix)),
);
if (missing.length > 0 || forbidden.length > 0) {
if (missing.length > 0) {
console.error("release-check: missing files in npm pack:");
for (const path of missing) {
console.error(` - ${path}`);
}
}
if (forbidden.length > 0) {
console.error("release-check: forbidden files in npm pack:");
for (const path of forbidden) {
console.error(` - ${path}`);
}
}
process.exit(1);
}
console.log("release-check: npm pack contents look OK.");
}
main();