Skip to content

Commit

Permalink
ci: check that commit messages follow Conventional Commits format
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardosm committed Apr 26, 2024
1 parent dce389f commit b70394d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/convetional-commits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Conventional Commits

on:
pull_request:

jobs:
check-conventional-commits:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: ./ci/check-conventional-commits.sh "$GITHUB_BASE_REF" "$GITHUB_SHA"
32 changes: 32 additions & 0 deletions ci/check-conventional-commits.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
set -euo pipefail

if [ $# -ne 2 ]; then
echo "Usage: $0 <base_ref> <head_ref>"
exit 1
fi

git log

#base_ref="$(git rev-parse "$1")"
#head_ref="$(git rev-parse "$2")"

commits="$(git rev-list --reverse "^$1" "$2")"
mapfile -t commits <<< "$commits"
#mapfile -t commits < <(git rev-list --reverse "$1..$2")

lf=$'\n'
cr=$'\r'
exclam='!'
types="build|change|chore|ci|doc|feat|fix|perf|refactor|revert|style|test"
regex="^($types)(\([^$lf$cr]+\))?$exclam?: .+\$"

echo "Checking ${#commits[@]} commit(s)"
for commit in "${commits[@]}"; do
echo "Checking commit $commit"
commit_msg="$(git log --format=%B -n 1 "$commit")"
if [[ ! "$commit_msg" =~ $regex ]]; then
echo "Commit $commit does not follow Conventional Commits format"
exit 1
fi
done

0 comments on commit b70394d

Please sign in to comment.