Skip to content

Commit

Permalink
Add changelog linter
Browse files Browse the repository at this point in the history
No changelog update needed for this.
  • Loading branch information
raxod502 committed Mar 2, 2024
1 parent 2fec569 commit 5c7ab12
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
env:
VERSION: ${{ matrix.emacs_version }}
run: >-
make docker CMD="make lint"
make docker CMD="make lint lint-changelog"
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,7 @@ fmt-changed: ## Get list of changed formatters on this PR
.PHONY: fmt-test # env var: FORMATTERS
fmt-test: ## Actually run formatter tests
@test/formatters/run-func.bash apheleia-ft-test

.PHONY: lint-changelog
lint-changelog: ## Report an error if the changelog wasn't updated
@scripts/lint-changelog.bash
39 changes: 39 additions & 0 deletions scripts/lint-changelog.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

set -euo pipefail

changed_files="$(git diff --name-only origin/main)"
if [[ -z "${changed_files}" ]]; then
exit 0
fi

commit_messages="$(git log origin/main..)"
if tr '[:upper:]' '[:lower:]' <<< "${commit_messages}" | \
tr '\n' ' ' | sed -E 's/[[:space:]]+/ /g' | \
grep -q "no changelog update needed"; then
exit 0
fi

if ! grep -qF CHANGELOG.md <<< "${changed_files}"; then
cat <<"EOF"
<== lint-changelog ==>
Please update the changelog to cover the changes you made. Or, if the
changes don't need to be documented in the changelog, add the text "no
changelog update needed" to one of your commit messages. Line breaks
and case sensitivity do not matter.
Remember, when writing a changelog entry, the idea is a user can use
it to understand what differences they might notice after upgrading to
the new version. So, include enough context for someone who isn't
working directly on the code to understand. If user-visible behavior
hasn't changed since the last release, for example because you're
fixing a bug that was just introduced, then you don't need a changelog
entry.
<== lint-changelog ==>
EOF
echo >&2 "lint-changelog: Please update the changelog to cover the changes you made."
exit 1
fi

0 comments on commit 5c7ab12

Please sign in to comment.