Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
191 lines
6.8 KiB
JavaScript
191 lines
6.8 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
// Temporarily narrows CHANGELOG.md to packaged release notes for npm tarballs.
|
|
import { existsSync } from "node:fs";
|
|
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const CHANGELOG_PATH = "CHANGELOG.md";
|
|
const PACKAGE_JSON_PATH = "package.json";
|
|
const BACKUP_PATH = path.join(".artifacts", "package-changelog", "CHANGELOG.md.prepack-backup");
|
|
const MAX_PACKAGED_CHANGELOG_BYTES = 500 * 1024;
|
|
const MIN_RELEASE_SECTION_BODY_BYTES = 32;
|
|
const UNRELEASED_HEADING = "Unreleased";
|
|
const RELEASE_HEADING_PATTERN =
|
|
/^##\s+([0-9]{4}\.[1-9][0-9]*\.[1-9][0-9]*(?:(?:-(?:alpha|beta)\.[1-9][0-9]*)|(?:-[1-9][0-9]*))?)(?:\s+.*)?$/u;
|
|
const RELEASE_VERSION_PATTERN =
|
|
/^([0-9]{4}\.[1-9][0-9]*\.[1-9][0-9]*)(?:(?:-(?:alpha|beta)\.[1-9][0-9]*)|(?:-[1-9][0-9]*))?$/u;
|
|
const PRERELEASE_VERSION_PATTERN =
|
|
/^([0-9]{4}\.[1-9][0-9]*\.[1-9][0-9]*)-(?:alpha|beta)\.[1-9][0-9]*$/u;
|
|
|
|
/**
|
|
* Resolves acceptable changelog headings for a package version.
|
|
*/
|
|
export function resolvePackageChangelogVersions(packageVersion) {
|
|
const match = RELEASE_VERSION_PATTERN.exec(packageVersion);
|
|
if (!match) {
|
|
throw new Error(
|
|
`Unsupported OpenClaw package version for changelog packaging: ${packageVersion}`,
|
|
);
|
|
}
|
|
if (PRERELEASE_VERSION_PATTERN.test(packageVersion)) {
|
|
return [packageVersion, match[1], UNRELEASED_HEADING];
|
|
}
|
|
return [packageVersion];
|
|
}
|
|
|
|
function splitLines(content) {
|
|
return content.replace(/^\uFEFF/u, "").split(/\r?\n/u);
|
|
}
|
|
|
|
function parseLevelTwoHeading(line) {
|
|
const releaseMatch = RELEASE_HEADING_PATTERN.exec(line);
|
|
if (releaseMatch) {
|
|
return releaseMatch[1];
|
|
}
|
|
return /^##\s+Unreleased(?:\s+.*)?$/u.test(line) ? UNRELEASED_HEADING : null;
|
|
}
|
|
|
|
function findLevelTwoHeadings(lines) {
|
|
return lines.flatMap((line, index) => {
|
|
const version = parseLevelTwoHeading(line);
|
|
return version ? [{ index, version }] : [];
|
|
});
|
|
}
|
|
|
|
function extractPreamble(lines, firstHeadingIndex) {
|
|
return lines.slice(0, firstHeadingIndex).join("\n").trimEnd();
|
|
}
|
|
|
|
/**
|
|
* Extracts the current release changelog section for package publishing.
|
|
*/
|
|
export function extractCurrentPackageChangelog(content, packageVersion) {
|
|
const targetVersions = resolvePackageChangelogVersions(packageVersion);
|
|
const lines = splitLines(content);
|
|
const headings = findLevelTwoHeadings(lines);
|
|
const heading = targetVersions
|
|
.map((version) => headings.find((entry) => entry.version === version))
|
|
.find((entry) => entry !== undefined);
|
|
if (!heading) {
|
|
throw new Error(
|
|
`CHANGELOG.md does not contain a release section for ${targetVersions.join(" or ")}.`,
|
|
);
|
|
}
|
|
const nextHeading = headings.find((entry) => entry.index > heading.index);
|
|
const firstLevelTwoHeadingIndex = lines.findIndex((line) => line.startsWith("## "));
|
|
const preamble = extractPreamble(lines, firstLevelTwoHeadingIndex);
|
|
const releaseSection = lines
|
|
.slice(heading.index, nextHeading?.index ?? lines.length)
|
|
.join("\n")
|
|
.trimEnd();
|
|
const releaseBody = releaseSection.split(/\r?\n/u).slice(1).join("\n").trim();
|
|
const releaseBodyBytes = Buffer.byteLength(releaseBody, "utf8");
|
|
if (releaseBodyBytes < MIN_RELEASE_SECTION_BODY_BYTES) {
|
|
throw new Error(
|
|
`Packaged changelog section for ${heading.version} is only ${releaseBodyBytes} body bytes, which is below the ${MIN_RELEASE_SECTION_BODY_BYTES} byte safety minimum.`,
|
|
);
|
|
}
|
|
const packaged = `${preamble}\n\n${releaseSection}\n`;
|
|
const packagedBytes = Buffer.byteLength(packaged, "utf8");
|
|
if (packagedBytes > MAX_PACKAGED_CHANGELOG_BYTES) {
|
|
throw new Error(
|
|
`Packaged changelog is ${packagedBytes} bytes, which exceeds the ${MAX_PACKAGED_CHANGELOG_BYTES} byte safety limit.`,
|
|
);
|
|
}
|
|
return packaged;
|
|
}
|
|
|
|
async function readPackageVersion(cwd) {
|
|
const packageJsonPath = path.join(cwd, PACKAGE_JSON_PATH);
|
|
const packageJson = JSON.parse(await readFile(packageJsonPath, "utf8"));
|
|
if (typeof packageJson.version !== "string") {
|
|
throw new Error("package.json version must be a string.");
|
|
}
|
|
return packageJson.version;
|
|
}
|
|
|
|
/**
|
|
* Restores the source changelog from a package-changelog backup.
|
|
*/
|
|
export async function restorePackageChangelog(cwd = process.cwd()) {
|
|
const backupPath = path.join(cwd, BACKUP_PATH);
|
|
if (!existsSync(backupPath)) {
|
|
return false;
|
|
}
|
|
const changelogPath = path.join(cwd, CHANGELOG_PATH);
|
|
const [backup, current] = await Promise.all([
|
|
readFile(backupPath, "utf8"),
|
|
readFile(changelogPath, "utf8"),
|
|
]);
|
|
if (current !== backup) {
|
|
const packageVersion = await readPackageVersion(cwd);
|
|
let expectedPackaged;
|
|
try {
|
|
expectedPackaged = extractCurrentPackageChangelog(backup, packageVersion);
|
|
} catch (error) {
|
|
const message = error instanceof Error ? error.message : String(error);
|
|
throw new Error(
|
|
`Refusing to restore stale packaged changelog backup from ${BACKUP_PATH}: ${message}`,
|
|
{ cause: error },
|
|
);
|
|
}
|
|
if (current !== expectedPackaged) {
|
|
throw new Error(
|
|
`Refusing to restore packaged changelog backup from ${BACKUP_PATH} because CHANGELOG.md has changed since the backup was written.`,
|
|
);
|
|
}
|
|
}
|
|
await writeFile(changelogPath, backup, "utf8");
|
|
await rm(backupPath, { force: true });
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Writes packaged changelog content while preserving a restorable backup.
|
|
*/
|
|
export async function preparePackageChangelog(cwd = process.cwd()) {
|
|
await restorePackageChangelog(cwd);
|
|
const changelogPath = path.join(cwd, CHANGELOG_PATH);
|
|
const backupPath = path.join(cwd, BACKUP_PATH);
|
|
const original = await readFile(changelogPath, "utf8");
|
|
const packageVersion = await readPackageVersion(cwd);
|
|
const packaged = extractCurrentPackageChangelog(original, packageVersion);
|
|
if (packaged === original) {
|
|
return false;
|
|
}
|
|
await mkdir(path.dirname(backupPath), { recursive: true });
|
|
await writeFile(backupPath, original, "utf8");
|
|
await writeFile(changelogPath, packaged, "utf8");
|
|
return true;
|
|
}
|
|
|
|
async function main(argv = process.argv.slice(2)) {
|
|
const command = argv[0];
|
|
if (command === "prepare") {
|
|
const changed = await preparePackageChangelog();
|
|
console.error(
|
|
changed
|
|
? "package-changelog: wrote current release notes for package tarball."
|
|
: "package-changelog: source changelog already matches package notes.",
|
|
);
|
|
return;
|
|
}
|
|
if (command === "restore") {
|
|
const restored = await restorePackageChangelog();
|
|
console.error(
|
|
restored
|
|
? "package-changelog: restored source CHANGELOG.md."
|
|
: "package-changelog: no packaged changelog backup to restore.",
|
|
);
|
|
return;
|
|
}
|
|
console.error("Usage: node scripts/package-changelog.mjs <prepare|restore>");
|
|
process.exitCode = 1;
|
|
}
|
|
|
|
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
await main();
|
|
}
|