-
Notifications
You must be signed in to change notification settings - Fork 0
170 lines (142 loc) · 4.91 KB
/
pre-commit.yml
File metadata and controls
170 lines (142 loc) · 4.91 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# Pre-commit Validation Workflow
# Quality gates that must pass before code can be pushed
name: Pre-commit Validation
on:
push:
branches-ignore:
- main
pull_request:
types: [opened, synchronize, reopened]
env:
NODE_VERSION: "20"
PNPM_VERSION: "9"
jobs:
pre-commit-checks:
name: Pre-commit Quality Gates
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: ${{ env.PNPM_VERSION }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: "pnpm"
cache-dependency-path: "cli/pnpm-lock.yaml"
- name: Install dependencies
run: |
pnpm install --frozen-lockfile
cd cli && pnpm install --frozen-lockfile
# Gate 1: No JavaScript syntax errors
- name: Check for JavaScript errors
run: |
echo "🔍 Checking for JavaScript syntax errors..."
find cli/src cli/bin -name "*.js" -type f 2>/dev/null | while read file; do
node --check "$file" 2>&1 || {
echo "❌ Syntax error in: $file"
exit 1
}
done
echo "✅ No JavaScript syntax errors found"
# Gate 2: ESLint must pass
- name: ESLint validation
run: |
echo "🔍 Running ESLint..."
pnpm lint || {
echo "❌ ESLint found errors. Please fix them before pushing."
exit 1
}
echo "✅ ESLint passed"
# Gate 3: JSDoc comments required
- name: JSDoc validation
run: |
echo "🔍 Checking JSDoc comments..."
pnpm lint:jsdoc || {
echo "❌ JSDoc comments missing or invalid. Please add documentation."
exit 1
}
echo "✅ JSDoc validation passed"
# Gate 4: Code formatting
- name: Prettier formatting check
run: |
echo "🔍 Checking code formatting..."
pnpm format:check || {
echo "❌ Code is not properly formatted. Run 'pnpm format' to fix."
exit 1
}
echo "✅ Code formatting is correct"
# Gate 5: YAML configuration validation
- name: YAML validation
run: |
echo "🔍 Validating YAML files..."
npm install -g yaml-lint
for file in $(find .claude -name "*.yml" -o -name "*.yaml"); do
if [ -f "$file" ]; then
yamllint "$file" || {
echo "❌ Invalid YAML: $file"
exit 1
}
fi
done
echo "✅ All YAML files are valid"
# Gate 6: CLI tests pass
- name: Run CLI tests
run: |
echo "🔍 Running CLI tests..."
cd cli && pnpm test || {
echo "❌ CLI tests failed"
exit 1
}
echo "✅ CLI tests passed"
# Gate 7: Validate changed files
- name: Validate changed files
run: |
echo "🔍 Validating changed files..."
# Get list of changed files
if [ "${{ github.event_name }}" = "pull_request" ]; then
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }})
else
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD 2>/dev/null || echo "")
fi
if [ -z "$CHANGED_FILES" ]; then
echo "No changed files to validate"
exit 0
fi
echo "Changed files:"
echo "$CHANGED_FILES"
# Check for agent library changes
AGENT_CHANGES=$(echo "$CHANGED_FILES" | grep -E '^agent-library/' || true)
if [ -n "$AGENT_CHANGES" ]; then
echo "📝 Agent library files changed - validating structure"
fi
# Check for CLI changes
CLI_CHANGES=$(echo "$CHANGED_FILES" | grep -E '^cli/' || true)
if [ -n "$CLI_CHANGES" ]; then
echo "📝 CLI files changed - tests already validated"
fi
# Check for config changes
CONFIG_CHANGES=$(echo "$CHANGED_FILES" | grep -E '\.yml$|\.yaml$' || true)
if [ -n "$CONFIG_CHANGES" ]; then
echo "📝 Configuration files changed - YAML already validated"
fi
echo "✅ All changed files validated"
- name: Summary
if: success()
run: |
echo "🎉 All pre-commit checks passed!"
echo ""
echo "Summary:"
echo " ✅ JavaScript syntax valid"
echo " ✅ ESLint passed"
echo " ✅ JSDoc comments present"
echo " ✅ Code properly formatted"
echo " ✅ YAML configs valid"
echo " ✅ CLI tests passed"
echo ""
echo "Your code is ready to be merged!"