Skip to content

Commit 9cf8c44

Browse files
ci: add GitHub Action to validate commit message style
This workflow checks all commits between the current branch and upstream/master. It enforces subject length, colon usage in the subject line, and body line length. This helps maintain consistency and readability in the project's history.
1 parent 4659d19 commit 9cf8c44

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

.github/workflows/compliance_check.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,56 @@ jobs:
106106
shell: bash
107107
run: |
108108
.github/check_doxygen.py
109+
110+
commits-check:
111+
name: Check commit messages
112+
runs-on: ubuntu-latest
113+
steps:
114+
- uses: actions/checkout@v3
115+
with:
116+
fetch-depth: 0
117+
- name: Validate commit message style
118+
shell: bash
119+
run: |
120+
set -e
121+
has_errors=0
122+
base_commit=$(git merge-base HEAD origin/master)
123+
for commit in $(git rev-list ${base_commit}...HEAD); do
124+
short_sha=$(git rev-parse --short=7 $commit)
125+
subject=$(git log -1 --pretty=format:%s $commit)
126+
body=$(git log -1 --pretty=format:%b $commit)
127+
128+
if [ ${#subject} -gt 72 ]; then
129+
echo "Commit $short_sha subject too long (${#subject} > 72):"
130+
has_errors=1
131+
fi
132+
133+
if [[ "$subject" != *:* ]]; then
134+
echo "Commit $short_sha subject missing colon (e.g. 'subsystem: msg')"
135+
has_errors=1
136+
fi
137+
138+
if [ -z "$body" ]; then
139+
echo "Commit $short_sha body is missing"
140+
has_errors=1
141+
else
142+
line_num=0
143+
while IFS= read -r line; do
144+
line_num=$((line_num + 1))
145+
if [ ${#line} -gt 72 ]; then
146+
echo "Commit $short_sha body line $line_num too long (${#line} > 72):"
147+
echo "$line"
148+
has_errors=1
149+
fi
150+
done <<< "$body"
151+
fi
152+
153+
echo ""
154+
done
155+
156+
if [ "$has_errors" -eq 1 ]; then
157+
echo "Commit message check failed."
158+
exit 1
159+
else
160+
echo "All commit messages pass style rules."
161+
fi

0 commit comments

Comments
 (0)