ci: introduce towncrier to generate changelog from fragments#5187
Conversation
Replace manual CHANGELOG.md editing with towncrier fragment-based changelog management. Each PR adds a small text file in .changelog/ instead of editing the changelog directly, eliminating merge conflicts. Changes: - Add towncrier configuration in pyproject.toml with 5 fragment types (added, changed, deprecated, removed, fixed) - Replace sed-based changelog generation in release workflows with towncrier build - Add changelog backport step to patch release workflow - Update CI to use towncrier check for fragment validation - Add pre-commit check via scripts/check_changelog_fragment.py - Add tox environments: changelog (preview) and new-changelog (create) - Add contributor documentation in CONTRIBUTING.md - Convert existing unreleased entries to fragment files - Add custom Jinja2 template for changelog output Based on the proof-of-concept in open-telemetry#4382 by @emdneto. Co-authored-by: Emídio Neto <9735060+emdneto@users.noreply.github.com> Assisted-by: Claude Opus 4.6
6d7185f to
f664c36
Compare
Existing ## Unreleased entries stay in CHANGELOG.md — the towncrier marker is placed above them. Fragment migration can happen at the next release. Assisted-by: Claude Opus 4.6
- Regenerate misc.yml for new changelog/new-changelog tox envs - Update uv.lock for towncrier dependency - Apply ruff formatting to check_changelog_fragment.py Assisted-by: Claude Opus 4.6
emdneto
left a comment
There was a problem hiding this comment.
Awesome. Thanks for resurrecting this 👍🏻 Left some comments
|
Awesome thanks Mike! I think we discussed it on slack but I can't remember the pro/cons of town crier vs chloggen. |
Per review feedback from @emdneto: - Remove changelog/new-changelog tox envs (they generate CI jobs) - Remove pre-commit hook (not all PRs need changelog, PR number unknown at commit time) - Simplify CONTRIBUTING.md to document direct file creation - Regenerate misc.yml Assisted-by: Claude Opus 4.6
Both tools solve the same problem in a similar way - they replace a single CHANGELOG.md that causes merge conflicts with per-PR fragment files that get compiled at release time.
I suggested Towncrier because it's built for use with with python projects, chloggen is a custom OTel tool used by the collector and requires a go binary.
I'm not against chloggen, they are very similar. chloggen would tie back into more OTel and has a stricter fragment strucure which would be nice. |
emdneto
left a comment
There was a problem hiding this comment.
I'm really happy to see that we now have an agreement on this!
My suggestion is we wait for the next release and prioritize merging this ASAP so we can start with a very fresh changelog, and you won't need to map every already merged PR to an entry here. Also, I believe we need at least the same setup for -contrib so the contributor experience is the same in both repos.
Per review feedback from @aabmass. Assisted-by: Claude Opus 4.6
…/towncrier-review
Assisted-by: Claude Opus 4.6
Remove references to manual ## Unreleased header requirements. Note that towncrier eliminates changelog merge conflicts during backports. Assisted-by: Claude Opus 4.6
Per feedback from @xrmx — no need to explain the old problem since it's already solved. Assisted-by: Claude Opus 4.6
Description
Replace manual
CHANGELOG.mdediting with towncrier fragment-based changelog management. Each PR adds a small text file in.changelog/instead of editing the changelog directly, eliminating merge conflicts.This supersedes #4382 (PoC by @emdneto) — builds on that foundation with updates for current
main, additional features informed by how pip, pytest, attrs, and Twisted use towncrier.Fixes #4307
Fixes #4309
What changed
Core towncrier setup:
pyproject.toml: towncrier config with 5 fragment types (added,changed,deprecated,removed,fixed), pinnedtowncrier==25.8.0in CIscripts/changelog_template.j2: custom Jinja2 template matching existing changelog formatCHANGELOG.md:<!-- changelog start -->marker added above existing## Unreleasedsection; existing entries preserved as-is and can be migrated to fragments at the next releaseCI & workflows:
.github/workflows/changelog.yml: rejects direct CHANGELOG.md edits, validates fragments exist viagit diff, previews rendered changelog withtowncrier build --draft.github/workflows/prepare-release-branch.yml:sedreplaced withtowncrier build.github/workflows/prepare-patch-release.yml: same + adds backport step to sync changelog to mainDocumentation:
CONTRIBUTING.md: changelog section with style guidance (imperative tone, package prefix, <80 chars)RELEASING.md: updated backporting sectionImprovements over #4382
deprecatedandremovedcategories (original only had added/changed/fixed)towncrieradded to dev dependency groupotelbot[bot]main(original PR was months stale)Type of change
How Has This Been Tested?
towncrier build --draft --version "Unreleased"— verified fragment parsing and categorized outputtowncrier build --yes --version "1.42.0/0.63b0"— verified full build inserts into CHANGELOG.md at marker, deletes fragmentsDoes This PR Require a Contrib Repo Change?
Checklist: