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