scripts/commitlint.sh
1
#!/usr/bin/env bash
3
set -euo pipefail
5
re='^(feat|fix|docs|style|refactor|test|chore|perf|ci|build|revert)(!)?(\([a-z0-9 .\-]+\))?!?: .+'
7
failed=0
8
while IFS= read -r subject; do
9
[ -z "$subject" ] && continue
10
case "$subject" in
11
'Merge '*) continue ;;
12
esac
13
if ! printf '%s\n' "$subject" | grep -qE "$re"; then
14
echo "::error::non-conforming commit subject: $subject" >&2
15
failed=1
16
fi
17
done
19
if [ "$failed" -ne 0 ]; then
20
cat >&2 <<'MSG'
21
Commit subjects MUST follow Conventional Commits 1.0.0:
22
<type>(<scope>)?!: <description>
23
Types: feat, fix, docs, style, refactor, test, chore, perf, ci, build, revert
24
Use ! after the type (or after the scope) for breaking changes.
25
See https://www.conventionalcommits.org/ and docs/explanation/decisions/0128.
26
MSG
27
exit 1
28
fi