aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRadon Rosborough <radon@intuitiveexplanations.com>2024-03-02 13:50:58 -0800
committerGitHub <noreply@github.com>2024-03-02 13:50:58 -0800
commitdd24c54897a19c2d7e0d90409bb23238fcac79f2 (patch)
tree2b0f8a897c070a43a966e3aa6315515da7c53cf1
parent2fec5692e424cd24e7450d63bbe58f75eafb7417 (diff)
Add changelog linter (#287)
This should help make sure we don't forget to document any important user-visible changes.
-rw-r--r--.github/workflows/lint.yml7
-rw-r--r--Makefile4
-rwxr-xr-xscripts/lint-changelog.bash39
3 files changed, 49 insertions, 1 deletions
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index 6a3c3ce..2d2340d 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -13,8 +13,13 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
+ with:
+ ref: ${{ github.event.pull_request.head.sha }}
+ # No shallow clone, we want to be able to compare PR branch
+ # to main.
+ fetch-depth: 0
- name: Run linters
env:
VERSION: ${{ matrix.emacs_version }}
run: >-
- make docker CMD="make lint"
+ make docker CMD="make lint lint-changelog"
diff --git a/Makefile b/Makefile
index 24fda89..1e2b7aa 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/scripts/lint-changelog.bash b/scripts/lint-changelog.bash
new file mode 100755
index 0000000..3a6334f
--- /dev/null
+++ b/scripts/lint-changelog.bash
@@ -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 ==>
+
+lint-changelog: Please update the changelog to cover the changes you made.
+EOF
+ exit 1
+fi