Skip to content

ci: enforce the changelog policy instead of trusting habit - #638

Merged
scttfrdmn merged 3 commits into
mainfrom
feat/changelog-gate
Oct 3, 2026
Merged

scttfrdmn merged 3 commits into
mainfrom
feat/changelog-gate

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

CLAUDE.md requires a changelog entry under ## [Unreleased] in the same PR as any user-facing change, and the release ritual promotes that section verbatim. Nothing checked either half, and both broke within a week.

What actually went wrong

#627 merged with no entry at all. It surfaced at the next release, which hit an empty [Unreleased] and had to reconstruct the entries from the diff at tag time — precisely when you least want to be reverse-engineering what a change did.

Three PRs each inserted their own ### Added at the top of [Unreleased]. That merges cleanly for git and badly for Keep a Changelog: the section ended up with duplicate ### Added and ### Fixed headings, consolidated by hand at release time. Then it happened a second time, which is what prompted this.

Two halves, because they need different inputs

where runs on
format — [Unreleased] has no duplicate groups, no unknown group names, no entries outside a group; every single-version release has a compare link changelog_test.go push, PR, and locally via go test ./...
presence — a PR changing non-test Go source must touch CHANGELOG.md CI step PR only (needs the base branch)

The presence check exempts test-only, CI-only and docs-gen/-only changes — there's nothing user-facing to describe. Verified against six path shapes:

code + changelog        -> PASS
code, no changelog      -> FAIL (the #627 case)
test-only               -> SKIP
CI-only                 -> SKIP
generated docs only     -> SKIP
hand docs only          -> SKIP

Its failure message says what to write, which group, and why the gate exists — including the "if this genuinely has no user-visible effect, add the line anyway, it costs less than the archaeology" case.

A scoping decision worth reviewing

I first wrote the format checks over the whole file. They reported duplicate groups in roughly a dozen shipped releases, plus two invented group names (### CI, ### Changed (internal refactors — no behavior change)). So this has been happening for a long time, not just in the three PRs that prompted the gate.

Gating frozen history would force either a mass rewrite of released notes — noisy, and those sections describe what actually shipped — or a permanently-red test. A permanently-red test gets disabled, which is worse than no test. So the format checks are scoped to [Unreleased]: the one section still being edited, and the only place the problem creates work.

Also: the compare-link check skips range headings like [0.36.0 – 0.36.13], which summarise a span and have no single diff to point at. Demanding a link there would be a false positive, and false positives are how a gate loses its authority.

Verification

Every check was confirmed to fail on the real mistake it describes, not just to pass today:

duplicate group in [Unreleased]  -> "has `### Added` more than once"
invented group name              -> "unknown group `### Improvements`"
entry with no group              -> "has an entry before any `###` group"
release without a compare link   -> "section [0.116.0] has no compare link"
missing [Unreleased]             -> "must keep a `## [Unreleased]` section"

gofmt · go vet · go build · go test ./... green · make check-docs clean · workflow YAML parses and the step is correctly if: github.event_name == 'pull_request'.

Note

This PR is test + CI + docs only, so it skips its own presence gate — correctly, by the rule it just added. I added a changelog entry anyway, since contributors will notice the behaviour change.

The policy is suite-wide (CLAUDE.md in every repo), so this is the reference implementation; propagating it to lagotto/libs/truffle/mcp is a follow-up worth doing, and changelog_test.go is deliberately self-contained enough to copy.

Suggested bump: PATCH — contributor-facing only, no runtime change.

CLAUDE.md requires a CHANGELOG entry under [Unreleased] in the SAME PR as any
user-facing change, and the release ritual promotes that section verbatim. Nothing
checked either half, and both broke within a week.

#627 merged with no entry at all. It surfaced at the next release, which hit an EMPTY
[Unreleased] and had to reconstruct the entries from the diff at tag time — precisely
when you least want to be reverse-engineering what a change did.

Separately, three PRs each inserted their own '### Added' at the top of [Unreleased].
That merges cleanly for git and badly for Keep a Changelog: the section ended up with
duplicate '### Added' and '### Fixed' headings, consolidated by hand at release time.
Then it happened a second time.

Two halves, because they need different things:

- changelog_test.go (plain Go test, runs on push and locally): [Unreleased] has no
  duplicate groups, no unknown group names, no entries outside a group; and every
  single-version release heading has a compare link.
- A CI step (PR-only, since it needs the base branch): a PR that changes non-test Go
  source must touch CHANGELOG.md. Test-only, CI-only and docs-gen-only changes are
  exempt — there is nothing user-facing to describe — and the failure message says
  what to write and why the gate exists.

Format checks are scoped to [Unreleased] deliberately. Run over the whole file they
report duplicate groups in roughly a dozen SHIPPED releases and two invented group
names ('### CI', '### Changed (internal refactors — no behavior change)'). Gating
frozen history would force either a mass rewrite of released notes or a permanently
red test, and a permanently red test gets disabled — worse than no test. The job is to
stop new occurrences in the one section still being edited, which is also the only
place the problem creates work.

The compare-link check skips range headings like '[0.36.0 – 0.36.13]', which
summarise a span and have no single diff to point at; demanding a link there would be
a false positive that teaches people to ignore the test.

Each check was verified to fail on the real mistake it describes, and CLAUDE.md now
says the policy is enforced rather than advisory.
1. Shell injection. '${{ github.base_ref }}' interpolated into a run: block is a
   script-injection vector, and Semgrep's run-shell-injection rule blocked the PR —
   correctly. It is now passed via env: and referenced as $BASE_REF, with nothing from
   the github context in the script body.

2. It would have failed EVERY pull request. 'git diff base...HEAD' needs a merge base,
   the checkout is shallow, and a depth-1 fetch has no common ancestor — so the step
   died with 'fatal: origin/main...HEAD: no merge base' (exit 128) before any of the
   logic ran. Not a false positive: a total block on all work, shipped in CI. Caught
   on this PR's own first run.

   Now it deepens the fetch, resolves the merge base explicitly, and diffs from it, so
   the unresolvable case is detectable rather than fatal. When the merge base cannot be
   found (long-lived branch, force-pushed base) it WARNS and passes: a gate must fail
   on a known violation, not on its own inability to measure one.

Both paths verified locally — the normal case computes the right file list and
verdict, and a disconnected history warns and exits 0.
@codecov

codecov Bot commented Oct 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Third attempt at the presence half, and the first that actually runs.

Attempt 1: 'git diff base...HEAD' at fetch depth 1 — died with 'no merge base'
(exit 128) before reaching any logic, which would have failed EVERY pull request.

Attempt 2: deepen main to 100 commits — still no merge base, because the PR branch
is itself fetched at depth 1, so no shared object exists locally. The gate then took
its warn-and-skip fail-safe on every run. That is the worse outcome: it reads as
enforcement while enforcing nothing, which is exactly the defect #624 fixed in the
reaper-coverage check.

Attempt 3: 'gh api repos/{repo}/pulls/{n}/files'. GitHub already knows what the PR
changed; no history needed, nothing to go shallow. All context still arrives via env,
so there is no '${{ }}' in the script body and Semgrep's run-shell-injection rule
stays satisfied.

Validated against three real PRs rather than reasoned about:
  #638 (this one: test + CI + docs)     -> SKIP, correct
  #636 (4 non-test .go + CHANGELOG.md)  -> PASS
  #627 (2 non-test .go, no changelog)   -> FAIL, the PR that prompted all of this

The API-failure and empty-result paths still warn and pass: a gate must fail on a
known violation, not on its own inability to measure one.
@scttfrdmn
scttfrdmn merged commit e1aac7f into main Oct 3, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the feat/changelog-gate branch October 3, 2026 03:19
@scttfrdmn scttfrdmn mentioned this pull request Nov 6, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant