-
Notifications
You must be signed in to change notification settings - Fork 0
52 lines (44 loc) · 1.57 KB
/
Copy pathcommit-message.yml
File metadata and controls
52 lines (44 loc) · 1.57 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
# This workflow is needed to validate commit messages in pull requests, if the githook was bypassed
name: Commit Message
on:
pull_request:
permissions:
contents: read
pull-requests: read
jobs:
validate-commit-messages:
name: Validate commit messages
runs-on: ubuntu-latest
steps:
- name: Check commit message
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Fetch base branch
run: git fetch origin "${{ github.base_ref }}"
- name: Validate commit message
shell: bash
run: |
pattern='^((feat|fix|docs|style|refactor|test|chore|ci|build|perf)\(#[0-9]+\): .{1,50}|chore\(deps\): .{1,72})$'
invalid=0
while IFS= read -r commit_message; do
echo "Checking: $commit_message"
if echo "$commit_message" | grep -Eq '^(Merge|Revert)'; then
echo "Skipping technical commit: $commit_message"
continue
fi
if ! echo "$commit_message" | grep -Eq "$pattern"; then
echo "::error::Invalid commit message: $commit_message"
invalid=1
fi
done < <(git log --format=%s "origin/${{ github.base_ref }}..HEAD")
if [ "$invalid" -ne 0 ]; then
echo ""
echo "Expected format:"
echo " feat(#1): add feature"
echo " chore(#5): add a file to .gitignore"
echo ""
echo "Allowed types:"
echo " feat, fix, docs, style, refactor, test, chore, ci, build, perf"
exit 1
fi