-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: check that commit messages follow Conventional Commits format
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |