Skip to content

Commit eba21ba

Browse files
machado144claude
andcommitted
ci: add PR title conventional commit validation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5ce5028 commit eba21ba

5 files changed

Lines changed: 96 additions & 53 deletions

File tree

.github/workflows/pr.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: PR
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, synchronize, reopened]
6+
branches:
7+
- main
8+
9+
permissions:
10+
contents: read
11+
pull-requests: write
12+
13+
jobs:
14+
title:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Validate PR title follows Conventional Commits
18+
env:
19+
TITLE: ${{ github.event.pull_request.title }}
20+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
run: |
22+
if echo "$TITLE" | grep -qE "^(feat|fix|docs|style|refactor|test|chore|build|ci|perf|revert)(\(.+\))?(!)?: .+"; then
23+
echo "PR title is valid: $TITLE"
24+
exit 0
25+
fi
26+
27+
BODY=$(cat <<'COMMENT'
28+
### ⚠️ Invalid PR Title
29+
30+
PR title must follow the **Conventional Commits** format since we use squash merge:
31+
32+
```
33+
<type>[optional scope][!]: <description>
34+
```
35+
36+
**Allowed types:** `feat`, `fix`, `docs`, `style`, `refactor`, `test`, `chore`, `build`, `ci`, `perf`, `revert`
37+
38+
**Examples:**
39+
- `feat: add new feature`
40+
- `fix(api): resolve null pointer`
41+
- `feat!: breaking change`
42+
- `chore(deps): update dependencies`
43+
COMMENT
44+
)
45+
46+
# Post comment on PR
47+
gh api "repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \
48+
-X POST -f body="$BODY"
49+
50+
echo "::error::PR title must follow Conventional Commits format"
51+
exit 1
52+
53+
review:
54+
runs-on: ubuntu-latest
55+
steps:
56+
- uses: actions/checkout@v4
57+
- uses: AxeForging/reviewforge@main
58+
with:
59+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60+
AI_PROVIDER: gemini
61+
AI_MODEL: gemini-2.5-flash
62+
AI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
63+
SHOW_TOKEN_USAGE: true
64+
INCREMENTAL: false
65+
REVIEW_RULES: concise
66+
67+
validate:
68+
runs-on: ubuntu-latest
69+
steps:
70+
- uses: actions/checkout@v4
71+
- uses: AxeForging/structlint@main
72+
with:
73+
config: .structlint.yaml
74+
comment-on-pr: "true"
75+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ on:
44
workflow_dispatch:
55
inputs:
66
tag:
7-
description: 'Release tag (e.g., v1.0.0)'
8-
required: true
7+
description: 'Release tag (leave empty for auto-bump from conventional commits)'
8+
required: false
99
type: string
1010

1111
permissions:
@@ -29,10 +29,26 @@ jobs:
2929
- name: Run tests
3030
run: go test ./... -v
3131

32+
- name: Determine version
33+
id: version
34+
uses: AxeForging/releaseforge@main
35+
with:
36+
command: bump
37+
38+
- name: Set tag
39+
id: tag
40+
run: |
41+
if [ -n "${{ inputs.tag }}" ]; then
42+
echo "tag=${{ inputs.tag }}" >> "$GITHUB_OUTPUT"
43+
else
44+
echo "tag=${{ steps.version.outputs.next-version }}" >> "$GITHUB_OUTPUT"
45+
fi
46+
3247
- name: Create and push tag
3348
run: |
34-
git tag ${{ inputs.tag }}
35-
git push origin ${{ inputs.tag }}
49+
echo "Releasing ${{ steps.tag.outputs.tag }}"
50+
git tag ${{ steps.tag.outputs.tag }}
51+
git push origin ${{ steps.tag.outputs.tag }}
3652
3753
- name: Run GoReleaser
3854
uses: goreleaser/goreleaser-action@v6

.github/workflows/review.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

.github/workflows/validate.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

lefthook.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ commit-msg:
2727
run: |
2828
msg=$(cat {1})
2929
# Check for conventional commit format
30-
if ! echo "$msg" | grep -qE "^(feat|fix|docs|style|refactor|test|chore|build|ci|perf|revert)(\(.+\))?: .+"; then
30+
if ! echo "$msg" | grep -qE "^(feat|fix|docs|style|refactor|test|chore|build|ci|perf|revert)(\(.+\))?(!)?: .+"; then
3131
echo "Error: Commit message must follow conventional commits format"
3232
echo "Examples:"
3333
echo " feat: add new feature"

0 commit comments

Comments
 (0)