From 49425ab994fe49e6932fb513c9204c6dc2b1537d Mon Sep 17 00:00:00 2001 From: Keiichiro Ui Date: Fri, 8 Dec 2023 22:54:09 +0900 Subject: [PATCH] Lint changelog --- Makefile | 1 + scripts/lint_changelog.bash | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100755 scripts/lint_changelog.bash diff --git a/Makefile b/Makefile index 8595b86..31fee5e 100644 --- a/Makefile +++ b/Makefile @@ -58,6 +58,7 @@ lint: node_modules npx prettier . --check npx tsc --project src --noEmit hadolint Dockerfile + ./scripts/lint_changelog.bash .PHONY: fix fix: node_modules diff --git a/scripts/lint_changelog.bash b/scripts/lint_changelog.bash new file mode 100755 index 0000000..d03ed44 --- /dev/null +++ b/scripts/lint_changelog.bash @@ -0,0 +1,31 @@ +#!/bin/bash + +set -euo pipefail + +cd "$(dirname "$0")/.." + +main() { + has_current_version_chengelog + for file in changelog/*.md; do + should_start_with_version_header "$file" + done +} + +has_current_version_chengelog() { + local v="$(node -e 'console.log(require("./package.json").version)')" + if ! [[ -f "changelog/$v.md" ]]; then + echo "changelog/$v.md does not exist" + exit 1 + fi +} + +should_start_with_version_header() { + local file="$1" + local v=$(basename "$file" .md) + if head -n1 "$file" | grep -vq "^# Version $v$"; then + echo "changelog/$v.md does not start with the correct version header" + exit 1 + fi +} + +main