ci: time-box package acceptance legacy compat

This commit is contained in:
Peter Steinberger
2026-04-27 07:11:11 +01:00
parent e6d2c9b080
commit 44a504cd39
10 changed files with 256 additions and 16 deletions

View File

@@ -48,6 +48,17 @@ const fs = require("node:fs");
const path = require("node:path");
const packageJsonPath = "/tmp/openclaw-git/package.json";
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
const isLegacyPackageAcceptanceCompat = (version) => {
const match = /^(\d{4})\.(\d{1,2})\.(\d{1,2})(?:[-+].*)?$/.exec(version || "");
if (!match) return false;
const value = [Number(match[1]), Number(match[2]), Number(match[3])];
const max = [2026, 4, 25];
for (let i = 0; i < value.length; i += 1) {
if (value[i] < max[i]) return true;
if (value[i] > max[i]) return false;
}
return true;
};
const fixtureUiBuildSource = `const fs=require("node:fs");fs.mkdirSync("dist/control-ui",{recursive:true});fs.writeFileSync("dist/control-ui/index.html","<!doctype html><title>fixture</title>\\n")`;
const fixtureUiBuildCommand = `node -e ${JSON.stringify(fixtureUiBuildSource)}`;
const nextPnpm = { ...packageJson.pnpm, allowUnusedPatches: true };
@@ -57,14 +68,28 @@ if (
typeof patchedDependencies === "object" &&
!Array.isArray(patchedDependencies)
) {
const patchEntries = Object.entries(patchedDependencies);
const keptPatches = Object.fromEntries(
Object.entries(patchedDependencies).filter(([, patchFile]) => {
patchEntries.filter(([, patchFile]) => {
return (
typeof patchFile === "string" &&
fs.existsSync(path.resolve(path.dirname(packageJsonPath), patchFile))
);
}),
);
const missingPatches = patchEntries.filter(([dependency, patchFile]) => {
return (
typeof patchFile !== "string" ||
!fs.existsSync(path.resolve(path.dirname(packageJsonPath), patchFile))
);
});
if (missingPatches.length > 0 && !isLegacyPackageAcceptanceCompat(packageJson.version)) {
throw new Error(
`package ${packageJson.version} has missing pnpm.patchedDependencies in package fixture: ${missingPatches
.map(([dependency, patchFile]) => `${dependency} -> ${patchFile}`)
.join(", ")}`,
);
}
if (Object.keys(keptPatches).length > 0) {
nextPnpm.patchedDependencies = keptPatches;
} else {
@@ -105,6 +130,31 @@ fixture_sha="$(git -C "$git_root" rev-parse HEAD)"
pkg_tgz_path="$package_tgz"
npm install -g --prefix /tmp/npm-prefix --omit=optional "$pkg_tgz_path"
package_version="$(node -p "require('/tmp/npm-prefix/lib/node_modules/openclaw/package.json').version")"
OPENCLAW_PACKAGE_ACCEPTANCE_LEGACY_COMPAT="$(
node - "$package_version" <<"NODE"
const version = process.argv[2] || "";
const match = /^(\d{4})\.(\d{1,2})\.(\d{1,2})(?:[-+].*)?$/.exec(version);
if (!match) {
console.log("0");
process.exit(0);
}
const value = [Number(match[1]), Number(match[2]), Number(match[3])];
const max = [2026, 4, 25];
for (let i = 0; i < value.length; i += 1) {
if (value[i] < max[i]) {
console.log("1");
process.exit(0);
}
if (value[i] > max[i]) {
console.log("0");
process.exit(0);
}
}
console.log("1");
NODE
)"
export OPENCLAW_PACKAGE_ACCEPTANCE_LEGACY_COMPAT
home_dir="$(mktemp -d /tmp/openclaw-update-channel-switch-home.XXXXXX)"
export HOME="$home_dir"
@@ -149,7 +199,11 @@ const path = require("node:path");
const configPath = path.join(process.env.HOME, ".openclaw", "openclaw.json");
const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
if (config.update?.channel !== "dev") {
console.log(`legacy package did not persist update.channel dev; got ${JSON.stringify(config.update?.channel)}`);
if (process.env.OPENCLAW_PACKAGE_ACCEPTANCE_LEGACY_COMPAT === "1") {
console.log(`legacy package did not persist update.channel dev; got ${JSON.stringify(config.update?.channel)}`);
} else {
throw new Error(`expected persisted update.channel dev, got ${JSON.stringify(config.update?.channel)}`);
}
}
NODE
@@ -190,7 +244,11 @@ const path = require("node:path");
const configPath = path.join(process.env.HOME, ".openclaw", "openclaw.json");
const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
if (config.update?.channel !== "stable") {
console.log(`legacy package did not persist update.channel stable; got ${JSON.stringify(config.update?.channel)}`);
if (process.env.OPENCLAW_PACKAGE_ACCEPTANCE_LEGACY_COMPAT === "1") {
console.log(`legacy package did not persist update.channel stable; got ${JSON.stringify(config.update?.channel)}`);
} else {
throw new Error(`expected persisted update.channel stable, got ${JSON.stringify(config.update?.channel)}`);
}
}
NODE