Skip to content

Commit

Permalink
ci: add commit message check
Browse files Browse the repository at this point in the history
  • Loading branch information
komret committed Feb 14, 2024
1 parent 5f17a36 commit 2b6fbd9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 27 deletions.
23 changes: 0 additions & 23 deletions .git-hooks/post-merge

This file was deleted.

12 changes: 12 additions & 0 deletions .github/workflows/commit-messages-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: "[Check]: Commit messages"

on: [pull_request]

jobs:
commit-message-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Check commit messages
run: ./scripts/check-commit-messages.sh
6 changes: 3 additions & 3 deletions COMMITS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Commits

Using [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) is strongly recommended and might be enforced in future.
Using [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) is enforced by a CI check.

### Examples

Expand All @@ -12,7 +12,7 @@ feat(lang): added polish language

### Git hook

Use this git hook to auto-check your commit messages. Save the following snippet into `.git/hooks/commit-msg`
Use this git hook to auto-check your commit messages. Save the following snippet into `.git/hooks/commit-msg`. This way, the check will run locally and can avoid some unnecessary CI runs.

```bash
#!/bin/sh
Expand All @@ -23,7 +23,7 @@ if echo "$commit_msg" | grep -qE "^(Revert|fixup! )"; then
exit 0
fi

if ! grep -qE "^(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert)(\([a-z\-]+\))?: " "$1" ; then
if ! grep -qE "^(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert)(\([a-z, -]+\))?: " "$1" ; then
echo "Conventional Commits validation failed"
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Run a dev build:

Inspired by [GitLab Contributing Guide](https://docs.gitlab.com/ee/development/contributing/)

Using [Conventional Commits](COMMITS.md) is strongly recommended.
Using [Conventional Commits](COMMITS.md) is required.

## Security vulnerability disclosure

Expand Down
15 changes: 15 additions & 0 deletions scripts/check-commit-messages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
for commit in $(git rev-list origin/HEAD..HEAD); do

commit_msg=$(git log --format=%B -n 1 "$commit")

# Skip validation in case of fixup and revert commits
if echo "$commit_msg" | grep -qE "^(Revert|fixup! )"; then
continue
fi

if ! echo "$commit_msg" | grep -qE "^(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert)(\([a-z, -]+\))?: "; then
echo "Conventional Commits validation failed for commit $commit: $commit_msg"
exit 1
fi
done

0 comments on commit 2b6fbd9

Please sign in to comment.