Skip to content

Commit 1cc495c

Browse files
committed
introducing towncrier to generate changelog from fragments
Signed-off-by: emdneto <[email protected]>
1 parent 29aad2e commit 1cc495c

File tree

10 files changed

+131
-50
lines changed

10 files changed

+131
-50
lines changed

.changelog/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!.gitignore

.changelog/4353.added

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add Python 3.13 support

.changelog/4364.added

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add `attributes` field in `metrics.get_meter` wrapper function

.changelog/4371.changed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sdk: don't log or print warnings when the SDK has been disabled

.github/workflows/changelog.yml

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,48 @@ on:
1313
jobs:
1414
changelog:
1515
runs-on: ubuntu-latest
16-
if: |
17-
!contains(github.event.pull_request.labels.*.name, 'Skip Changelog')
18-
&& github.actor != 'opentelemetrybot'
19-
2016
steps:
21-
- uses: actions/checkout@v4
17+
- name: Checkout repo @ SHA - ${{ github.sha }}
18+
uses: actions/checkout@v4
19+
20+
- name: Fetch base branch - ${{ github.base_ref }}
21+
run: git fetch origin ${{ github.base_ref }} --depth=1
2222

23-
- name: Check for CHANGELOG changes
23+
- name: Ensure no changes to CHANGELOG.md
24+
if: |
25+
!contains(github.event.pull_request.labels.*.name, 'Skip Changelog')
26+
&& github.event.pull_request.user.login != 'opentelemetrybot'
2427
run: |
25-
# Only the latest commit of the feature branch is available
26-
# automatically. To diff with the base branch, we need to
27-
# fetch that too (and we only need its latest commit).
28-
git fetch origin ${{ github.base_ref }} --depth=1
29-
if [[ $(git diff --name-only FETCH_HEAD | grep CHANGELOG) ]]
28+
# If there are any changes to CHANGELOG.md, fail.
29+
if [[ $(git diff --name-only FETCH_HEAD -- 'CHANGELOG.md') ]]
3030
then
31-
echo "A CHANGELOG was modified. Looks good!"
31+
echo "CHANGELOG.md should not be directly modified."
32+
echo "Please add a entry file to the .changelog/ directory instead."
33+
echo "See CONTRIBUTING.md for more details."
34+
echo "Alternately, add the \"Skip Changelog\" label if this job should be skipped."
35+
false
3236
else
33-
echo "No CHANGELOG was modified."
34-
echo "Please add a CHANGELOG entry, or add the \"Skip Changelog\" label if not required."
37+
echo "CHANGELOG.md was not modified."
38+
fi
39+
40+
- name: Ensure changelog entry addition
41+
if: |
42+
!contains(github.event.pull_request.labels.*.name, 'Skip Changelog')
43+
&& github.event.pull_request.user.login != 'opentelemetrybot'
44+
run: |
45+
if [[ -z $(git diff --diff-filter=A --name-only FETCH_HEAD -- './.changelog/${{ github.event.pull_request.number }}*') ]]
46+
then
47+
echo "No changelog entry was added to the ./.changelog/ directory."
48+
echo "Please add a changelog entry file to the ./.changelog/ directory."
49+
echo "See CONTRIBUTING.md for more details."
50+
echo "Alternately, add the \"Skip Changelog\" label if this job should be skipped."
3551
false
52+
else
53+
echo "A changelog entry was added to the ./.changelog/ directory."
3654
fi
55+
56+
- name: Install towncrier
57+
run: pip install towncrier
58+
59+
- name: Generate changelog
60+
run: towncrier build --draft --version "Unreleased"

.github/workflows/prepare-patch-release.yml

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,14 @@ jobs:
99
- uses: actions/checkout@v4
1010

1111
- name: Install toml
12-
run: pip install toml
12+
run: pip install toml towncrier
1313

1414
- run: |
1515
if [[ ! $GITHUB_REF_NAME =~ ^release/v[0-9]+\.[0-9]+\.x-0\.[0-9]+bx$ ]]; then
1616
echo this workflow should only be run against long-term release branches
1717
exit 1
1818
fi
1919
20-
if ! grep --quiet "^## Unreleased$" CHANGELOG.md; then
21-
echo the change log is missing an \"Unreleased\" section
22-
exit 1
23-
fi
24-
2520
- name: Set environment variables
2621
run: |
2722
stable_version=$(./scripts/eachdist.py version --mode stable)
@@ -56,10 +51,8 @@ jobs:
5651
- name: Update version
5752
run: .github/scripts/update-version-patch.sh $STABLE_VERSION $UNSTABLE_VERSION $STABLE_VERSION_PREV $UNSTABLE_VERSION_PREV
5853

59-
- name: Update the change log with the approximate release date
60-
run: |
61-
date=$(date "+%Y-%m-%d")
62-
sed -Ei "s/^## Unreleased$/## Version ${STABLE_VERSION}\/${UNSTABLE_VERSION} ($date)/" CHANGELOG.md
54+
- name: Generate changelog
55+
run: towncrier build --yes --version "$STABLE_VERSION/$UNSTABLE_VERSION"
6356

6457
- name: Use CLA approved github bot
6558
run: .github/scripts/use-cla-approved-github-bot.sh
@@ -78,3 +71,32 @@ jobs:
7871
--body "$message." \
7972
--head $branch \
8073
--base $GITHUB_REF_NAME
74+
75+
- uses: actions/checkout@v4
76+
with:
77+
ref: main
78+
79+
- name: Use CLA approved github bot
80+
run: .github/scripts/use-cla-approved-github-bot.sh
81+
82+
- name: Backport patch release changelog to main
83+
env:
84+
# not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
85+
GITHUB_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
86+
run: |
87+
release_branch="opentelemetrybot/prepare-release-${STABLE_VERSION}-${UNSTABLE_VERSION}"
88+
message="Backport ${STABLE_VERSION}/${UNSTABLE_VERSION} changelog"
89+
body="Backport \`${STABLE_VERSION}/${UNSTABLE_VERSION}\` changelog"
90+
branch="opentelemetrybot/backport-changelog-from-${STABLE_VERSION}-${UNSTABLE_VERSION}"
91+
92+
git fetch origin $release_branch
93+
94+
# Copy the updated CHANGELOG.md from the release branch
95+
git checkout $release_branch -- CHANGELOG.md
96+
git commit -m "$message"
97+
98+
git push origin HEAD:$branch
99+
gh pr create --title "$message" \
100+
--body "$body" \
101+
--head $branch \
102+
--base main

.github/workflows/prepare-release-branch.yml

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ jobs:
2424
exit 1
2525
fi
2626
27-
if ! grep --quiet "^## Unreleased$" CHANGELOG.md; then
28-
echo the change log is missing an \"Unreleased\" section
29-
exit 1
30-
fi
31-
3227
if [[ ! -z $PRERELEASE_VERSION ]]; then
3328
stable_version=$(./scripts/eachdist.py version --mode stable)
3429
stable_version=${stable_version//.dev/}
@@ -44,8 +39,8 @@ jobs:
4439
steps:
4540
- uses: actions/checkout@v4
4641

47-
- name: Install toml
48-
run: pip install toml
42+
- name: Install deps
43+
run: pip install toml towncrier
4944

5045
- name: Create release branch
5146
env:
@@ -82,10 +77,8 @@ jobs:
8277
- name: Update version
8378
run: .github/scripts/update-version.sh $STABLE_VERSION $UNSTABLE_VERSION
8479

85-
- name: Update the change log with the approximate release date
86-
run: |
87-
date=$(date "+%Y-%m-%d")
88-
sed -Ei "s/^## Unreleased$/## Version ${STABLE_VERSION}\/${UNSTABLE_VERSION} ($date)/" CHANGELOG.md
80+
- name: Generate changelog
81+
run: towncrier build --yes --version "$STABLE_VERSION/$UNSTABLE_VERSION"
8982

9083
- name: Use CLA approved github bot
9184
run: .github/scripts/use-cla-approved-github-bot.sh
@@ -111,8 +104,8 @@ jobs:
111104
steps:
112105
- uses: actions/checkout@v4
113106

114-
- name: Install toml
115-
run: pip install toml
107+
- name: Install deps
108+
run: pip install toml towncrier
116109

117110
- name: Set environment variables
118111
env:
@@ -160,11 +153,8 @@ jobs:
160153
- name: Update version
161154
run: .github/scripts/update-version.sh $STABLE_NEXT_VERSION $UNSTABLE_NEXT_VERSION
162155

163-
- name: Update the change log on main
164-
run: |
165-
# the actual release date on main will be updated at the end of the release workflow
166-
date=$(date "+%Y-%m-%d")
167-
sed -Ei "s/^## Unreleased$/## Unreleased\n\n## Version ${STABLE_VERSION}\/${UNSTABLE_VERSION} ($date)/" CHANGELOG.md
156+
- name: Generate changelog
157+
run: towncrier build --yes --version "$STABLE_VERSION/$UNSTABLE_VERSION"
168158

169159
- name: Use CLA approved github bot
170160
run: .github/scripts/use-cla-approved-github-bot.sh

CHANGELOG.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,7 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## Unreleased
9-
10-
- Add `attributes` field in `metrics.get_meter` wrapper function
11-
([#4364](https://github.com/open-telemetry/opentelemetry-python/pull/4364))
12-
- Add Python 3.13 support
13-
([#4353](https://github.com/open-telemetry/opentelemetry-python/pull/4353))
14-
- sdk: don't log or print warnings when the SDK has been disabled
15-
([#4371](https://github.com/open-telemetry/opentelemetry-python/pull/4371))
8+
<!-- changelog start -->
169

1710
## Version 1.29.0/0.50b0 (2024-12-11)
1811

pyproject.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,27 @@ known-third-party = [
4949
"opencensus",
5050
]
5151
known-first-party = ["opentelemetry", "opentelemetry_example_app"]
52+
53+
[tool.towncrier]
54+
directory = ".changelog"
55+
filename = "CHANGELOG.md"
56+
start_string = "<!-- changelog start -->\n"
57+
template = "scripts/changelog_template.j2"
58+
issue_format = "[#{issue}](https://github.com/open-telemetry/opentelemetry-python/pull/{issue})"
59+
wrap = true # to wrap fragments to a line length of 79
60+
issue_pattern = "^(\\d+)" # to allow only PR numbers as prefix (e.g. 1234.fixed)
61+
62+
[[tool.towncrier.type]]
63+
directory="changed"
64+
name = "Changed"
65+
showcontent = true
66+
67+
[[tool.towncrier.type]]
68+
directory="added"
69+
name = "Added"
70+
showcontent = true
71+
72+
[[tool.towncrier.type]]
73+
directory="fixed"
74+
name = "Fixed"
75+
showcontent = true

scripts/changelog_template.j2

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## Version {{ versiondata.version }} ({{ versiondata.date }})
2+
3+
{% for section, _ in sections.items() %}
4+
{%- if section %}{{ section }}{% endif -%}
5+
6+
{% if sections[section] %}
7+
{% for category, val in definitions.items() if category in sections[section] %}
8+
### {{ definitions[category]['name'] }}
9+
10+
{% for text, values in sections[section][category].items() %}
11+
{% if "\n - " in text or '\n * ' in text %}
12+
{%- set main_text, sub_items = text.split('\n', 1) %}
13+
- {{ main_text }} ({{ values|join(', ') }})
14+
{% if sub_items %}
15+
{{- sub_items }}
16+
{% endif %}
17+
{% else %}
18+
- {{ text }} ({{ values|join(', ') }})
19+
{% endif %}
20+
{% endfor %}
21+
22+
{% endfor %}
23+
{% endif %}
24+
{% endfor %}

0 commit comments

Comments
 (0)