fix: keep root release metadata version-synced

This commit is contained in:
Affaan Mustafa
2026-04-12 02:36:32 -07:00
parent 1b3c4a53ba
commit c95fd4cf06
2 changed files with 71 additions and 2 deletions

View File

@@ -7,6 +7,9 @@ set -euo pipefail
VERSION="${1:-}" VERSION="${1:-}"
ROOT_PACKAGE_JSON="package.json" ROOT_PACKAGE_JSON="package.json"
PACKAGE_LOCK_JSON="package-lock.json" PACKAGE_LOCK_JSON="package-lock.json"
ROOT_AGENTS_MD="AGENTS.md"
AGENT_YAML="agent.yaml"
VERSION_FILE="VERSION"
PLUGIN_JSON=".claude-plugin/plugin.json" PLUGIN_JSON=".claude-plugin/plugin.json"
MARKETPLACE_JSON=".claude-plugin/marketplace.json" MARKETPLACE_JSON=".claude-plugin/marketplace.json"
CODEX_PLUGIN_JSON=".codex-plugin/plugin.json" CODEX_PLUGIN_JSON=".codex-plugin/plugin.json"
@@ -47,7 +50,7 @@ if ! git diff --quiet || ! git diff --cached --quiet; then
fi fi
# Verify versioned manifests exist # Verify versioned manifests exist
for FILE in "$ROOT_PACKAGE_JSON" "$PACKAGE_LOCK_JSON" "$PLUGIN_JSON" "$MARKETPLACE_JSON" "$CODEX_PLUGIN_JSON" "$OPENCODE_PACKAGE_JSON" "$OPENCODE_PACKAGE_LOCK_JSON" "$README_FILE"; do for FILE in "$ROOT_PACKAGE_JSON" "$PACKAGE_LOCK_JSON" "$ROOT_AGENTS_MD" "$AGENT_YAML" "$VERSION_FILE" "$PLUGIN_JSON" "$MARKETPLACE_JSON" "$CODEX_PLUGIN_JSON" "$OPENCODE_PACKAGE_JSON" "$OPENCODE_PACKAGE_LOCK_JSON" "$README_FILE"; do
if [[ ! -f "$FILE" ]]; then if [[ ! -f "$FILE" ]]; then
echo "Error: $FILE not found" echo "Error: $FILE not found"
exit 1 exit 1
@@ -115,9 +118,52 @@ update_readme_version_row() {
' "$README_FILE" "$VERSION" ' "$README_FILE" "$VERSION"
} }
update_agents_version() {
node -e '
const fs = require("fs");
const file = process.argv[1];
const version = process.argv[2];
const current = fs.readFileSync(file, "utf8");
const updated = current.replace(
/^\*\*Version:\*\* [0-9][0-9.]*$/m,
`**Version:** ${version}`
);
if (updated === current) {
console.error(`Error: could not update AGENTS version line in ${file}`);
process.exit(1);
}
fs.writeFileSync(file, updated);
' "$ROOT_AGENTS_MD" "$VERSION"
}
update_agent_yaml_version() {
node -e '
const fs = require("fs");
const file = process.argv[1];
const version = process.argv[2];
const current = fs.readFileSync(file, "utf8");
const updated = current.replace(
/^version:\s*[0-9][0-9.]*$/m,
`version: ${version}`
);
if (updated === current) {
console.error(`Error: could not update agent.yaml version line in ${file}`);
process.exit(1);
}
fs.writeFileSync(file, updated);
' "$AGENT_YAML" "$VERSION"
}
update_version_file() {
printf '%s\n' "$VERSION" > "$VERSION_FILE"
}
# Update all shipped package/plugin manifests # Update all shipped package/plugin manifests
update_version "$ROOT_PACKAGE_JSON" "s|\"version\": *\"[^\"]*\"|\"version\": \"$VERSION\"|" update_version "$ROOT_PACKAGE_JSON" "s|\"version\": *\"[^\"]*\"|\"version\": \"$VERSION\"|"
update_package_lock_version "$PACKAGE_LOCK_JSON" update_package_lock_version "$PACKAGE_LOCK_JSON"
update_agents_version
update_agent_yaml_version
update_version_file
update_version "$PLUGIN_JSON" "s|\"version\": *\"[^\"]*\"|\"version\": \"$VERSION\"|" update_version "$PLUGIN_JSON" "s|\"version\": *\"[^\"]*\"|\"version\": \"$VERSION\"|"
update_version "$MARKETPLACE_JSON" "0,/\"version\": *\"[^\"]*\"/s|\"version\": *\"[^\"]*\"|\"version\": \"$VERSION\"|" update_version "$MARKETPLACE_JSON" "0,/\"version\": *\"[^\"]*\"/s|\"version\": *\"[^\"]*\"|\"version\": \"$VERSION\"|"
update_version "$CODEX_PLUGIN_JSON" "s|\"version\": *\"[^\"]*\"|\"version\": \"$VERSION\"|" update_version "$CODEX_PLUGIN_JSON" "s|\"version\": *\"[^\"]*\"|\"version\": \"$VERSION\"|"
@@ -126,7 +172,7 @@ update_package_lock_version "$OPENCODE_PACKAGE_LOCK_JSON"
update_readme_version_row update_readme_version_row
# Stage, commit, tag, and push # Stage, commit, tag, and push
git add "$ROOT_PACKAGE_JSON" "$PACKAGE_LOCK_JSON" "$PLUGIN_JSON" "$MARKETPLACE_JSON" "$CODEX_PLUGIN_JSON" "$OPENCODE_PACKAGE_JSON" "$OPENCODE_PACKAGE_LOCK_JSON" "$README_FILE" git add "$ROOT_PACKAGE_JSON" "$PACKAGE_LOCK_JSON" "$ROOT_AGENTS_MD" "$AGENT_YAML" "$VERSION_FILE" "$PLUGIN_JSON" "$MARKETPLACE_JSON" "$CODEX_PLUGIN_JSON" "$OPENCODE_PACKAGE_JSON" "$OPENCODE_PACKAGE_LOCK_JSON" "$README_FILE"
git commit -m "chore: bump plugin version to $VERSION" git commit -m "chore: bump plugin version to $VERSION"
git tag "v$VERSION" git tag "v$VERSION"
git push origin main "v$VERSION" git push origin main "v$VERSION"

View File

@@ -22,6 +22,9 @@ const repoRoot = path.resolve(__dirname, '..');
const repoRootWithSep = `${repoRoot}${path.sep}`; const repoRootWithSep = `${repoRoot}${path.sep}`;
const packageJsonPath = path.join(repoRoot, 'package.json'); const packageJsonPath = path.join(repoRoot, 'package.json');
const packageLockPath = path.join(repoRoot, 'package-lock.json'); const packageLockPath = path.join(repoRoot, 'package-lock.json');
const rootAgentsPath = path.join(repoRoot, 'AGENTS.md');
const agentYamlPath = path.join(repoRoot, 'agent.yaml');
const versionFilePath = path.join(repoRoot, 'VERSION');
const opencodePackageJsonPath = path.join(repoRoot, '.opencode', 'package.json'); const opencodePackageJsonPath = path.join(repoRoot, '.opencode', 'package.json');
const opencodePackageLockPath = path.join(repoRoot, '.opencode', 'package-lock.json'); const opencodePackageLockPath = path.join(repoRoot, '.opencode', 'package-lock.json');
@@ -83,6 +86,26 @@ test('package-lock.json root version matches package.json', () => {
assert.strictEqual(packageLock.packages[''].version, expectedVersion); assert.strictEqual(packageLock.packages[''].version, expectedVersion);
}); });
test('AGENTS.md version line matches package.json', () => {
const agentsSource = fs.readFileSync(rootAgentsPath, 'utf8');
const match = agentsSource.match(/^\*\*Version:\*\* ([0-9][0-9.]*)$/m);
assert.ok(match, 'Expected AGENTS.md to declare a top-level version line');
assert.strictEqual(match[1], expectedVersion);
});
test('agent.yaml version matches package.json', () => {
const agentYamlSource = fs.readFileSync(agentYamlPath, 'utf8');
const match = agentYamlSource.match(/^version:\s*([0-9][0-9.]*)$/m);
assert.ok(match, 'Expected agent.yaml to declare a top-level version field');
assert.strictEqual(match[1], expectedVersion);
});
test('VERSION file matches package.json', () => {
const versionFile = fs.readFileSync(versionFilePath, 'utf8').trim();
assert.ok(versionFile, 'Expected VERSION file to be non-empty');
assert.strictEqual(versionFile, expectedVersion);
});
// ── Claude plugin manifest ──────────────────────────────────────────────────── // ── Claude plugin manifest ────────────────────────────────────────────────────
console.log('\n=== .claude-plugin/plugin.json ===\n'); console.log('\n=== .claude-plugin/plugin.json ===\n');