mirror of
https://github.com/openclaw/openclaw.git
synced 2026-10-03 09:39:25 +00:00
## What Problem This Solves Repository scripts retain private copies of shared tooling helpers and an unused translation subprocess runner, increasing maintenance work across sibling scripts. ## User Impact Internal tooling cleanup: existing flags, diagnostics, generated bytes, JSON formats, exit codes, and cleanup policies stay the same. The build wrapper additionally detects forbidden dynamic-import warnings when compiler output splits the warning marker across chunks. ## Why This Change Was Made - Remove the retired i18n process runner. Its final production caller moved to the shared formatter in #95534; retain real CLI/privacy/provider tests and run their subprocesses with the existing dependency. - Share Docker resource, signal-trap, platform, workspace-staging, and plugin-selection helpers while retaining each caller's environment precedence and lifecycle decisions. - Reuse existing E2E fixture JSON/assertion and package-path helpers; retain distinct write modes, recovery ordering, and mounted/frozen harness contracts. - Share macOS guest desktop-user/home resolution through its existing owner while preserving per-caller timeout policy. - Route release/mobile flags through the existing version flag specifications, preserving split-only values, duplicate/mode rules, help timing, and error text. Reuse existing retry sleep and comparator owners and remove an unreachable iOS output branch. - Reuse existing guard entrypoint, failure-trailer, diagnostic-line, and metadata-normalization owners. Measured reduction: **732 net production lines**, with test changes counted separately. PR tooling and its protected import closure, CI planners/shards, baselines, and generated artifacts are unchanged. ## Fixes Found Along the Way The tsdown scanner checked each raw output chunk for its warning marker. It now checks the existing combined-line buffer. The regression exercises every split inside the marker and fails on the original source for the intended missing-warning assertion. ## Evidence - Blacksmith Testbox `tbx_01m3tp4sabwd0807kj9jkqqmbr`: frozen dependency install and candidate source-byte verification; all nine changed test files and 59 selected sibling files passed, including real CLI, package fixture, recovery, Docker harness, and Parallels transport contracts. - Generated channel metadata is byte-identical; differential metadata normalization cases passed. - SDK surface check passed. Independent isolated Codex review completed with no P0–P2 findings. - Initial changed checks caught an invalid direct source import in a proposed snapshot-distance consolidation; that independent change was withdrawn. No boundary exception was added. The final changed checks pass, including script/test lint and Docker shell/scheduler checks; madge reports 0 cycles and the runtime import check reports 0 cycles. - Per-file single-worker wall time for changed suites: translation 9.92s; Docker helper 38.88s; live Docker auth 1.71s; mobile ref 2.36s; mobile release 6.23s; release preparation 2.42s; version 2.04s; installer 15.01s; tsdown 2.70s. The existing Docker helper suite executes shell/process cleanup and container-command boundary fixtures; new assertions reuse those fixtures. New parser/scanner cases use no sleeps or polling. Hosted CI will be verified against this PR's exact pushed head. No live deployment or release was performed.
289 lines
9.2 KiB
TypeScript
289 lines
9.2 KiB
TypeScript
// Release Version keeps the core and explicitly selected native release trains aligned.
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { expectDefined } from "../packages/normalization-core/src/expect.js";
|
|
import {
|
|
canonicalAndroidVersionCode,
|
|
normalizeAndroidVersionCode,
|
|
normalizePinnedAndroidVersion,
|
|
renderAndroidReleaseNotes,
|
|
renderAndroidVersionProperties,
|
|
} from "./lib/android-version.ts";
|
|
import { booleanFlag, parseFlagArgs } from "./lib/arg-utils.mts";
|
|
import { parseReleaseVersion } from "./lib/release-version.mjs";
|
|
import { versionValueFlag } from "./lib/version-script-args.ts";
|
|
|
|
const MACOS_INFO_PLIST = "apps/macos/Sources/OpenClaw/Resources/Info.plist";
|
|
const ANDROID_CHANGELOG_FILE = "apps/android/CHANGELOG.md";
|
|
const ANDROID_RELEASE_NOTES_FILE = "apps/android/fastlane/metadata/android/en-US/release_notes.txt";
|
|
const ANDROID_VERSION_FILE = "apps/android/version.json";
|
|
const ANDROID_VERSION_PROPERTIES_FILE = "apps/android/Config/Version.properties";
|
|
|
|
type ReleaseVersionMode = "check" | "write";
|
|
|
|
type ReleaseVersionArgs = {
|
|
android: boolean;
|
|
help: boolean;
|
|
mode: ReleaseVersionMode;
|
|
rootDir: string;
|
|
version: string | null;
|
|
};
|
|
|
|
type ReleaseVersionChange = {
|
|
currentContent: string;
|
|
nextContent: string;
|
|
path: string;
|
|
};
|
|
|
|
type ReleaseVersionPlan = {
|
|
changes: ReleaseVersionChange[];
|
|
version: string;
|
|
};
|
|
|
|
type AndroidVersionManifest = {
|
|
version?: unknown;
|
|
versionCode?: unknown;
|
|
};
|
|
|
|
export function parseReleaseVersionArgs(argv: string[]): ReleaseVersionArgs {
|
|
const args: ReleaseVersionArgs = {
|
|
android: false,
|
|
help: false,
|
|
mode: "check",
|
|
rootDir: path.resolve("."),
|
|
version: null,
|
|
};
|
|
return parseFlagArgs(
|
|
argv,
|
|
args,
|
|
[
|
|
booleanFlag("--android", "android", true, { repeatable: true }),
|
|
booleanFlag("--check", "mode", "check", { repeatable: true }),
|
|
booleanFlag("--write", "mode", "write", { repeatable: true }),
|
|
booleanFlag("-h", "help", true, { repeatable: true }),
|
|
booleanFlag("--help", "help", true, { repeatable: true }),
|
|
versionValueFlag("--root", "rootDir", path.resolve),
|
|
versionValueFlag("--version", "version"),
|
|
],
|
|
{
|
|
onUnhandledArg(arg) {
|
|
throw new Error(`Unknown argument: ${arg}`);
|
|
},
|
|
},
|
|
);
|
|
}
|
|
|
|
export function planReleaseVersion(params: {
|
|
android?: boolean;
|
|
rootDir?: string;
|
|
version: string;
|
|
}): ReleaseVersionPlan {
|
|
const rootDir = path.resolve(params.rootDir ?? ".");
|
|
const parsedVersion = parseReleaseVersion(params.version);
|
|
if (!parsedVersion) {
|
|
throw new Error(
|
|
`Invalid release version '${params.version}'. Expected YYYY.M.PATCH, YYYY.M.PATCH-beta.N, or YYYY.M.PATCH-N.`,
|
|
);
|
|
}
|
|
|
|
if (parsedVersion.channel === "alpha") {
|
|
throw new Error("Alpha releases are retired; use a beta prerelease instead.");
|
|
}
|
|
|
|
const packageVersion =
|
|
parsedVersion.correctionNumber === undefined
|
|
? parsedVersion.version
|
|
: parsedVersion.baseVersion;
|
|
const changes = [
|
|
planPackageJson(rootDir, packageVersion),
|
|
planMacosInfoPlist(rootDir, parsedVersion),
|
|
];
|
|
if (params.android) {
|
|
changes.push(...planAndroidVersion(rootDir, parsedVersion.baseVersion));
|
|
}
|
|
|
|
return {
|
|
changes: changes.filter((change) => change.currentContent !== change.nextContent),
|
|
version: parsedVersion.version,
|
|
};
|
|
}
|
|
|
|
export function applyReleaseVersionPlan(plan: ReleaseVersionPlan): void {
|
|
const tempPaths: string[] = [];
|
|
try {
|
|
for (const [index, change] of plan.changes.entries()) {
|
|
const tempPath = `${change.path}.release-version-${process.pid}-${index}.tmp`;
|
|
fs.writeFileSync(tempPath, change.nextContent, "utf8");
|
|
tempPaths.push(tempPath);
|
|
}
|
|
for (const [index, change] of plan.changes.entries()) {
|
|
fs.renameSync(
|
|
expectDefined(tempPaths[index], `release temp path at index ${index}`),
|
|
change.path,
|
|
);
|
|
}
|
|
} finally {
|
|
for (const tempPath of tempPaths) {
|
|
fs.rmSync(tempPath, { force: true });
|
|
}
|
|
}
|
|
}
|
|
|
|
export function main(argv = process.argv.slice(2)): number {
|
|
const args = parseReleaseVersionArgs(argv);
|
|
if (args.help) {
|
|
printUsage();
|
|
return 0;
|
|
}
|
|
if (!args.version) {
|
|
throw new Error("Missing required --version.");
|
|
}
|
|
|
|
const plan = planReleaseVersion({
|
|
android: args.android,
|
|
rootDir: args.rootDir,
|
|
version: args.version,
|
|
});
|
|
if (plan.changes.length === 0) {
|
|
process.stdout.write(`Release version ${plan.version} is already aligned.\n`);
|
|
return 0;
|
|
}
|
|
|
|
const relativePaths = plan.changes.map((change) => path.relative(args.rootDir, change.path));
|
|
if (args.mode === "check") {
|
|
process.stderr.write(
|
|
`Release version ${plan.version} requires updates:\n- ${relativePaths.join("\n- ")}\n`,
|
|
);
|
|
return 1;
|
|
}
|
|
|
|
applyReleaseVersionPlan(plan);
|
|
process.stdout.write(
|
|
`Updated release version ${plan.version}:\n- ${relativePaths.join("\n- ")}\n`,
|
|
);
|
|
return 0;
|
|
}
|
|
|
|
function planPackageJson(rootDir: string, version: string): ReleaseVersionChange {
|
|
const filePath = path.join(rootDir, "package.json");
|
|
const currentContent = fs.readFileSync(filePath, "utf8");
|
|
const packageJson = JSON.parse(currentContent) as Record<string, unknown>;
|
|
if (typeof packageJson.version !== "string" || !packageJson.version.trim()) {
|
|
throw new Error(`Missing package.json version in ${filePath}.`);
|
|
}
|
|
packageJson.version = version;
|
|
return {
|
|
currentContent,
|
|
nextContent: `${JSON.stringify(packageJson, null, 2)}\n`,
|
|
path: filePath,
|
|
};
|
|
}
|
|
|
|
function planMacosInfoPlist(
|
|
rootDir: string,
|
|
releaseVersion: NonNullable<ReturnType<typeof parseReleaseVersion>>,
|
|
): ReleaseVersionChange {
|
|
const filePath = path.join(rootDir, MACOS_INFO_PLIST);
|
|
const currentContent = fs.readFileSync(filePath, "utf8");
|
|
const buildVersion = [
|
|
String(releaseVersion.year),
|
|
String(releaseVersion.month).padStart(2, "0"),
|
|
String(releaseVersion.patch).padStart(2, "0"),
|
|
"00",
|
|
].join("");
|
|
const shortVersionContent = replacePlistString(
|
|
currentContent,
|
|
"CFBundleShortVersionString",
|
|
releaseVersion.baseVersion,
|
|
MACOS_INFO_PLIST,
|
|
);
|
|
const nextContent = replacePlistString(
|
|
shortVersionContent,
|
|
"CFBundleVersion",
|
|
buildVersion,
|
|
MACOS_INFO_PLIST,
|
|
);
|
|
return { currentContent, nextContent, path: filePath };
|
|
}
|
|
|
|
function planAndroidVersion(rootDir: string, baseVersion: string): ReleaseVersionChange[] {
|
|
const versionPath = path.join(rootDir, ANDROID_VERSION_FILE);
|
|
const propertiesPath = path.join(rootDir, ANDROID_VERSION_PROPERTIES_FILE);
|
|
const changelogPath = path.join(rootDir, ANDROID_CHANGELOG_FILE);
|
|
const releaseNotesPath = path.join(rootDir, ANDROID_RELEASE_NOTES_FILE);
|
|
const versionContent = fs.readFileSync(versionPath, "utf8");
|
|
const propertiesContent = fs.readFileSync(propertiesPath, "utf8");
|
|
const changelogContent = fs.readFileSync(changelogPath, "utf8");
|
|
const releaseNotesContent = fs.readFileSync(releaseNotesPath, "utf8");
|
|
const manifest = JSON.parse(versionContent) as AndroidVersionManifest;
|
|
const currentVersion =
|
|
typeof manifest.version === "string" ? normalizePinnedAndroidVersion(manifest.version) : null;
|
|
const currentVersionCode =
|
|
typeof manifest.versionCode === "number" ? manifest.versionCode : Number.NaN;
|
|
const versionCode =
|
|
currentVersion === baseVersion
|
|
? normalizeAndroidVersionCode(currentVersionCode, baseVersion)
|
|
: canonicalAndroidVersionCode(baseVersion);
|
|
const nextVersionContent = `${JSON.stringify({ version: baseVersion, versionCode }, null, 2)}\n`;
|
|
const nextPropertiesContent = renderAndroidVersionProperties({
|
|
canonicalVersion: baseVersion,
|
|
versionCode,
|
|
});
|
|
const nextReleaseNotesContent = renderAndroidReleaseNotes(
|
|
{ canonicalVersion: baseVersion },
|
|
changelogContent,
|
|
);
|
|
|
|
return [
|
|
{
|
|
currentContent: versionContent,
|
|
nextContent: nextVersionContent,
|
|
path: versionPath,
|
|
},
|
|
{
|
|
currentContent: propertiesContent,
|
|
nextContent: nextPropertiesContent,
|
|
path: propertiesPath,
|
|
},
|
|
{
|
|
currentContent: releaseNotesContent,
|
|
nextContent: nextReleaseNotesContent,
|
|
path: releaseNotesPath,
|
|
},
|
|
];
|
|
}
|
|
|
|
function replacePlistString(content: string, key: string, value: string, filePath: string): string {
|
|
const escapedKey = key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
const pattern = new RegExp(
|
|
`(<key>\\s*${escapedKey}\\s*</key>\\s*<string>)([^<]*)(</string>)`,
|
|
"gu",
|
|
);
|
|
const matches = [...content.matchAll(pattern)];
|
|
if (matches.length !== 1) {
|
|
throw new Error(`${filePath} must contain exactly one string value for ${key}.`);
|
|
}
|
|
return content.replace(pattern, `$1${value}$3`);
|
|
}
|
|
|
|
function printUsage(): void {
|
|
process.stdout.write(
|
|
[
|
|
"Usage: node --import tsx scripts/release-version.ts --version <version> [--check|--write] [--android] [--root dir]",
|
|
"",
|
|
" --check report release version drift without writing (default)",
|
|
" --write update all selected version files after validating them",
|
|
" --android also align the independently pinned Android release train",
|
|
"",
|
|
].join("\n"),
|
|
);
|
|
}
|
|
|
|
if (import.meta.main) {
|
|
try {
|
|
process.exitCode = main();
|
|
} catch (error) {
|
|
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
process.exitCode = 1;
|
|
}
|
|
}
|