@@ -2,7 +2,7 @@ name: commit-message
2
2
on :
3
3
merge_group :
4
4
pull_request :
5
- branches : [ main ]
5
+ branches : [main]
6
6
types :
7
7
- opened
8
8
- synchronize
@@ -13,33 +13,26 @@ jobs:
13
13
if : ${{ github.event_name != 'merge_group' }}
14
14
runs-on : ubuntu-20.04
15
15
steps :
16
- - name : verify_commit_message
17
- run : |
18
- if [[ "${{ github.event_name }}" == pull_request ]]; then
19
- commit_msg_header="${{ github.event.pull_request.title }}"
20
- else
21
- # get first line of commit message
22
- commit_msg_header=`echo "${{ github.event.head_commit.message }}" | head -n 1`
23
- fi
16
+ - name : verify_commit_message
17
+ env :
18
+ TITLE : ${{ github.event.pull_request.title }}
19
+ run : |
20
+ commit_msg_type_regex='feat|fix|refactor|style|test|docs|build|tool|chore|deps'
21
+ commit_msg_scope_regex='.{1,20}'
22
+ commit_msg_subject_regex='.{1,150}'
23
+ commit_msg_regex="^(${commit_msg_type_regex})(\(${commit_msg_scope_regex}\))?: (${commit_msg_subject_regex})\$"
24
+ merge_msg_regex="^Merge branch '.+' into .+\$"
25
+ full_regex="(${commit_msg_regex})|(${merge_msg_regex})"
24
26
25
- commit_msg_type_regex='feat|fix|refactor|style|test|docs|build|tool|chore|deps'
26
- commit_msg_scope_regex='.{1,20}'
27
- commit_msg_subject_regex='.{1,150}'
28
- commit_msg_regex="^(${commit_msg_type_regex})(\(${commit_msg_scope_regex}\))?: (${commit_msg_subject_regex})\$"
29
- merge_msg_regex="^Merge branch '.+' into .+\$"
30
- full_regex="(${commit_msg_regex})|(${merge_msg_regex})"
31
-
32
- echo $commit_msg_header | grep -qP "$full_regex" || {
33
- echo "ERROR: Invalid commit message header. Please fix format of your PR title or the commit pushed to main."
34
- echo "Current value:"
35
- echo "$commit_msg_header"
36
- echo
37
- echo "Examples of valid commits:"
38
- echo 'example 1: "feat(cli): new feature"'
39
- echo 'example 2: "fix(advanced-metrics): bug fix"'
40
- echo 'example 3: "docs: update readme"'
41
- echo
42
- echo "Valid types are: $commit_msg_type_regex"
43
- echo "For more details, see .github/workflows/commit-message.yaml"
44
- exit 1
45
- }
27
+ grep -qP "$full_regex" <<< "$TITLE" || {
28
+ echo "ERROR: Invalid commit message header. Please fix format of your PR title."
29
+ echo
30
+ echo "Examples of valid commits:"
31
+ echo 'example 1: "feat(cli): new feature"'
32
+ echo 'example 2: "fix(advanced-metrics): bug fix"'
33
+ echo 'example 3: "docs: update readme"'
34
+ echo
35
+ echo "Valid types are: $commit_msg_type_regex"
36
+ echo "For more details, see .github/workflows/commit-message.yaml"
37
+ exit 1
38
+ }
0 commit comments