Skip to content

Commit 60c1997

Browse files
committed
Add CI job to check that changelog is up-to-date when making releases
1 parent ca2c69d commit 60c1997

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,48 @@ jobs:
2929
- name: Check that version and tag are identical
3030
run: test $GITHUB_REF_NAME = $VERSION
3131

32+
check_changelog:
33+
name: Check changelog is up-to-date
34+
needs: check_version
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@v4
38+
- name: Check that changes/ is empty
39+
shell: bash
40+
run: |
41+
set -euo pipefail
42+
# Count every *.md file except README.md in changes/
43+
count=$(find changes -type f -name '*.md' ! -name 'README.md' | wc -l)
44+
45+
if [ "$count" -ne 0 ]; then
46+
echo "::error::There are still $count news fragment(s) in 'changes/'."
47+
echo "Run 'towncrier build' and commit the updated CHANGELOG.md."
48+
exit 1
49+
fi
50+
echo "No news fragments left in changes/"
51+
- name: Check CHANGELOG.md heading
52+
shell: bash
53+
run: |
54+
set -euo pipefail
55+
56+
# Extract the first level 2 heading
57+
first_h2=$(grep -m1 -E "^## \[blaupause ${GITHUB_REF_NAME//./\\.}\]" CHANGELOG.md || true)
58+
59+
if [ -z "$first_h2" ]; then
60+
echo "::error::No level-2 (##) heading found in CHANGELOG.md."
61+
exit 1
62+
fi
63+
64+
echo "First heading in CHANGELOG.md: '$first_h2'"
65+
66+
expected="## [blaupause $GITHUB_REF_NAME]"
67+
if [ "$first_h2" != "$expected" ]; then
68+
echo "::error::First heading must be '$expected'"
69+
exit 1
70+
fi
71+
72+
echo "✔ CHANGELOG heading matches the pushed tag ($tag)"
73+
3274
publish-to-pypi:
3375
name: Publish to PyPI
3476
if: startsWith(github.ref, 'refs/tags/') # only publish on tag pushes

0 commit comments

Comments
 (0)