-
Notifications
You must be signed in to change notification settings - Fork 5
360 lines (297 loc) · 11.2 KB
/
Copy pathpr-checks.yml
File metadata and controls
360 lines (297 loc) · 11.2 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
name: PR Quality Gates
on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: read
pull-requests: write
checks: write
jobs:
# PR metadata validation
pr-validation:
name: Validate PR Metadata
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate PR title
uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
types: |
feat
fix
docs
refactor
test
chore
release
requireScope: false
- name: Check PR description
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pr = context.payload.pull_request;
if (!pr.body || pr.body.trim().length === 0) {
core.setFailed('PR description is required');
return;
}
if (pr.body.trim().length < 20) {
core.setFailed('PR description is too short (minimum 20 characters)');
return;
}
console.log('✓ PR description is valid');
# Check what files changed
detect-changes:
name: Detect Changes
runs-on: ubuntu-latest
outputs:
agents: ${{ steps.filter.outputs.agents }}
workflows: ${{ steps.filter.outputs.workflows }}
docs: ${{ steps.filter.outputs.docs }}
config: ${{ steps.filter.outputs.config }}
version: ${{ steps.filter.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Detect file changes
uses: dorny/paths-filter@v2
id: filter
with:
filters: |
agents:
- '.claude/agents/**/*.md'
workflows:
- '.claude/commands/**/*.md'
docs:
- 'README.md'
- 'ARCHITECTURE.md'
- 'CLAUDE.md'
- '.claude/CHANGELOG.md'
- '.claude/CLAUDE.md'
config:
- '.claude/plugin.json'
- '.claude-plugin/marketplace.json'
version:
- '.claude/VERSION'
- '.claude/plugin.json'
- '.claude-plugin/marketplace.json'
# Validate new/modified agents
validate-agents:
name: Validate Agent Changes
runs-on: ubuntu-latest
needs: detect-changes
if: needs.detect-changes.outputs.agents == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed agent files
id: changed-files
run: |
git diff --name-only origin/${{ github.base_ref }}...HEAD | \
grep '.claude/agents/.*\.md$' > changed-agents.txt || true
if [ -s changed-agents.txt ]; then
echo "Changed agents:"
cat changed-agents.txt
else
echo "No agent files changed"
fi
- name: Validate agent frontmatter
run: |
if [ ! -s changed-agents.txt ]; then
echo "No agents to validate"
exit 0
fi
echo "Validating changed agents..."
while IFS= read -r file; do
echo "Checking $file..."
# Check frontmatter exists
if ! head -n 1 "$file" | grep -q "^---$"; then
echo "ERROR: Missing frontmatter in $file"
exit 1
fi
# Extract and validate required fields
if ! grep -A 20 "^---$" "$file" | grep -q "name:"; then
echo "ERROR: Missing 'name' field in $file"
exit 1
fi
if ! grep -A 20 "^---$" "$file" | grep -q "description:"; then
echo "ERROR: Missing 'description' field in $file"
exit 1
fi
if ! grep -A 20 "^---$" "$file" | grep -q "model:"; then
echo "WARNING: Missing 'model' field in $file (will use default)"
fi
echo "✓ $file is valid"
done < changed-agents.txt
echo "✓ All changed agents are valid"
- name: Check agent documentation quality
run: |
if [ ! -s changed-agents.txt ]; then
exit 0
fi
echo "Checking documentation quality..."
while IFS= read -r file; do
# Count lines (excluding frontmatter)
line_count=$(tail -n +10 "$file" | wc -l)
if [ "$line_count" -lt 50 ]; then
echo "WARNING: $file has less than 50 lines of documentation"
fi
# Check for code examples (looking for ``` blocks)
example_count=$(grep -c '```' "$file" || true)
if [ "$example_count" -lt 2 ]; then
echo "WARNING: $file has few or no code examples (found $example_count)"
fi
done < changed-agents.txt
echo "✓ Documentation quality check complete"
# Validate new/modified workflows
validate-workflows:
name: Validate Workflow Changes
runs-on: ubuntu-latest
needs: detect-changes
if: needs.detect-changes.outputs.workflows == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed workflow files
run: |
git diff --name-only origin/${{ github.base_ref }}...HEAD | \
grep '.claude/commands/.*\.md$' > changed-workflows.txt || true
if [ -s changed-workflows.txt ]; then
echo "Changed workflows:"
cat changed-workflows.txt
fi
- name: Validate workflow frontmatter
run: |
if [ ! -s changed-workflows.txt ]; then
echo "No workflows to validate"
exit 0
fi
while IFS= read -r file; do
echo "Checking $file..."
if ! head -n 1 "$file" | grep -q "^---$"; then
echo "ERROR: Missing frontmatter in $file"
exit 1
fi
if ! grep -A 10 "^---$" "$file" | grep -q "description:"; then
echo "ERROR: Missing 'description' field in $file"
exit 1
fi
echo "✓ $file is valid"
done < changed-workflows.txt
echo "✓ All changed workflows are valid"
# Validate version changes
validate-version-change:
name: Validate Version Changes
runs-on: ubuntu-latest
needs: detect-changes
if: needs.detect-changes.outputs.version == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install jq
run: sudo apt-get update && sudo apt-get install -y jq
- name: Check version consistency
run: |
echo "Checking version consistency..."
VERSION_FILE=$(cat .claude/VERSION | tr -d '\n')
PLUGIN_VERSION=$(jq -r '.version' .claude/plugin.json)
MARKETPLACE_META=$(jq -r '.metadata.version' .claude-plugin/marketplace.json)
MARKETPLACE_PLUGIN=$(jq -r '.plugins[0].version' .claude-plugin/marketplace.json)
echo "VERSION file: $VERSION_FILE"
echo "plugin.json: $PLUGIN_VERSION"
echo "marketplace.json (metadata): $MARKETPLACE_META"
echo "marketplace.json (plugins[0]): $MARKETPLACE_PLUGIN"
errors=0
if [ "$VERSION_FILE" != "$PLUGIN_VERSION" ]; then
echo "ERROR: Version mismatch between VERSION and plugin.json"
errors=$((errors + 1))
fi
if [ "$VERSION_FILE" != "$MARKETPLACE_META" ]; then
echo "ERROR: Version mismatch between VERSION and marketplace.json metadata"
errors=$((errors + 1))
fi
if [ "$VERSION_FILE" != "$MARKETPLACE_PLUGIN" ]; then
echo "ERROR: Version mismatch between VERSION and marketplace.json plugins[0]"
errors=$((errors + 1))
fi
if [ $errors -gt 0 ]; then
echo ""
echo "❌ Version consistency check failed!"
echo "All version files must match. Please update:"
echo " - .claude/VERSION"
echo " - .claude/plugin.json (version field)"
echo " - .claude-plugin/marketplace.json (metadata.version)"
echo " - .claude-plugin/marketplace.json (plugins[0].version)"
exit 1
fi
echo "✓ All version files are consistent"
- name: Check CHANGELOG updated
run: |
VERSION=$(cat .claude/VERSION | tr -d '\n')
if ! grep -q "## \[$VERSION\]" .claude/CHANGELOG.md; then
echo "ERROR: CHANGELOG.md must have entry for version $VERSION"
echo "Add: ## [$VERSION] - $(date +%Y-%m-%d)"
exit 1
fi
echo "✓ CHANGELOG has entry for version $VERSION"
# Comment on PR with validation results
pr-comment:
name: Post PR Comment
runs-on: ubuntu-latest
needs: [pr-validation, detect-changes, validate-agents, validate-workflows, validate-version-change]
if: always()
steps:
- name: Post validation summary
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const needs = ${{ toJSON(needs) }};
const allPassed = Object.values(needs).every(job =>
job.result === 'success' || job.result === 'skipped'
);
let comment = '## 🤖 PR Quality Gates\n\n';
// PR Validation
const prValidation = needs['pr-validation'];
comment += `- ${prValidation.result === 'success' ? '✅' : '❌'} PR Metadata Validation\n`;
// Agent validation
if (needs['detect-changes'].outputs.agents === 'true') {
const agentValidation = needs['validate-agents'];
comment += `- ${agentValidation.result === 'success' ? '✅' : '❌'} Agent Changes Validation\n`;
}
// Workflow validation
if (needs['detect-changes'].outputs.workflows === 'true') {
const workflowValidation = needs['validate-workflows'];
comment += `- ${workflowValidation.result === 'success' ? '✅' : '❌'} Workflow Changes Validation\n`;
}
// Version validation
if (needs['detect-changes'].outputs.version === 'true') {
const versionValidation = needs['validate-version-change'];
comment += `- ${versionValidation.result === 'success' ? '✅' : '❌'} Version Consistency Check\n`;
}
comment += '\n';
if (allPassed) {
comment += '✅ **All quality gates passed!** This PR is ready for review.\n';
} else {
comment += '❌ **Some quality gates failed.** Please review the checks above.\n';
}
// Post comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: comment
});