Skip to content

Commit 0b690d2

Browse files
MikeGoldsmithxrmx
andauthored
ci: validate changelog fragment filenames (#5212)
* ci: validate changelog fragment filenames Add a workflow step that rejects fragments whose basename doesn't match <PR_NUMBER>.<type> (where type is one of added, changed, deprecated, removed, fixed). This catches typos in either the PR number or the fragment type before they produce a misleading PR link in the rendered changelog. towncrier check verifies a fragment exists; it doesn't enforce naming. Also note in the do-not-edit comment of the root CHANGELOG.md that the existing static "## Unreleased" entries must be folded into the first towncrier-built release manually — towncrier inserts new release blocks above that section without merging. Assisted-by: Claude Opus 4.7 (1M context) * Update CHANGELOG.md * Update pyproject.toml --------- Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
1 parent d4fabb4 commit 0b690d2

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

.github/workflows/changelog.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,30 @@ jobs:
5656
false
5757
fi
5858
59+
- name: Validate fragment filenames
60+
env:
61+
PR_NUMBER: ${{ github.event.pull_request.number }}
62+
run: |
63+
fragments=$(git diff --diff-filter=A --name-only origin/${{ github.base_ref }} -- '.changelog/*' | grep -v '/\.gitignore$' || true)
64+
[ -z "$fragments" ] && exit 0
65+
invalid=()
66+
while IFS= read -r f; do
67+
base=$(basename "$f")
68+
if [[ ! "$base" =~ ^([0-9]+)\.(added|changed|deprecated|removed|fixed)$ ]]; then
69+
invalid+=("$f (expected <PR_NUMBER>.<type>; type one of added, changed, deprecated, removed, fixed)")
70+
continue
71+
fi
72+
if [[ "${BASH_REMATCH[1]}" != "${PR_NUMBER}" ]]; then
73+
invalid+=("$f (PR number ${BASH_REMATCH[1]} does not match this PR's number ${PR_NUMBER})")
74+
fi
75+
done <<< "$fragments"
76+
if (( ${#invalid[@]} > 0 )); then
77+
echo "Invalid changelog fragment(s):"
78+
for msg in "${invalid[@]}"; do
79+
echo " $msg"
80+
done
81+
exit 1
82+
fi
83+
5984
- name: Preview changelog
6085
run: towncrier build --draft --version Unreleased

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ issue_format = "[#{issue}](https://github.com/open-telemetry/opentelemetry-pytho
174174
wrap = true # wrap fragments to 79 char line length
175175
issue_pattern = "^(\\d+)" # only PR numbers as fragment prefix (e.g. 1234.fixed)
176176

177+
# NOTE: remember to update the changelog workflow if these types change
177178
[[tool.towncrier.type]]
178179
directory = "added"
179180
name = "Added"

0 commit comments

Comments
 (0)