Skip to content

Commit 1bb8ce1

Browse files
committed
chore(github): add commit message guard
1 parent cb88101 commit 1bb8ce1

2 files changed

Lines changed: 110 additions & 0 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Commit Message Check
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- synchronize
8+
- reopened
9+
- edited
10+
push:
11+
branches-ignore:
12+
- main
13+
14+
jobs:
15+
conventional-commits:
16+
name: conventional-commits
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Validate commit messages
26+
env:
27+
EVENT_NAME: ${{ github.event_name }}
28+
BEFORE_SHA: ${{ github.event.before }}
29+
AFTER_SHA: ${{ github.sha }}
30+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
31+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
32+
run: |
33+
set -euo pipefail
34+
35+
regex='^(feat|fix|refactor|test|docs|chore|perf|style|revert)(\([a-z0-9][a-z0-9._/-]*\))?(!)?: [^ ].*[^.]$'
36+
37+
if [ "$EVENT_NAME" = "pull_request" ]; then
38+
range="${BASE_SHA}..${HEAD_SHA}"
39+
else
40+
if [ "${BEFORE_SHA}" = "0000000000000000000000000000000000000000" ]; then
41+
range="${AFTER_SHA}"
42+
else
43+
range="${BEFORE_SHA}..${AFTER_SHA}"
44+
fi
45+
fi
46+
47+
echo "Validating commits in range: ${range}"
48+
49+
invalid=0
50+
51+
while IFS=$'\t' read -r sha subject; do
52+
if [ -z "${sha}" ]; then
53+
continue
54+
fi
55+
56+
if [[ "${subject}" =~ ^Merge[[:space:]] ]]; then
57+
continue
58+
fi
59+
60+
if [[ ! "${subject}" =~ ${regex} ]]; then
61+
echo "Invalid commit message: ${sha} ${subject}"
62+
invalid=1
63+
fi
64+
done < <(git log --format='%H%x09%s' "${range}")
65+
66+
if [ "${invalid}" -ne 0 ]; then
67+
echo "Commit message validation failed. Use Conventional Commits."
68+
exit 1
69+
fi
70+
71+
echo "All commit messages passed Conventional Commit validation."

AGENTS.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,42 @@ Before committing:
8282

8383
- run `jq empty models/*.json` and, if applicable, `jq empty providers/**/*.json`
8484
- keep `README.md` in sync with the supported models actually present in the repository
85+
86+
## Git workflow
87+
88+
- Direct pushes to `main` are prohibited.
89+
- All changes must go through a feature branch and Pull Request.
90+
- Keep commits focused and reviewable.
91+
92+
## Commit messages
93+
94+
Use Conventional Commits.
95+
96+
Format:
97+
98+
`<type>[optional scope]: <description>`
99+
100+
Allowed types:
101+
102+
- `feat`
103+
- `fix`
104+
- `refactor`
105+
- `test`
106+
- `docs`
107+
- `chore`
108+
- `perf`
109+
- `style`
110+
- `revert`
111+
112+
Rules:
113+
114+
- use imperative mood
115+
- keep the subject concise
116+
- do not end the subject with a period
117+
- use a scope when it improves clarity, for example `models`, `readme`, `registry`, or `github`
118+
119+
Examples:
120+
121+
- `feat(models): add gpt-5.3-codex defaults`
122+
- `docs(readme): update supported models table`
123+
- `chore(github): add commit message workflow`

0 commit comments

Comments
 (0)