Skip to content

Commit dd24c54

Browse files
authored
Add changelog linter (radian-software#287)
This should help make sure we don't forget to document any important user-visible changes.
1 parent 2fec569 commit dd24c54

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

.github/workflows/lint.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ jobs:
1313
steps:
1414
- name: Checkout
1515
uses: actions/checkout@v4
16+
with:
17+
ref: ${{ github.event.pull_request.head.sha }}
18+
# No shallow clone, we want to be able to compare PR branch
19+
# to main.
20+
fetch-depth: 0
1621
- name: Run linters
1722
env:
1823
VERSION: ${{ matrix.emacs_version }}
1924
run: >-
20-
make docker CMD="make lint"
25+
make docker CMD="make lint lint-changelog"

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,7 @@ fmt-changed: ## Get list of changed formatters on this PR
107107
.PHONY: fmt-test # env var: FORMATTERS
108108
fmt-test: ## Actually run formatter tests
109109
@test/formatters/run-func.bash apheleia-ft-test
110+
111+
.PHONY: lint-changelog
112+
lint-changelog: ## Report an error if the changelog wasn't updated
113+
@scripts/lint-changelog.bash

scripts/lint-changelog.bash

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
changed_files="$(git diff --name-only origin/main)"
6+
if [[ -z "${changed_files}" ]]; then
7+
exit 0
8+
fi
9+
10+
commit_messages="$(git log origin/main..)"
11+
if tr '[:upper:]' '[:lower:]' <<< "${commit_messages}" | \
12+
tr '\n' ' ' | sed -E 's/[[:space:]]+/ /g' | \
13+
grep -q "no changelog update needed"; then
14+
exit 0
15+
fi
16+
17+
if ! grep -qF CHANGELOG.md <<< "${changed_files}"; then
18+
cat <<"EOF"
19+
<== lint-changelog ==>
20+
21+
Please update the changelog to cover the changes you made. Or, if the
22+
changes don't need to be documented in the changelog, add the text "no
23+
changelog update needed" to one of your commit messages. Line breaks
24+
and case sensitivity do not matter.
25+
26+
Remember, when writing a changelog entry, the idea is a user can use
27+
it to understand what differences they might notice after upgrading to
28+
the new version. So, include enough context for someone who isn't
29+
working directly on the code to understand. If user-visible behavior
30+
hasn't changed since the last release, for example because you're
31+
fixing a bug that was just introduced, then you don't need a changelog
32+
entry.
33+
34+
<== lint-changelog ==>
35+
36+
lint-changelog: Please update the changelog to cover the changes you made.
37+
EOF
38+
exit 1
39+
fi

0 commit comments

Comments
 (0)