#!/usr/bin/env node // Verify that CHANGELOG.md gained at least one entry under [Unreleased] // or that a [vX.Y.Z] block was added since main. Fails CI if not. // // Skip with the PR label `no-changelog` for trivial doc-only changes. import { execSync } from "node:child_process"; import { readFileSync } from "node:fs"; const base = process.env.GITHUB_BASE_REF || "main"; let diff; try { execSync(`git fetch --no-tags --depth=50 origin ${base}`, { stdio: "ignore" }); diff = execSync(`git diff --unified=0 origin/${base}...HEAD -- CHANGELOG.md`).toString(); } catch (err) { console.error("Could not diff CHANGELOG.md:", err.message); process.exit(1); } const additions = diff.split("\n").filter(l => l.startsWith("+") && !l.startsWith("+++")); const meaningful = additions.filter(l => l.replace(/^\+/, "").trim().length > 0 && !l.includes("Unreleased")); if (meaningful.length === 0) { console.error("CHANGELOG.md has no new entries on this PR."); console.error("Either add an entry under [Unreleased], or label this PR `no-changelog`."); process.exit(1); } console.log(`OK — ${meaningful.length} CHANGELOG line(s) added.`);