-
Notifications
You must be signed in to change notification settings - Fork 0
181 lines (143 loc) · 6.24 KB
/
Copy pathvalidate-rules.yml
File metadata and controls
181 lines (143 loc) · 6.24 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
name: Validate Rules
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '24'
- name: Setup PNPM
uses: pnpm/action-setup@v4
with:
version: 10.28.2
- name: Install dependencies
run: pnpm install
- name: Run linting
run: pnpm lint
- name: Validate referential integrity
run: |
#!/bin/bash
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo "🔍 Checking referential integrity..."
echo ""
# Track if any errors were found
ERRORS_FOUND=0
# Find all SKILL.md files
SKILL_FILES=$(find skills -name "SKILL.md")
for skill_file in $SKILL_FILES; do
skill_dir=$(dirname "$skill_file")
skill_name=$(basename "$skill_dir")
echo "Checking skill: $skill_name"
# Find all rule files in the rules directory
if [ -d "$skill_dir/rules" ]; then
rule_files=$(find "$skill_dir/rules" -name "*.md" -type f)
for rule_file in $rule_files; do
rule_basename=$(basename "$rule_file")
rule_name="${rule_basename%.md}"
# Check if the rule is registered in SKILL.md
if ! grep -q "(rules/$rule_basename)" "$skill_file"; then
echo -e "${RED}❌ ERROR: Rule '$rule_name' exists but is not registered in $skill_file${NC}"
ERRORS_FOUND=1
else
echo -e "${GREEN}✓${NC} $rule_name"
fi
done
fi
echo ""
done
# Check for rules referenced in SKILL.md that don't exist
for skill_file in $SKILL_FILES; do
skill_dir=$(dirname "$skill_file")
skill_name=$(basename "$skill_dir")
# Extract rule references from markdown links like [rule-name](rules/rule-name.md)
# Note: Uses grep -P (Perl regex) which is available on GitHub Actions Ubuntu runners
referenced_rules=$(grep -oP '\[.*?\]\(rules/\K[^)]+(?=\))' "$skill_file" || true)
if [ -n "$referenced_rules" ]; then
echo "Validating referenced rules in $skill_name..."
while IFS= read -r rule_ref; do
rule_path="$skill_dir/rules/$rule_ref"
if [ ! -f "$rule_path" ]; then
echo -e "${RED}❌ ERROR: Rule referenced in $skill_file does not exist: $rule_path${NC}"
ERRORS_FOUND=1
else
echo -e "${GREEN}✓${NC} $(basename $rule_ref)"
fi
done <<< "$referenced_rules"
echo ""
fi
done
# Final result
if [ $ERRORS_FOUND -eq 0 ]; then
echo -e "${GREEN}✅ All referential integrity checks passed!${NC}"
exit 0
else
echo -e "${RED}❌ Referential integrity checks failed. Please fix the errors above.${NC}"
exit 1
fi
- name: Validate YAML frontmatter
run: |
#!/bin/bash
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
echo "🔍 Validating YAML frontmatter in rule files..."
echo ""
ERRORS_FOUND=0
# Find all rule files
rule_files=$(find skills/*/rules -name "*.md" -type f)
for rule_file in $rule_files; do
# Check if file has YAML frontmatter
if ! head -n 1 "$rule_file" | grep -q "^---$"; then
echo -e "${RED}❌ ERROR: Missing YAML frontmatter in $rule_file${NC}"
ERRORS_FOUND=1
continue
fi
# Extract frontmatter
frontmatter=$(awk '/^---$/{f=!f;next}f' "$rule_file" | head -n 20)
# Check required fields
required_fields=("title" "impact" "impactDescription" "type" "tags")
for field in "${required_fields[@]}"; do
if ! echo "$frontmatter" | grep -q "^$field:"; then
echo -e "${RED}❌ ERROR: Missing required field '$field' in $rule_file${NC}"
ERRORS_FOUND=1
fi
done
# Validate impact value
impact_value=$(echo "$frontmatter" | grep "^impact:" | cut -d':' -f2 | tr -d ' ')
if [[ ! "$impact_value" =~ ^(HIGH|MEDIUM|LOW)$ ]]; then
echo -e "${RED}❌ ERROR: Invalid impact value '$impact_value' in $rule_file (must be HIGH, MEDIUM, or LOW)${NC}"
ERRORS_FOUND=1
fi
# Validate type value
type_value=$(echo "$frontmatter" | grep "^type:" | cut -d':' -f2 | tr -d ' ')
if [[ ! "$type_value" =~ ^(capability|efficiency)$ ]]; then
echo -e "${RED}❌ ERROR: Invalid type value '$type_value' in $rule_file (must be capability or efficiency)${NC}"
ERRORS_FOUND=1
fi
# Check for Impact Line after H1 (skip all blank lines)
line_after_h1=$(awk '/^# /{found=1; next} found && NF {print; exit}' "$rule_file")
if ! echo "$line_after_h1" | grep -q '^\*\*Impact:'; then
echo -e "${RED}❌ ERROR: Missing Impact Line after H1 title in $rule_file${NC}"
ERRORS_FOUND=1
fi
done
if [ $ERRORS_FOUND -eq 0 ]; then
echo -e "${GREEN}✅ All YAML frontmatter validations passed!${NC}"
exit 0
else
echo -e "${RED}❌ YAML frontmatter validation failed. Please fix the errors above.${NC}"
exit 1
fi