forked from boundlessfi/boundless
-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (109 loc) Β· 4.29 KB
/
pre-commit-validation.yml
File metadata and controls
132 lines (109 loc) Β· 4.29 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
name: Pre-commit Hook Validation
on:
push:
branches: [main, develop, staging]
pull_request:
branches: [main, develop, staging]
jobs:
validate-pre-commit:
name: Validate Pre-commit Hooks
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for bypassed commits
run: |
echo "π Checking for bypassed pre-commit hooks..."
# Get recent commits
commits=$(git log --oneline -10)
# Check for emergency bypass commits
bypass_commits=$(echo "$commits" | grep -i "emergency.*bypass\|no-verify\|skip.*hook" || true)
if [ -n "$bypass_commits" ]; then
echo "β οΈ Found commits that bypassed pre-commit hooks:"
echo "$bypass_commits"
echo ""
echo "β Emergency bypasses are not allowed in protected branches."
echo "Please fix the issues and commit properly."
exit 1
else
echo "β
No bypassed commits found."
fi
- name: Validate commit message format
run: |
echo "π Validating commit message format..."
# Conventional commit regex
commit_regex='^(feat|fix|docs|style|refactor|test|chore|perf|ci|build|revert)(\(.+\))?: .{1,50}'
# Get commits in this push/PR
if [ "$GITHUB_EVENT_NAME" = "push" ]; then
commits=$(git log --pretty=format:"%s" ${{ github.event.before }}..${{ github.event.after }})
else
commits=$(git log --pretty=format:"%s" origin/main..HEAD)
fi
invalid_commits=""
while IFS= read -r message; do
if [ -n "$message" ] && ! echo "$message" | grep -qE "$commit_regex"; then
invalid_commits="$invalid_commits\n$message"
fi
done <<< "$commits"
if [ -n "$invalid_commits" ]; then
echo "β Invalid commit messages found:"
echo -e "$invalid_commits"
echo ""
echo "β
Please use conventional commit format:"
echo " <type>(<scope>): <description>"
exit 1
else
echo "β
All commit messages follow conventional format."
fi
- name: Check for console.log statements
run: |
echo "π Checking for console.log statements..."
# Get changed files
if [ "$GITHUB_EVENT_NAME" = "push" ]; then
changed_files=$(git diff --name-only ${{ github.event.before }}..${{ github.event.after }})
else
changed_files=$(git diff --name-only origin/main..HEAD)
fi
console_log_found=false
for file in $changed_files; do
if [[ "$file" =~ \.(ts|tsx|js|jsx)$ ]]; then
if grep -q "console\.log" "$file"; then
echo "β Found console.log in $file"
console_log_found=true
fi
fi
done
if [ "$console_log_found" = true ]; then
echo "β Console.log statements found in changed files."
echo "Please remove them before committing."
exit 1
else
echo "β
No console.log statements found in changed files."
fi
- name: Check for TODO/FIXME comments
run: |
echo "π Checking for TODO/FIXME comments..."
# Get changed files
if [ "$GITHUB_EVENT_NAME" = "push" ]; then
changed_files=$(git diff --name-only ${{ github.event.before }}..${{ github.event.after }})
else
changed_files=$(git diff --name-only origin/main..HEAD)
fi
todo_found=false
for file in $changed_files; do
if [[ "$file" =~ \.(ts|tsx|js|jsx)$ ]]; then
if grep -q "TODO\|FIXME" "$file"; then
echo "β οΈ Found TODO/FIXME in $file"
todo_found=true
fi
fi
done
if [ "$todo_found" = true ]; then
echo "β οΈ TODO/FIXME comments found in changed files."
echo "Please address them before merging."
# Don't fail the build, just warn
else
echo "β
No TODO/FIXME comments found in changed files."
fi