Skip to content

Commit 0c7d05f

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 0c7d05f

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

.github/workflows/compliance_check.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,70 @@ 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+
118+
- name: Validate commit message style
119+
shell: bash
120+
run: |
121+
set -e
122+
has_errors=0
123+
124+
# Determine commit range for PR or fallback to origin/master
125+
if [ -n "${GITHUB_BASE_REF}" ]; then
126+
base_ref="origin/${GITHUB_BASE_REF}"
127+
else
128+
base_ref="origin/master"
129+
fi
130+
131+
base_commit=$(git merge-base HEAD ${base_ref})
132+
133+
echo "Checking commits from ${base_commit} to HEAD"
134+
135+
for commit in $(git rev-list ${base_commit}..HEAD); do
136+
short_sha=$(git rev-parse --short=7 $commit)
137+
subject=$(git log -1 --pretty=format:%s $commit)
138+
body=$(git log -1 --pretty=format:%b $commit)
139+
140+
if [ ${#subject} -gt 72 ]; then
141+
echo "Commit $short_sha subject too long (${#subject} > 72):"
142+
echo "$subject"
143+
has_errors=1
144+
fi
145+
146+
if [[ "$subject" != *:* ]]; then
147+
echo "Commit $short_sha subject missing colon (e.g. 'subsystem: msg')"
148+
echo "$subject"
149+
has_errors=1
150+
fi
151+
152+
if [ -z "$body" ]; then
153+
echo "Commit $short_sha body is missing"
154+
has_errors=1
155+
else
156+
line_num=0
157+
while IFS= read -r line; do
158+
line_num=$((line_num + 1))
159+
if [ ${#line} -gt 72 ]; then
160+
echo "Commit $short_sha body line $line_num too long (${#line} > 72):"
161+
echo "$line"
162+
has_errors=1
163+
fi
164+
done <<< "$body"
165+
fi
166+
167+
echo ""
168+
done
169+
170+
if [ "$has_errors" -eq 1 ]; then
171+
echo "Commit message check failed."
172+
exit 1
173+
else
174+
echo "All commit messages pass style rules."
175+
fi

0 commit comments

Comments
 (0)