-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.sh
More file actions
executable file
·327 lines (269 loc) · 9.25 KB
/
validate.sh
File metadata and controls
executable file
·327 lines (269 loc) · 9.25 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
#!/usr/bin/env bash
#
# Claude Priority Validator - GitHub Action Script
# Validates Claude Code plugins for marketplace compliance
#
set -euo pipefail
# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Input parameters
PLUGIN_PATH="${1:-.}"
CHECK_NAMING="${2:-true}"
CHECK_JSON="${3:-true}"
CHECK_FRONTMATTER="${4:-true}"
STRICT_MODE="${5:-true}"
FAIL_ON_ERROR="${6:-true}"
# Counters
TOTAL_CHECKS=0
PASSED_CHECKS=0
FAILED_CHECKS=0
ERROR_MESSAGES=""
# GitHub Actions output
github_output() {
if [[ "${GITHUB_ACTIONS:-false}" == "true" ]] && [[ -n "${GITHUB_OUTPUT:-}" ]]; then
echo "$1" >> "$GITHUB_OUTPUT" || true
fi
}
# Print with GitHub Actions annotations
print_error() {
local message="$1"
ERROR_MESSAGES="${ERROR_MESSAGES}${message}\n"
if [[ "${GITHUB_ACTIONS:-false}" == "true" ]]; then
echo "::error::${message}"
else
echo -e "${RED}❌ ${message}${NC}"
fi
}
print_warning() {
local message="$1"
if [[ "${GITHUB_ACTIONS:-false}" == "true" ]]; then
echo "::warning::${message}"
else
echo -e "${YELLOW}⚠️ ${message}${NC}"
fi
}
print_success() {
local message="$1"
if [[ "${GITHUB_ACTIONS:-false}" == "true" ]]; then
echo "::notice::${message}"
else
echo -e "${GREEN}✅ ${message}${NC}"
fi
}
print_info() {
local message="$1"
echo -e "${BLUE}ℹ️ ${message}${NC}"
}
# Banner
echo ""
echo "╔══════════════════════════════════════════════════╗"
echo "║ Claude Priority Validator ║"
echo "║ Ensuring marketplace compliance ║"
echo "╚══════════════════════════════════════════════════╝"
echo ""
# Validate plugin path exists
if [[ ! -d "$PLUGIN_PATH" ]]; then
print_error "Plugin path does not exist: $PLUGIN_PATH"
exit 1
fi
print_info "Validating plugin at: $PLUGIN_PATH"
echo ""
# Get plugin name from path
PLUGIN_NAME=$(basename "$PLUGIN_PATH")
# ============================================================================
# Validation Functions
# ============================================================================
validate_naming_conventions() {
print_info "Checking naming conventions..."
((TOTAL_CHECKS++))
local errors=0
# Check plugin directory name
if [[ ! "$PLUGIN_NAME" =~ ^[a-z0-9-]+$ ]]; then
print_error "Plugin directory name must be lowercase-with-hyphens: $PLUGIN_NAME"
((errors++))
fi
# Check for marketplace.json
if [[ ! -f "$PLUGIN_PATH/marketplace.json" ]]; then
print_error "Missing marketplace.json in plugin root"
((errors++))
fi
# Check skills directory
if [[ -d "$PLUGIN_PATH/skills" ]]; then
while IFS= read -r -d '' skill_dir; do
skill_name=$(basename "$skill_dir")
if [[ ! "$skill_name" =~ ^[a-z0-9-]+$ ]]; then
print_error "Skill directory must be lowercase-with-hyphens: $skill_name"
((errors++))
fi
# Check for skill.md
if [[ ! -f "$skill_dir/skill.md" ]]; then
print_error "Missing skill.md in: $skill_name"
((errors++))
fi
done < <(find "$PLUGIN_PATH/skills" -mindepth 1 -maxdepth 1 -type d -print0)
fi
if [[ $errors -eq 0 ]]; then
((PASSED_CHECKS++))
print_success "Naming conventions: PASSED"
else
((FAILED_CHECKS++))
print_error "Naming conventions: FAILED ($errors errors)"
fi
echo ""
return $errors
}
validate_json_schema() {
print_info "Checking JSON schema compliance..."
((TOTAL_CHECKS++))
local errors=0
local marketplace_json="$PLUGIN_PATH/marketplace.json"
if [[ ! -f "$marketplace_json" ]]; then
print_error "marketplace.json not found"
((errors++))
((FAILED_CHECKS++))
echo ""
return $errors
fi
# Validate JSON syntax
if ! jq empty "$marketplace_json" 2>/dev/null; then
print_error "marketplace.json is not valid JSON"
((errors++))
((FAILED_CHECKS++))
echo ""
return $errors
fi
# Check required fields
local required_fields=("name" "version" "description" "author")
for field in "${required_fields[@]}"; do
if ! jq -e ".$field" "$marketplace_json" >/dev/null 2>&1; then
print_error "marketplace.json missing required field: $field"
((errors++))
fi
done
# Validate version format (semantic versioning)
local version
version=$(jq -r '.version // ""' "$marketplace_json")
if [[ -n "$version" ]] && [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
print_error "Version must follow semantic versioning (x.y.z): $version"
((errors++))
fi
# Validate skills array
if jq -e '.skills' "$marketplace_json" >/dev/null 2>&1; then
if [[ $(jq -r '.skills | type' "$marketplace_json") != "array" ]]; then
print_error "skills must be an array in marketplace.json"
((errors++))
fi
fi
if [[ $errors -eq 0 ]]; then
((PASSED_CHECKS++))
print_success "JSON schema: PASSED"
else
((FAILED_CHECKS++))
print_error "JSON schema: FAILED ($errors errors)"
fi
echo ""
return $errors
}
validate_frontmatter() {
print_info "Checking YAML frontmatter format..."
((TOTAL_CHECKS++))
local errors=0
# Find all skill.md files
if [[ -d "$PLUGIN_PATH/skills" ]]; then
while IFS= read -r -d '' skill_file; do
skill_name=$(basename "$(dirname "$skill_file")")
# Check for frontmatter
if ! grep -q "^---$" "$skill_file"; then
print_error "Missing frontmatter in skill: $skill_name"
((errors++))
continue
fi
# Extract frontmatter
local frontmatter
frontmatter=$(sed -n '/^---$/,/^---$/p' "$skill_file" | sed '1d;$d')
if [[ -z "$frontmatter" ]]; then
print_error "Empty frontmatter in skill: $skill_name"
((errors++))
continue
fi
# Check for required fields
if ! echo "$frontmatter" | grep -q "^name:"; then
print_error "Missing 'name' in frontmatter: $skill_name"
((errors++))
fi
if ! echo "$frontmatter" | grep -q "^description:"; then
print_error "Missing 'description' in frontmatter: $skill_name"
((errors++))
fi
done < <(find "$PLUGIN_PATH/skills" -name "skill.md" -print0)
fi
if [[ $errors -eq 0 ]]; then
((PASSED_CHECKS++))
print_success "Frontmatter format: PASSED"
else
((FAILED_CHECKS++))
print_error "Frontmatter format: FAILED ($errors errors)"
fi
echo ""
return $errors
}
# ============================================================================
# Run Validations
# ============================================================================
VALIDATION_FAILED=0
if [[ "$CHECK_NAMING" == "true" ]]; then
validate_naming_conventions || VALIDATION_FAILED=1
fi
if [[ "$CHECK_JSON" == "true" ]]; then
validate_json_schema || VALIDATION_FAILED=1
fi
if [[ "$CHECK_FRONTMATTER" == "true" ]]; then
validate_frontmatter || VALIDATION_FAILED=1
fi
# ============================================================================
# Summary
# ============================================================================
echo "══════════════════════════════════════════════════"
echo "Validation Summary"
echo "══════════════════════════════════════════════════"
echo "Total checks: $TOTAL_CHECKS"
echo "Passed: $PASSED_CHECKS"
echo "Failed: $FAILED_CHECKS"
echo "══════════════════════════════════════════════════"
echo ""
# Set GitHub Actions outputs
if [[ "${GITHUB_ACTIONS:-false}" == "true" ]] && [[ -n "${GITHUB_OUTPUT:-}" ]]; then
# Determine status
if [[ $VALIDATION_FAILED -eq 0 ]]; then
VALIDATION_STATUS="pass"
else
VALIDATION_STATUS="fail"
fi
{
echo "validation-status=$VALIDATION_STATUS"
echo "total-checks=$TOTAL_CHECKS"
echo "passed-checks=$PASSED_CHECKS"
echo "failed-checks=$FAILED_CHECKS"
echo "error-messages<<EOF"
echo -e "$ERROR_MESSAGES"
echo "EOF"
} >> "$GITHUB_OUTPUT" || true
fi
# Final result
if [[ $VALIDATION_FAILED -eq 0 ]]; then
print_success "All validation checks passed! 🎉"
echo ""
exit 0
fi
# If we get here, validation failed
print_error "Validation failed with $FAILED_CHECKS failed checks"
echo ""
if [[ "$FAIL_ON_ERROR" == "true" ]]; then
exit 1
fi
print_warning "Continuing despite errors (fail-on-error is false)"
exit 0