summaryrefslogtreecommitdiff
path: root/tests/conventional-commits.test.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tests/conventional-commits.test.sh')
-rwxr-xr-xtests/conventional-commits.test.sh42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/conventional-commits.test.sh b/tests/conventional-commits.test.sh
new file mode 100755
index 0000000..042b819
--- /dev/null
+++ b/tests/conventional-commits.test.sh
@@ -0,0 +1,42 @@
+#!/usr/bin/env bash
+# Enforce Conventional Commits 1.0.0 on every commit subject in this repo.
+set -euo pipefail
+
+ROOT="$(cd "$(dirname "$0")/.." && pwd)"
+cd "$ROOT"
+
+fail() { echo "FAIL: $*" >&2; exit 1; }
+pass() { echo "ok: $*"; }
+
+# Same rule as scripts/lib/note-helpers.mjs isConventionalCommitSubject
+RE='^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-zA-Z0-9._/-]+\))?!?: .+'
+
+mapfile -t SUBJECTS < <(git log --format=%s)
+[[ "${#SUBJECTS[@]}" -gt 0 ]] || fail "no commits"
+
+bad=0
+for s in "${SUBJECTS[@]}"; do
+ if [[ ! "$s" =~ $RE ]]; then
+ echo "non-conventional: $s" >&2
+ bad=1
+ else
+ pass "commit: $s"
+ fi
+done
+[[ "$bad" -eq 0 ]] || fail "one or more commits are not Conventional Commits"
+
+# Unit helper agrees with git history
+node --input-type=module -e '
+import { isConventionalCommitSubject } from "./scripts/lib/note-helpers.mjs";
+import { execSync } from "node:child_process";
+const subjects = execSync("git log --format=%s", { encoding: "utf8" })
+ .trim().split("\n").filter(Boolean);
+for (const s of subjects) {
+ if (!isConventionalCommitSubject(s)) {
+ console.error("helper rejected:", s);
+ process.exit(1);
+ }
+}
+'
+
+echo "All conventional-commit checks passed."