Skip to content

Commit 97bfd32

Browse files
committed
ci: enforce commit message conventions
Cherry-pick pull request redpwn#522 from redpwn/ci/commit-check
1 parent 13ba69f commit 97bfd32

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

.github/workflows/ci.yml

+14-1
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,27 @@ on:
55
pull_request:
66

77
jobs:
8+
check-commits:
9+
runs-on: ubuntu-latest
10+
if: github.event_name == 'pull_request'
11+
steps:
12+
- uses: actions/checkout@v2
13+
with:
14+
# Fetch all history
15+
fetch-depth: 0
16+
17+
- name: Check commit messages
18+
run: |
19+
scripts/check-commits.sh ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}
20+
821
shellcheck:
922
runs-on: ubuntu-latest
1023
steps:
1124
- uses: actions/checkout@v2
1225

1326
- name: Shellcheck
1427
run: |
15-
shellcheck install/*.sh
28+
shellcheck install/*.sh scripts/*.sh
1629
1730
lint:
1831
runs-on: ubuntu-latest

CONTRIBUTING.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ You should follow the examples below as a guideline for how to name your branche
5252
```
5353
feature/brief-description-here
5454
fix/bug-description
55-
style/some-frontend-component
5655
refactor/some-component
57-
add/contributing-md
56+
docs/some-component
5857
```

scripts/check-commits.sh

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
set -eo pipefail
4+
5+
do_check() {
6+
set -eo pipefail
7+
8+
base="$1"
9+
head="$2"
10+
log="$(git log --pretty='format:%h %s' --no-merges "${base}..${head}")"
11+
if [ -z "$log" ]; then
12+
echo 'WARNING: no commits in specified range' >&2
13+
fi
14+
grep -vE '^[0-9a-f]+ (feat|fix|refactor|docs|chore|build|test|ci|style)(\([a-zA-Z-]+\))?:' <<<"$log" || true
15+
}
16+
17+
if [ $# -ne 2 ]; then
18+
cat >&2 <<EOF
19+
Usage:
20+
$0 BASE HEAD
21+
EOF
22+
exit 1
23+
fi
24+
25+
output="$(do_check "$1" "$2")"
26+
if [ -n "$output" ]; then
27+
echo 'Bad commit messages:'
28+
echo "$output"
29+
exit 1
30+
else
31+
echo 'All commit messages OK'
32+
fi

0 commit comments

Comments
 (0)