mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-09 09:26:14 -08:00
* chore(release): author release notes in .changes instead of reconstructing them CHANGELOG.md has been frozen at 0.12.0 since 2023 while the app shipped 0.23.0, semantic-release sat in devDependencies with no config, and the real user-facing notes were a 280-line MDX post written from memory at release time. The gap was never version math — it was authored notes captured while the context is still fresh. Add a `.changes/*.md` note format (type, area, issues, screenshot; no version field, since the release version is chosen deliberately) plus a generator that composes the GitHub release body, the CHANGELOG.md section and a blog-post scaffold from the accumulated notes. Changesets was considered and rejected: it versions multiple published packages, and this repo has exactly one private package. Its `version` step would also rewrite CHANGELOG.md into a flatter format than the blog post and fight the deliberate, updater-constrained version choice. - hand-rolled frontmatter parser over a YAML engine: the schema is closed, so it can reject unknown keys, which is what catches typos - PR numbers are resolved from the commit that added the note, never written by the author - MDX-significant characters in note bodies are escaped so a stray `<` cannot break the website build - blog scaffold ships `draft: true` with explicit TODO headings; the prose is editorial work, only the inventory is mechanical - revive CHANGELOG.md with an honest pointer for 0.13.0-0.23.0 rather than fabricating the missing history - drop the five unused semantic-release/conventional-changelog packages Docs: `.changes/README.md`, plus a "Release Notes For User-Visible Changes" section mirrored in CLAUDE.md and AGENTS.md, and a PR template checkbox for contributors who never read either. Tests: 26 unit tests in tools/release/release-notes.test.mjs covering parsing, validation, grouping and all three renderers. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * fix(release): default the notes version to package.json and harden alt escaping Review follow-ups on the release-notes generator. - `--version` now defaults to the root package.json version, so the `release🎶*` package scripts run bare instead of failing on a missing argument. Bumping package.json is the deliberate act that starts a release, which makes it the right single source of truth; `--version` remains as an override for dry runs before the bump. The notice goes to stderr so `--format github` keeps a pipeable stdout. - Escape backslashes before apostrophes when building the MDX `alt` string literal. A note body ending in a backslash previously produced an unterminated string and would have broken the website build. - Document that release posts are one per minor version, in the slug helper, the overwrite error, and `.changes/README.md` — a patch release edits the existing post rather than creating a second one. Tests: +1 regression test for the alt escaping, verified to fail without the fix (27 total, all passing). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * feat(ci): put authored notes into the tag release body, fail-closed Wires the .changes pipeline into the release workflow (Codex review P1 on #1256). Calling the generator from the tag build cannot work — --consume deletes .changes/ before the tag exists — so the tag build reads what the generator already wrote: release-meta now fills BODY from the CHANGELOG.md section matching the tag's version via tools/release/extract-changelog-section.mjs. generate_release_notes stays on, so GitHub's commit list renders below the authored notes; the existing draft-metadata repair step already concatenates RELEASE_BODY with the generated notes, so the rare duplicate-draft path keeps the same layering unchanged. The extractor exits non-zero when the section is missing or empty, failing the release instead of silently shipping PR-title-only notes. A hotfix tag cut without running release:notes:changelog therefore fails at create-release by design; the error message names the exact commands to run. Tests: 5 new extractor tests (32 total in release-tools, all passing); packaging suite (247) re-run green since build-and-make.yaml is one of its inputs. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * fix(release): escape all regex metacharacters in the changelog extractor CodeQL flagged the version-to-RegExp interpolation in extract-changelog-section.mjs (regex injection + incomplete escaping): only dots were escaped, and while the CLI validates its argument as bare semver before calling, the exported extractSection() carries no such guarantee on its own. Escape the full metacharacter set so no caller can inject pattern syntax, with tests covering wildcard dots, alternation, `.*` and backslashes. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * fix(release): make changelog generation idempotent per version Codex review P2 on #1256: rerunning `release:notes:changelog` for the same version — the normal move after correcting a note before --consume — prepended a second section instead of replacing the first, leaving duplicate release entries. Extract the marker insertion into upsertChangelogSection(): it removes any existing section for the version, then rebuilds around the marker rather than string-replacing into it, so the blank-line count on both sides stays exact on both the fresh-insert and replace paths. The CLI reports when a section was replaced. Tests: 4 new cases (insert, replace-not-duplicate, neighbours untouched, missing marker); 37 total passing. End-to-end rerun verified: one heading, latest date wins, extractor output unchanged. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
261 lines
7.6 KiB
JavaScript
261 lines
7.6 KiB
JavaScript
/**
|
|
* Parsing and validation for `.changes/*.md` release notes.
|
|
*
|
|
* One file per user-visible change, written by the PR author while the
|
|
* context is still fresh. The generator (build-release-notes.mjs) turns the
|
|
* accumulated files into the GitHub release body, the CHANGELOG.md section,
|
|
* and the website blog scaffold.
|
|
*
|
|
* Deliberately dependency-free: a hand-rolled parser for this tiny, closed
|
|
* schema is more predictable than a YAML engine, and it can reject unknown
|
|
* keys — which is what catches agent typos.
|
|
*/
|
|
|
|
import { readdirSync, readFileSync } from 'node:fs';
|
|
import path from 'node:path';
|
|
|
|
export const REPO_URL = 'https://github.com/4gray/iptvnator';
|
|
|
|
/** Render order. `internal` is last and is excluded from user-facing output. */
|
|
export const NOTE_TYPES = ['breaking', 'feature', 'fix', 'perf', 'internal'];
|
|
|
|
export const TYPE_HEADINGS = {
|
|
breaking: 'Breaking changes',
|
|
feature: 'Features',
|
|
fix: 'Fixes',
|
|
perf: 'Performance',
|
|
internal: 'Internal',
|
|
};
|
|
|
|
const KNOWN_KEYS = new Set(['type', 'area', 'issues', 'screenshot']);
|
|
const SLUG_PATTERN = /^[a-z0-9][a-z0-9-]*$/;
|
|
const DELIMITER = '---';
|
|
|
|
/** Keeps entries to a sentence or three; essays belong in the blog post. */
|
|
const MAX_BODY_LENGTH = 400;
|
|
|
|
/**
|
|
* Splits a note into its frontmatter lines and body.
|
|
*
|
|
* @param {string} content raw file content
|
|
* @returns {{ frontmatterLines: string[], body: string }}
|
|
*/
|
|
function splitFrontmatter(content) {
|
|
const lines = content.replace(/\r\n/g, '\n').split('\n');
|
|
|
|
if (lines[0]?.trim() !== DELIMITER) {
|
|
throw new Error('missing opening `---` frontmatter delimiter');
|
|
}
|
|
|
|
const closingIndex = lines.findIndex(
|
|
(line, index) => index > 0 && line.trim() === DELIMITER
|
|
);
|
|
|
|
if (closingIndex === -1) {
|
|
throw new Error('missing closing `---` frontmatter delimiter');
|
|
}
|
|
|
|
return {
|
|
frontmatterLines: lines.slice(1, closingIndex),
|
|
body: lines.slice(closingIndex + 1).join('\n').trim(),
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Parses a single `key: value` frontmatter line.
|
|
*
|
|
* Trailing `# comment` text is stripped: no value in this schema (enum slug,
|
|
* area slug, issue numbers) can legitimately contain `#`, and the documented
|
|
* examples carry explanatory comments.
|
|
*
|
|
* @param {string} line
|
|
* @returns {[string, string] | null} key/value pair, or null for blank lines
|
|
*/
|
|
function parseFrontmatterLine(line) {
|
|
const withoutComment = line.replace(/\s+#.*$/, '').trim();
|
|
|
|
if (!withoutComment) {
|
|
return null;
|
|
}
|
|
|
|
const separatorIndex = withoutComment.indexOf(':');
|
|
|
|
if (separatorIndex === -1) {
|
|
throw new Error(`frontmatter line is not \`key: value\`: "${line.trim()}"`);
|
|
}
|
|
|
|
const key = withoutComment.slice(0, separatorIndex).trim();
|
|
const value = withoutComment
|
|
.slice(separatorIndex + 1)
|
|
.trim()
|
|
.replace(/^['"]|['"]$/g, '');
|
|
|
|
return [key, value];
|
|
}
|
|
|
|
/**
|
|
* @param {string} value e.g. `[1187, 1188]` or `1187`
|
|
* @returns {number[]}
|
|
*/
|
|
function parseIssueList(value) {
|
|
const inner = value.startsWith('[') ? value.replace(/^\[|\]$/g, '') : value;
|
|
|
|
return inner
|
|
.split(',')
|
|
.map((entry) => entry.trim().replace(/^#/, ''))
|
|
.filter(Boolean)
|
|
.map((entry) => Number(entry));
|
|
}
|
|
|
|
/**
|
|
* Parses a note file into a structured record. Shape errors throw; semantic
|
|
* errors are reported by validateNote() so a run can list every problem at
|
|
* once instead of failing on the first one.
|
|
*
|
|
* @param {string} content
|
|
* @param {string} sourcePath path used in error messages and PR resolution
|
|
* @returns {{ type: string, area: string, issues: number[], screenshot: string | null, body: string, sourcePath: string }}
|
|
*/
|
|
export function parseNote(content, sourcePath) {
|
|
const { frontmatterLines, body } = splitFrontmatter(content);
|
|
const fields = new Map();
|
|
|
|
for (const line of frontmatterLines) {
|
|
const parsed = parseFrontmatterLine(line);
|
|
|
|
if (!parsed) {
|
|
continue;
|
|
}
|
|
|
|
const [key, value] = parsed;
|
|
|
|
if (fields.has(key)) {
|
|
throw new Error(`duplicate frontmatter key: \`${key}\``);
|
|
}
|
|
|
|
fields.set(key, value);
|
|
}
|
|
|
|
return {
|
|
type: fields.get('type') ?? '',
|
|
area: fields.get('area') ?? '',
|
|
issues: fields.has('issues') ? parseIssueList(fields.get('issues')) : [],
|
|
screenshot: fields.get('screenshot') ?? null,
|
|
unknownKeys: [...fields.keys()].filter((key) => !KNOWN_KEYS.has(key)),
|
|
body,
|
|
sourcePath,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* @param {ReturnType<typeof parseNote>} note
|
|
* @returns {string[]} human-readable problems, empty when the note is valid
|
|
*/
|
|
export function validateNote(note) {
|
|
const errors = [];
|
|
|
|
if (!note.type) {
|
|
errors.push('`type` is required');
|
|
} else if (!NOTE_TYPES.includes(note.type)) {
|
|
errors.push(
|
|
`unknown \`type\`: "${note.type}" (expected one of ${NOTE_TYPES.join(', ')})`
|
|
);
|
|
}
|
|
|
|
if (!note.area) {
|
|
errors.push('`area` is required (use the conventional-commit scope)');
|
|
} else if (!SLUG_PATTERN.test(note.area)) {
|
|
errors.push(`\`area\` must be a lowercase slug, got "${note.area}"`);
|
|
}
|
|
|
|
if (!note.body) {
|
|
errors.push('body is empty — describe the change for a user');
|
|
} else if (note.body.length > MAX_BODY_LENGTH) {
|
|
errors.push(
|
|
`body is ${note.body.length} characters, max ${MAX_BODY_LENGTH} — keep it to a few sentences and put detail in the blog post`
|
|
);
|
|
}
|
|
|
|
for (const issue of note.issues) {
|
|
if (!Number.isInteger(issue) || issue <= 0) {
|
|
errors.push(`\`issues\` must be positive integers, got "${issue}"`);
|
|
}
|
|
}
|
|
|
|
if (note.screenshot !== null && !SLUG_PATTERN.test(note.screenshot)) {
|
|
errors.push(
|
|
`\`screenshot\` must be a lowercase slug from the screenshot manifest, got "${note.screenshot}"`
|
|
);
|
|
}
|
|
|
|
for (const key of note.unknownKeys) {
|
|
errors.push(
|
|
`unknown frontmatter key: \`${key}\` (expected ${[...KNOWN_KEYS].join(', ')})`
|
|
);
|
|
}
|
|
|
|
return errors;
|
|
}
|
|
|
|
/**
|
|
* Reads and parses every note in a directory, sorted by filename so output
|
|
* ordering is stable across machines.
|
|
*
|
|
* @param {string} directory
|
|
* @returns {{ notes: object[], errors: string[] }}
|
|
*/
|
|
export function loadNotes(directory) {
|
|
let entries = [];
|
|
|
|
try {
|
|
entries = readdirSync(directory);
|
|
} catch (error) {
|
|
if (error.code === 'ENOENT') {
|
|
return { notes: [], errors: [] };
|
|
}
|
|
|
|
throw error;
|
|
}
|
|
|
|
const files = entries
|
|
.filter((name) => name.endsWith('.md') && name !== 'README.md')
|
|
.sort();
|
|
|
|
const notes = [];
|
|
const errors = [];
|
|
|
|
for (const name of files) {
|
|
const sourcePath = path.join(directory, name);
|
|
|
|
try {
|
|
const note = parseNote(readFileSync(sourcePath, 'utf8'), sourcePath);
|
|
const problems = validateNote(note);
|
|
|
|
if (problems.length > 0) {
|
|
errors.push(...problems.map((problem) => `${name}: ${problem}`));
|
|
continue;
|
|
}
|
|
|
|
notes.push(note);
|
|
} catch (error) {
|
|
errors.push(`${name}: ${error.message}`);
|
|
}
|
|
}
|
|
|
|
return { notes, errors };
|
|
}
|
|
|
|
/**
|
|
* Groups notes by type in render order, dropping empty groups.
|
|
*
|
|
* @param {object[]} notes
|
|
* @returns {{ type: string, heading: string, notes: object[] }[]}
|
|
*/
|
|
export function groupNotes(notes) {
|
|
return NOTE_TYPES.map((type) => ({
|
|
type,
|
|
heading: TYPE_HEADINGS[type],
|
|
notes: notes.filter((note) => note.type === type),
|
|
})).filter((group) => group.notes.length > 0);
|
|
}
|