Skip to content

Commit 3d7fa06

Browse files
committed
ci: add semantic commit message check for PRs
Validates that all commits in a PR follow the conventional format (feat/fix/refactor/test/docs/ci/chore/perf/style/build/revert).
1 parent 3c8146f commit 3d7fa06

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

.github/workflows/ci.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,34 @@ jobs:
131131
go mod tidy
132132
git diff --exit-code go.mod go.sum
133133
134+
commit-messages:
135+
name: Commit Messages
136+
if: github.event_name == 'pull_request'
137+
runs-on: ubuntu-latest
138+
steps:
139+
- uses: actions/checkout@v4
140+
with:
141+
fetch-depth: 0
142+
143+
- name: Check semantic commit messages
144+
run: |
145+
MERGE_BASE=$(git merge-base ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }})
146+
COMMITS=$(git log --format='%s' "$MERGE_BASE"..${{ github.event.pull_request.head.sha }})
147+
PATTERN='^(feat|fix|refactor|test|docs|ci|chore|perf|style|build|revert)(\(.+\))?: .+'
148+
FAILED=0
149+
while IFS= read -r msg; do
150+
if [[ ! "$msg" =~ $PATTERN ]]; then
151+
echo "::error::Non-compliant commit message: $msg"
152+
FAILED=1
153+
fi
154+
done <<< "$COMMITS"
155+
if [ "$FAILED" -eq 1 ]; then
156+
echo ""
157+
echo "Commit messages must follow: <type>: <description>"
158+
echo "Valid types: feat, fix, refactor, test, docs, ci, chore, perf, style, build, revert"
159+
exit 1
160+
fi
161+
134162
genconfig:
135163
name: Verify Generated Configs
136164
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)