-
Notifications
You must be signed in to change notification settings - Fork 0
46 lines (41 loc) · 1.31 KB
/
Copy pathcommit-lint.yml
File metadata and controls
46 lines (41 loc) · 1.31 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
name: Commit Lint
on:
pull_request:
branches: [main]
concurrency:
group: commit-lint-${{ github.ref }}
cancel-in-progress: true
jobs:
lint-commits:
name: Validate Commit Messages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Check commit messages
run: |
ERRORS=0
while IFS= read -r sha; do
msg=$(git log --format=%s -n 1 "$sha")
if echo "$msg" | grep -qE '^Merge '; then
continue
fi
if ! echo "$msg" | grep -qE '^(feat|fix|docs|chore|refactor|test|ci): .+'; then
echo "BAD: $msg"
echo " Commit $sha does not follow Conventional Commits format."
ERRORS=$((ERRORS + 1))
fi
if [ ${#msg} -gt 72 ]; then
echo "LONG: $msg"
echo " Commit $sha first line is ${#msg} chars (max 72)."
ERRORS=$((ERRORS + 1))
fi
done < <(git rev-list origin/main..HEAD)
if [ "$ERRORS" -gt 0 ]; then
echo ""
echo "Required format: <type>: <short description>"
echo "Allowed types: feat, fix, docs, chore, refactor, test, ci"
exit 1
fi
echo "All commit messages OK."