Repository navigation
ci: enforce the changelog policy instead of trusting habit - #638
Merged
Merged
Conversation
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 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CLAUDE.mdrequires 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
### Addedat the top of[Unreleased]. That merges cleanly for git and badly for Keep a Changelog: the section ended up with duplicate### Addedand### Fixedheadings, consolidated by hand at release time. Then it happened a second time, which is what prompted this.Two halves, because they need different inputs
[Unreleased]has no duplicate groups, no unknown group names, no entries outside a group; every single-version release has a compare linkchangelog_test.gogo test ./...CHANGELOG.mdThe presence check exempts test-only, CI-only and
docs-gen/-only changes — there's nothing user-facing to describe. Verified against six path shapes: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:
gofmt·go vet·go build·go test ./...green ·make check-docsclean · workflow YAML parses and the step is correctlyif: 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.mdin every repo), so this is the reference implementation; propagating it to lagotto/libs/truffle/mcp is a follow-up worth doing, andchangelog_test.gois deliberately self-contained enough to copy.Suggested bump: PATCH — contributor-facing only, no runtime change.