build(changelog): assemble release notes from per-PR changelog fragments #229
Propagate the git show error instead of treating it as an absent Unreleased section. A PR that deletes or renames CHANGELOG.md currently passes this gate because the read failure is ignored and that path does not require a fragment. Both assemble and verify-assembled subsequently fail because the file is missing, blocking releases after the PR merges.
A four-backtick opener followed by a three-backtick line is treated as a closed block, so an unterminated fragment can pass validation and make subsequent changelog sections render as code. The same toggle can reject valid longer-fenced examples or rewrite literal links inside them. Track the opening fence length and close only on a fence at least that long with no trailing content; add regression cases for both valid and unterminated longer-fenced blocks.
<!-- ccr-overview-v2 -->
🟡 Changes recommended
Incorrect handling of longer code fences can corrupt changelog rendering, while ignored git show errors allow changelog deletion or renaming to pass validation and later block releases.
<details open>
<summary><strong>2 open issues</strong></summary>
</details>
<details>
<summary><strong>What changed in this PR</strong></summary>
Moves unreleased notes into per-PR changelog fragments to reduce merge conflicts, with tooling to assemble them into CHANGELOG.md before a release.
Changes:
| File | Description |
| ---- | ----------- |
| hack/changelog/main.go | Defines the changelog CLI commands. |
| hack/changelog/fragment.go | Parses fragments, rewrites links, and renders sections. |
| hack/changelog/fragment_test.go | Tests fragment validation and ordering. |
| hack/changelog/check.go | Checks public-contract changes for fragments. |
| hack/changelog/check_test.go | Tests the pull-request gate and CLI errors. |
| hack/changelog/assemble.go | Assembles release sections and checks for pending fragments. |
| hack/changelog/assemble_test.go | Tests assembly, refusals, and release verification. |
| CONTRIBUTING.md | Documents fragment and release procedures. |
| changelog/unreleased/verified-approver.md | Migrates verified-approver feature notes. |
| changelog/unreleased/verified-approver-compat.md | Migrates approver compatibility notes. |
| changelog/unreleased/tool-policy.md | Migrates tool-policy feature notes. |
| changelog/unreleased/tool-policy-compat.md | Migrates tool-policy compatibility notes. |
| changelog/unreleased/substrate-kind-example.md | Migrates example and verification feature notes. |
| changelog/unreleased/substrate-kind-example-fixed.md | Migrates example, replay, and logging fixes. |
| changelog/unreleased/substrate-fork-capture-refusal.md | Migrates fork-refusal compatibility notes. |
| changelog/unreleased/err-missing-model.md | Migrates missing-model error notes. |
| changelog/unreleased/create-harness.md | Migrates harness-creation feature notes. |
| changelog/unreleased/create-harness-compat.md | Migrates harness-creation compatibility notes. |
| changelog/unreleased/allocation-ownership.md | Migrates allocation-ownership feature notes. |
| changelog/unreleased/allocation-ownership-compat.md | Migrates allocation migration requirements. |
| changelog/unreleased/.gitkeep | Preserves the empty fragment directory after assembly. |
| changelog/README.md | Defines fragment format, requirements, and assembly steps. |
| CHANGELOG.md | Replaces Unreleased entries with links to fragments. |
| .github/workflows/release.yml | Blocks publishing while fragments remain unassembled. |
| .github/workflows/changelog.yml | Adds the fragment gate with label-triggered reruns. |
| .github/copilot-instructions.md | Updates review guidance to require fragments. |
</details>
<sub>Review effort: Balanced</sub>
Fixed: the check now fails when CHANGELOG.md is missing or not a file at head, and a git failure reading it exits 2 instead of passing. The new TestCheck cases (deleting, renaming, or replacing CHANGELOG.md with a directory or symlink) and TestCheckChangelogReadError cover it.
Fixed: the validator now tracks the opening fence's character and length, closes only on a fence of the same character that is at least as long with nothing after it, and handles tilde fences too. The regression cases are in TestParseFragment, starting with "shorter fence does not close a longer one" and "longer fence holds a shorter one".
Could this force-add the Finder fixture? With a global .DS_Store ignore, git add -A leaves it out and go test -race ./hack/changelog/... fails committed_Finder_metadata_fails.
Reference-style links pass validation but keep their fragment-relative path after assembly. [guide]: ../../docs/allocation-ownership.md then points outside the repo. Could we reject these and ask for inline links?
Approved these changes.
Done: the test repo commits with git add -A --force, so a global excludes file no longer drops the fixture. Passes with .DS_Store in either core.excludesFile or ~/.config/git/ignore.
Done. Fragments must use inline links now: the check refuses reference-style definitions, since a label applies to all of CHANGELOG.md and could link text in another fragment, and any other link form assembly can't rewrite (HTML href/src, angle-bracket targets, titles). changelog/README.md states the rule.
Footnote labels need the same isolation as reference-style links. Two valid fragments can each use [^1] and define [^1]: ..., which this parser explicitly permits. After assembly concatenates them into one document, both references share a label, so at least one entry displays the wrong note. Namespace footnote labels and references by fragment name, or reject footnote definitions along with reference-style link definitions.
A fragment containing - Entry. followed by a blank line and <!-- draft passes validation, but its unterminated HTML comment hides subsequent entries and release sections after assembly. Assembly deletes the fragment and verify-assembled succeeds despite the damaged rendering. Require HTML comments outside code to close within the fragment, or reject them, and add an assembly regression case.
A link such as [related change](other.md) passes validation and resolves while the fragments exist, but this rewrites it to changelog/unreleased/other.md and assemble then deletes that target. The resulting CHANGELOG contains a broken link even though both input fragments are valid. Reject links to fragment files, or remap them to persistent locations in the assembled changelog.
Recognize Markdown's optional closing heading hashes instead of comparing the entire source line. The valid heading ## Unreleased ## returns false here, so both check and verify-assembled accept a changelog that still contains Unreleased notes, and assemble leaves that section behind. Normalize the heading syntax before comparing its title, and cover closing hashes and tab-separated headings in the tests.
<!-- ccr-overview-v2 -->
🟡 Changes recommended
Changelog validation and assembly still permit unterminated comments, colliding footnotes, links to deleted fragments, and missed Unreleased headings, allowing damaged output to pass verification.
<details open>
<summary><strong>4 open issues</strong></summary>
</details>
<details>
<summary><strong>2 resolved since last review</strong></summary>
</details>
<sub>Review effort: Balanced</sub>
Fixed in #230 by refusing footnotes in fragments rather than isolating labels: a fragment can't know which others share the assembled document.
Fixed in #230, more strictly than asked: HTML comments outside code are refused entirely, since an author can't know which entry assembly puts after theirs.
Fixed in #230 by refusing links that resolve into changelog/unreleased/ instead of rewriting them, since assembly deletes the targets.
gambtho
aramase
Every pull request that adds an Unreleased entry edits the same lines of
CHANGELOG.md, so concurrent PRs conflict. This moves release notes into one fragment file per PR and category underchangelog/unreleased/, assembled intoCHANGELOG.mdat release time.hack/changelogwithassemble,verify-assembledandcheck, and a format guide inchangelog/README.md. CONTRIBUTING and the Copilot instructions point to it.CHANGELOG.mdno longer has an Unreleased section.changelogworkflow that fails a PR changing a public contract path without a fragment.Tested:
go test -race ./hack/changelog/,go vet,gofmt,actionlinton both workflows andhack/check-doc-links.pyall pass.assembleon a copy of the branch produces one release section with the same 20 entries as main's Unreleased section, leaves only.gitkeep, and passesverify-assembled.