-
Notifications
You must be signed in to change notification settings - Fork 212
38 lines (37 loc) · 1.34 KB
/
commit-message.yaml
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
name: commit-message
on:
merge_group:
pull_request:
branches: [main]
types:
- opened
- synchronize
- edited
- reopened
jobs:
commit-message:
if: ${{ github.event_name != 'merge_group' }}
runs-on: ubuntu-20.04
steps:
- name: verify_commit_message
env:
TITLE: ${{ github.event.pull_request.title }}
run: |
commit_msg_type_regex='feat|fix|refactor|style|test|docs|build|tool|chore|deps'
commit_msg_scope_regex='.{1,20}'
commit_msg_subject_regex='.{1,150}'
commit_msg_regex="^(${commit_msg_type_regex})(\(${commit_msg_scope_regex}\))?: (${commit_msg_subject_regex})\$"
merge_msg_regex="^Merge branch '.+' into .+\$"
full_regex="(${commit_msg_regex})|(${merge_msg_regex})"
grep -qP "$full_regex" <<< "$TITLE" || {
echo "ERROR: Invalid commit message header. Please fix format of your PR title."
echo
echo "Examples of valid commits:"
echo 'example 1: "feat(cli): new feature"'
echo 'example 2: "fix(advanced-metrics): bug fix"'
echo 'example 3: "docs: update readme"'
echo
echo "Valid types are: $commit_msg_type_regex"
echo "For more details, see .github/workflows/commit-message.yaml"
exit 1
}