-
Notifications
You must be signed in to change notification settings - Fork 0
133 lines (111 loc) Β· 4.31 KB
/
commitlint.yml
File metadata and controls
133 lines (111 loc) Β· 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
name: Commit Lint
on:
pull_request:
types: [opened, edited, synchronize, reopened]
# Permissions needed to comment on PRs (including dependabot PRs)
permissions:
contents: read
pull-requests: write
jobs:
conventional-commits:
name: Validate Commit Messages
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0 # Full history for commit validation
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '20'
- name: Install commitlint
run: |
npm install -g @commitlint/cli @commitlint/config-conventional
- name: Validate PR title
run: |
PR_TITLE="${{ github.event.pull_request.title }}"
echo "$PR_TITLE" | commitlint --config .commitlintrc.json
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Validate commit messages
run: |
# Get commits in PR
git fetch origin ${{ github.base_ref }}
COMMITS=$(git log origin/${{ github.base_ref }}..HEAD --pretty=format:"%s")
echo "π Validating commits in PR..."
echo ""
# Validate each commit
EXIT_CODE=0
while IFS= read -r commit; do
echo "Checking: $commit"
if ! echo "$commit" | commitlint --config .commitlintrc.json; then
EXIT_CODE=1
fi
done <<< "$COMMITS"
if [ $EXIT_CODE -ne 0 ]; then
echo ""
echo "β Some commits don't follow Conventional Commits format!"
echo ""
echo "π Format: <type>(<scope>): <subject>"
echo ""
echo "Examples:"
echo " β
feat(devices): add SSDP auto-discovery"
echo " β
fix(api): handle null response"
echo " β
docs(readme): update installation"
echo ""
echo "Allowed types:"
echo " feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert"
exit 1
fi
echo ""
echo "β
All commits follow Conventional Commits format!"
- name: PR comment on failure
if: failure()
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `## β Commit Message Validation Failed
Your PR contains commits that don't follow the [Conventional Commits](https://www.conventionalcommits.org/) format.
### Required Format
\`\`\`
<type>(<scope>): <subject>
\`\`\`
### Examples
β
\`feat(devices): add SSDP auto-discovery\`
β
\`fix(api): handle null response in device sync\`
β
\`docs(readme): update installation instructions\`
β
\`test(backend): add regression test for XML parsing\`
### Allowed Types
- \`feat\` - New feature
- \`fix\` - Bug fix
- \`docs\` - Documentation only
- \`style\` - Code style (formatting, no logic change)
- \`refactor\` - Code refactoring (no feature/fix)
- \`perf\` - Performance improvement
- \`test\` - Adding/updating tests
- \`build\` - Build system changes
- \`ci\` - CI/CD changes
- \`chore\` - Maintenance (dependencies, etc.)
- \`revert\` - Revert previous commit
### Optional Scopes
\`devices\`, \`api\`, \`frontend\`, \`backend\`, \`docker\`, \`workflow\`
### How to Fix
**Option 1: Amend last commit**
\`\`\`bash
git commit --amend -m "feat(devices): add SSDP discovery"
git push --force-with-lease
\`\`\`
**Option 2: Interactive rebase (multiple commits)**
\`\`\`bash
git rebase -i HEAD~3 # Last 3 commits
# Mark commits as "reword" in editor
# Update commit messages
git push --force-with-lease
\`\`\`
**Need help?** Check [Conventional Commits Guide](https://www.conventionalcommits.org/)`
})