Skip to content

Commit 3bb2671

Browse files
szymon-czaprackisjanc
authored andcommitted
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 77a383d commit 3bb2671

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

.github/workflows/compliance_check.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,73 @@ jobs:
110110
shell: bash
111111
run: |
112112
.github/check_doxygen.py
113+
114+
commits-check:
115+
name: Check commit messages
116+
runs-on: ubuntu-latest
117+
steps:
118+
- uses: actions/checkout@v3
119+
with:
120+
fetch-depth: 0
121+
122+
- name: Validate commit message style
123+
shell: bash
124+
run: |
125+
set -e
126+
has_errors=0
127+
COMMIT_URL="https://cwiki.apache.org/confluence/display/MYNEWT/Contributing+to+Apache+Mynewt"
128+
129+
# Determine commit range for PR or fallback to origin/master
130+
if [ -n "${GITHUB_BASE_REF}" ]; then
131+
base_ref="origin/${GITHUB_BASE_REF}"
132+
else
133+
base_ref="origin/master"
134+
fi
135+
136+
base_commit=$(git merge-base HEAD ${base_ref})
137+
138+
echo "Checking commits from ${base_commit} to HEAD"
139+
140+
for commit in $(git rev-list --no-merges ${base_commit}..HEAD); do
141+
short_sha=$(git rev-parse --short=7 $commit)
142+
subject=$(git log -1 --pretty=format:%s $commit)
143+
body=$(git log -1 --pretty=format:%b $commit)
144+
145+
if [ ${#subject} -gt 72 ]; then
146+
echo "Commit $short_sha subject too long (${#subject} > 72):"
147+
echo "$subject"
148+
has_errors=1
149+
fi
150+
151+
if [[ "$subject" != *:* ]]; then
152+
echo "Commit $short_sha subject missing colon (e.g. 'subsystem: msg')"
153+
echo "$subject"
154+
has_errors=1
155+
fi
156+
157+
if [ -z "$body" ]; then
158+
echo "Commit $short_sha body is missing"
159+
has_errors=1
160+
else
161+
line_num=0
162+
while IFS= read -r line; do
163+
line_num=$((line_num + 1))
164+
if [ ${#line} -gt 72 ]; then
165+
echo "Commit $short_sha body line $line_num too long (${#line} > 72):"
166+
echo "$line"
167+
has_errors=1
168+
fi
169+
done <<< "$body"
170+
fi
171+
172+
echo ""
173+
done
174+
175+
if [ "$has_errors" -eq 1 ]; then
176+
echo "::error::Commit message check failed."
177+
echo "For contributing guidelines, see:"
178+
echo " $COMMIT_URL"
179+
exit 1
180+
else
181+
echo "All commit messages pass style rules."
182+
fi

0 commit comments

Comments
 (0)