Repository navigation
50 lines (42 loc) · 1.59 KB
/
Copy pathconventional-commit.yml
File metadata and controls
50 lines (42 loc) · 1.59 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
name: Conventional Commits
on:
pull_request:
branches:
- main
jobs:
validate:
name: Validate Conventional Commits
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate PR commit messages
shell: bash
run: |
PATTERN="^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(!)?(\([a-zA-Z0-9._-]+\))?: .+"
BASE_SHA="${{ github.event.pull_request.base.sha }}"
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
FAILED=0
echo "Validating commits between $BASE_SHA and $HEAD_SHA..."
while IFS= read -r line; do
[ -z "$line" ] && continue
commit_hash="${line%% *}"
subject="${line#* }"
if [[ "$subject" =~ $PATTERN ]]; then
echo "✓ [$commit_hash] $subject"
else
echo "✗ [$commit_hash] $subject"
echo " Error: Commit subject does not follow Conventional Commits format."
echo " Pattern: $PATTERN"
FAILED=1
fi
done < <(git log --no-merges --format="%H %s" "$BASE_SHA..$HEAD_SHA")
if [ $FAILED -ne 0 ]; then
echo ""
echo "Validation failed: One or more non-merge commits do not follow Conventional Commits format."
echo "Format requirement: <type>(<scope>): <description> or <type>: <description>"
exit 1
fi
echo "All non-merge commits follow Conventional Commits format."