ci: introduce towncrier to generate changelog from fragments#5187
ci: introduce towncrier to generate changelog from fragments#5187MikeGoldsmith wants to merge 8 commits into
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.
| echo " tox -e new-changelog -- ${{ github.event.pull_request.number }} TYPE \"Description\"" | ||
| echo "where TYPE is one of: added, changed, deprecated, removed, fixed" | ||
| echo "" | ||
| echo "Or add the \"Skip Changelog\" label if this job should be skipped." |
There was a problem hiding this comment.
Can you add a new step here to build and print the changelog? Just for ourselves to see when we want, and to save time from running the command locally to see how it renders?
Per review feedback from @aabmass. Assisted-by: Claude Opus 4.6
…/towncrier-review
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)scripts/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: usestowncrier check(per Twisted's approach) instead of grepping for CHANGELOG changes; rejects direct CHANGELOG.md edits; suggeststox -e new-changelogon failure.github/workflows/prepare-release-branch.yml:sedreplaced withtowncrier build.github/workflows/prepare-patch-release.yml: same + adds backport step to sync changelog to mainDeveloper experience:
tox -e new-changelog -- PR_NUMBER TYPE "Description"to create a fragmenttox -e changelogto preview generated changelogtox -e precommitchecks for missing fragments viascripts/check_changelog_fragment.pyCONTRIBUTING.md: changelog section with style guidanceImprovements over #4382
deprecatedandremovedcategories (original only had added/changed/fixed)towncrier check(Twisted's approach) instead of manual shell script for CI validationtowncrieradded 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 fragmentstowncrier check --compare-with upstream/main— verified branch-level fragment detectionscripts/check_changelog_fragment.pylogic for main vs feature branch casesDoes This PR Require a Contrib Repo Change?
Checklist: