-
Notifications
You must be signed in to change notification settings - Fork 0
82 lines (68 loc) · 2.32 KB
/
Copy pathcommit-convention.yml
File metadata and controls
82 lines (68 loc) · 2.32 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
name: Commit Convention Check
on:
pull_request:
branches:
- master
push:
branches:
- master
permissions:
contents: read
concurrency:
group: commit-convention-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
conventional-commits:
name: Commit Convention
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
fetch-depth: 0
- name: Validate commit messages
shell: bash
run: |
set -euo pipefail
CONVENTIONAL_REGEX='^(feat|fix|chore|docs|refactor|perf|build|ci|test|revert)(\([^)]+\))?(!)?: .+'
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
BASE_SHA="${{ github.event.pull_request.base.sha }}"
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
else
BASE_SHA="${{ github.event.before }}"
HEAD_SHA="${{ github.sha }}"
fi
echo "Checking commits in range: ${BASE_SHA}..${HEAD_SHA}"
# First push on repo may have all-zero before SHA.
if [[ "$BASE_SHA" == "0000000000000000000000000000000000000000" ]]; then
COMMITS=$(git rev-list --max-count=1 "$HEAD_SHA")
else
COMMITS=$(git rev-list "${BASE_SHA}..${HEAD_SHA}")
fi
if [[ -z "$COMMITS" ]]; then
echo "No commits to validate."
exit 0
fi
FAIL=0
while IFS= read -r COMMIT; do
SUBJECT=$(git log -1 --pretty=%s "$COMMIT")
# Ignore merge commits created by GitHub.
if [[ "$SUBJECT" =~ ^Merge\ pull\ request\ ]] || [[ "$SUBJECT" =~ ^Merge\ branch\ ]]; then
continue
fi
if [[ ! "$SUBJECT" =~ $CONVENTIONAL_REGEX ]]; then
echo "Invalid commit: $COMMIT"
echo "Subject: $SUBJECT"
FAIL=1
fi
done <<< "$COMMITS"
if [[ "$FAIL" -ne 0 ]]; then
echo ""
echo "Use Conventional Commits:"
echo " feat: description"
echo " fix: description"
echo " chore: description"
exit 1
fi
echo "All commit messages are valid."