-
Notifications
You must be signed in to change notification settings - Fork 0
114 lines (91 loc) · 4.27 KB
/
commit-limits.yml
File metadata and controls
114 lines (91 loc) · 4.27 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
name: Commit Limits
on:
pull_request:
types: [opened, synchronize, reopened]
push:
branches: [main, dev]
jobs:
lint-commits:
name: Check commit sizes and branch naming
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check branch naming convention
if: github.event_name == 'pull_request'
run: |
branch_name="${{ github.head_ref }}"
# Define valid branch prefixes
valid_prefixes="feat|fix|docs|style|refactor|test|chore|perf|ci|build|revert"
# Check if branch follows naming convention
if ! echo "$branch_name" | grep -E "^($valid_prefixes)/" > /dev/null; then
echo "❌ Branch name '$branch_name' doesn't follow naming convention"
echo "Branch names must start with one of: feat/, fix/, docs/, style/, refactor/, test/, chore/, perf/, ci/, build/, revert/"
exit 1
fi
echo "✅ Branch name follows convention"
- name: Check commit sizes
run: |
# For PRs, check all commits in the PR
if [ "${{ github.event_name }}" == "pull_request" ]; then
commits=$(git rev-list ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }})
else
# For pushes, just check the latest commit
commits=$(git rev-parse HEAD)
fi
failed=false
for commit in $commits; do
echo "Checking commit $commit"
# Get commit stats
files_changed=$(git diff-tree --no-commit-id --name-only -r $commit | wc -l)
lines_added=$(git diff-tree --no-commit-id --numstat -r $commit | awk '{sum+=$1} END {print sum}')
lines_deleted=$(git diff-tree --no-commit-id --numstat -r $commit | awk '{sum+=$2} END {print sum}')
total_lines=$((lines_added + lines_deleted))
echo " Files changed: $files_changed"
echo " Lines added: $lines_added"
echo " Lines deleted: $lines_deleted"
echo " Total lines changed: $total_lines"
# Check limits
if [ "$files_changed" -gt 30 ]; then
echo "❌ Commit changes too many files: $files_changed (max: 30)"
failed=true
fi
if [ "$total_lines" -gt 800 ]; then
echo "❌ Commit changes too many lines: $total_lines (max: 800)"
failed=true
fi
# Check for generated files (relaxed for initial setup)
if git diff-tree --no-commit-id --name-only -r $commit | grep -E "(Package\.resolved|\.pbxproj|\.xcodeproj)" > /dev/null; then
echo "⚠️ Warning: Commit includes generated files (allowed during setup phase)"
fi
done
if [ "$failed" = true ]; then
echo ""
echo "🚫 One or more commits exceed size limits"
echo "Please break large changes into smaller, focused commits"
exit 1
fi
echo ""
echo "✅ All commits within size limits"
- name: Check commit messages
if: github.event_name == 'pull_request'
run: |
# Check commit message format
commits=$(git rev-list ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }})
failed=false
for commit in $commits; do
message=$(git log --format=%s -n 1 $commit)
# Check conventional commit format
if ! echo "$message" | grep -E "^(feat|fix|docs|style|refactor|test|chore|perf|ci|build|revert)(\(.+\))?: .+" > /dev/null; then
echo "❌ Commit message doesn't follow conventional format: $message"
echo "Expected format: type(scope): description"
echo "Example: feat(inventory): add item search functionality"
failed=true
fi
done
if [ "$failed" = true ]; then
exit 1
fi
echo "✅ All commit messages follow convention"