#!/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."