Skip to content

Commit c3b8e39

Browse files
MikeGoldsmithxrmx
andauthored
ci: validate changelog fragment filenames (#4586)
* ci: validate changelog fragment filenames Extend the existing fragment-existence check so it also rejects fragments whose basename doesn't match <PR_NUMBER>.<type> (where type is one of added, changed, deprecated, removed, fixed). This catches typos in the PR number or in the fragment type that would otherwise render a wrong PR link, or be silently dropped, in the rendered changelog. Also note in the do-not-edit comment of each towncrier-managed CHANGELOG.md (root and the 4 independent packages) that the existing static "## Unreleased" entries pre-date towncrier and 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 * Update CHANGELOG.md * Update CHANGELOG.md * Update CHANGELOG.md * Update CHANGELOG.md --------- Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
1 parent 35f1575 commit c3b8e39

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

.github/workflows/changelog.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ jobs:
4141
fi
4242
4343
- name: Check for changelog fragment
44+
env:
45+
PR_NUMBER: ${{ github.event.pull_request.number }}
4446
run: |
4547
# Check for any new fragment files in any .changelog/ directory
4648
fragments=$(git diff --diff-filter=A --name-only FETCH_HEAD -- '**/.changelog/*' '.changelog/*' | grep -v '.gitignore' || true)
4749
if [[ -z "$fragments" ]]; then
4850
echo "No changelog fragment found for this PR."
4951
echo ""
50-
echo "Add a file named .changelog/${{ github.event.pull_request.number }}.<type>"
52+
echo "Add a file named .changelog/${PR_NUMBER}.<type>"
5153
echo "where <type> is one of: added, changed, deprecated, removed, fixed"
5254
echo ""
5355
echo "For coordinated packages, add to the root .changelog/ directory."
@@ -57,6 +59,24 @@ jobs:
5759
echo "Or add the \"Skip Changelog\" label if this job should be skipped."
5860
exit 1
5961
fi
62+
invalid=()
63+
while IFS= read -r f; do
64+
base=$(basename "$f")
65+
if [[ ! "$base" =~ ^([0-9]+)\.(added|changed|deprecated|removed|fixed)$ ]]; then
66+
invalid+=("$f (expected <PR_NUMBER>.<type>; type one of added, changed, deprecated, removed, fixed)")
67+
continue
68+
fi
69+
if [[ "${BASH_REMATCH[1]}" != "${PR_NUMBER}" ]]; then
70+
invalid+=("$f (PR number ${BASH_REMATCH[1]} does not match this PR's number ${PR_NUMBER})")
71+
fi
72+
done <<< "$fragments"
73+
if (( ${#invalid[@]} > 0 )); then
74+
echo "Invalid changelog fragment(s):"
75+
for msg in "${invalid[@]}"; do
76+
echo " $msg"
77+
done
78+
exit 1
79+
fi
6080
echo "Found changelog fragment(s):"
6181
echo "$fragments"
6282

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ issue_format = "[#{issue}](https://github.com/open-telemetry/opentelemetry-pytho
249249
wrap = true
250250
issue_pattern = "^(\\d+)"
251251

252+
# NOTE: remember to update the changelog workflow if these types change
252253
[[tool.towncrier.type]]
253254
directory = "added"
254255
name = "Added"

0 commit comments

Comments
 (0)