blob: 12c1f4696b6c94b6bb983142a95745deff92be85 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#!/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: $*"; }
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"
# Cross-check with Rust helper unit tests
out="$(cargo test -q --lib helpers::tests::conventional_subjects -- --exact 2>&1)"
echo "$out"
echo "$out" | rg -q '1 passed' || fail "Rust conventional_subjects test did not run/pass"
echo "All conventional-commit checks passed."
|