-
Notifications
You must be signed in to change notification settings - Fork 15
36 lines (31 loc) · 995 Bytes
/
commit-message-check.yaml
File metadata and controls
36 lines (31 loc) · 995 Bytes
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
name: Check Commit Messages
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
check-commit-messages:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Fetch base branch
run: git fetch origin master
- name: Get commit messages
run: |
COMMITS=$(git log origin/master..HEAD --pretty=format:"%s")
echo "Commit messages:"
echo "$COMMITS"
echo "$COMMITS" > commits.txt
- name: Validate commit messages
run: |
VALID_MESSAGES=$(grep -v '^Merge ' commits.txt)
INVALID=$(echo "$VALID_MESSAGES" | grep -vE '^#[[:digit:]]+[[:space:]]{1}' || true)
if [[ -n "$INVALID" ]]; then
echo "🔴 The following commit messages are invalid:"
echo "$INVALID"
exit 1
else
echo "🟢 All commit messages are valid."
fi