Repository navigation
56 lines (46 loc) · 1.68 KB
/
Copy pathconventional-commit.yml
File metadata and controls
56 lines (46 loc) · 1.68 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
47
48
49
50
51
52
53
54
55
56
name: Conventional Commits
on:
pull_request:
branches: [master, main]
permissions:
contents: read
jobs:
check:
name: Validate commit messages
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate conventional commits
shell: bash
run: |
set -euo pipefail
# Regex for conventional commits:
# type[!][(scope)]: description
# types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
pattern='^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(!)?(\([a-zA-Z0-9._-]+\))?: .+'
base="${{ github.event.pull_request.base.sha }}"
head="${{ github.event.pull_request.head.sha }}"
echo "Checking commits from ${base:0:8} to ${head:0:8}..."
invalid=0
while IFS= read -r line; do
hash="${line%% *}"
subject="${line#* }"
if [[ "$subject" =~ $pattern ]]; then
echo " ✓ ${hash:0:8} $subject"
else
echo " ✗ ${hash:0:8} $subject"
invalid=$((invalid + 1))
fi
done < <(git log --no-merges --format='%H %s' "$base..$head")
if [ "$invalid" -gt 0 ]; then
echo
echo "ERROR: $invalid commit(s) do not follow Conventional Commits."
echo "Expected format: <type>[!][(scope)]: <description>"
echo "Valid types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert"
exit 1
fi
echo
echo "All commits follow Conventional Commits."