Skip to content

introducing towncrier to generate changelog from fragments#4382

Closed
emdneto wants to merge 1 commit into
open-telemetry:mainfrom
emdneto:towncrier-changelog
Closed

introducing towncrier to generate changelog from fragments#4382
emdneto wants to merge 1 commit into
open-telemetry:mainfrom
emdneto:towncrier-changelog

Conversation

@emdneto

@emdneto emdneto commented Jan 9, 2025

Copy link
Copy Markdown
Member

Fix #4307
Hopefully, also Fix #4309

Description

Towncrier is a tool adopted in some well-known python projects to generate release notes from fragments. In otel-python we are always dealing with CHANGELOG.mdconflicts during rebases, specially after releases. So, this can help us with it since now we have a changelog entry for each PR in the .changelog directory. This is similar to chloggen adopted in opentelemetry-collector.

How it works:

  1. Creating a Changelog Fragment:

    • Contributors add a changelog entry under the .changelog directory in the format <PR_NUMBER>.<CATEGORY>, where <CATEGORY> can be added, changed, fixed, etc.
    • For example, a PR #1234 fixing a bug would create a file named ./.changelog/1234.fixed containing a short description of the change.
    • Every PR should include at least one changelog fragment unless explicitly exempted (e.g., PR's with Skip Changelog).
  2. Releasing:

    • During the release, we run towncrier build --yes. This command:
      • Gathers all fragments in the .changelog directory.
      • Renders the release notes.
      • Updates CHANGELOG.md with the generated content.

The configuration is pretty simple and we can customize the changelog as we want using jinja templates and also customize the category names.

I tested the changes using https://github.com/nektos/act: act -W '.github/workflows/changelog.yml' --eventpath event.json

{
    "act": true,
    "env": {
        "GITHUB_REF_NAME": "main"
    },
    "pull_request": {
      "number": 4371,
      "head": {
        "ref": "xyz",
        "sha": "1234567890abcdef1234567890abcdef12345678"
      },
      "base": {
        "ref": "main"
      },
      "user": {
        "login": "opentelemetrybot"
      }
    }
  }

If you checkout this branch and run towncrier build --yes --version=1.30.0/0.51b0
The generated changelog for this branch will be:

## Version 1.30.0/0.51b0 (2025-01-09)

### Changed

- sdk: don't log or print warnings when the SDK has been disabled
  ([#4371](https://github.com/open-telemetry/opentelemetry-python/pull/4371))

### Added

- Add Python 3.13 support
  ([#4353](https://github.com/open-telemetry/opentelemetry-python/pull/4353))
- Add `attributes` field in `metrics.get_meter` wrapper function
  ([#4364](https://github.com/open-telemetry/opentelemetry-python/pull/4364))

@emdneto emdneto added Skip Changelog PRs that do not require a CHANGELOG.md entry and removed Skip Changelog PRs that do not require a CHANGELOG.md entry labels Jan 9, 2025
@emdneto
emdneto marked this pull request as ready for review January 9, 2025 13:37
@emdneto
emdneto requested a review from a team as a code owner January 9, 2025 13:37
--head $branch \
--base $GITHUB_REF_NAME

- uses: actions/checkout@v4

@emdneto emdneto Jan 9, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably leave this for another PR to not introduce too many changes at this moment

@emdneto emdneto added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Jan 9, 2025
@github-actions

Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment.
If you're still working on this, please add a comment or push new commits.

@github-actions github-actions Bot added the Stale label Mar 12, 2026
@github-actions

Copy link
Copy Markdown

This PR has been closed due to inactivity. Please reopen if you would like to continue working on it.

@github-actions github-actions Bot closed this Mar 26, 2026
@github-project-automation github-project-automation Bot moved this from Ready for review to Done in Python PR digest Mar 26, 2026
@MikeGoldsmith MikeGoldsmith reopened this May 8, 2026
MikeGoldsmith added a commit to MikeGoldsmith/opentelemetry-python that referenced this pull request May 8, 2026
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 <[email protected]>
Assisted-by: Claude Opus 4.6
@emdneto emdneto closed this May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Skip Changelog PRs that do not require a CHANGELOG.md entry

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Backport workflow as part of releasing is broken Patch release workflow doesn’t backport the patch changelog entry to main branch

2 participants