|
| 1 | +name: Validate Rules |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, develop] |
| 6 | + pull_request: |
| 7 | + branches: [main, develop] |
| 8 | + |
| 9 | +jobs: |
| 10 | + validate: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + steps: |
| 14 | + - name: Checkout code |
| 15 | + uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Setup Node.js |
| 18 | + uses: actions/setup-node@v4 |
| 19 | + with: |
| 20 | + node-version: '20' |
| 21 | + |
| 22 | + - name: Setup PNPM |
| 23 | + uses: pnpm/action-setup@v4 |
| 24 | + with: |
| 25 | + version: 10.28.1 |
| 26 | + |
| 27 | + - name: Install dependencies |
| 28 | + run: pnpm install |
| 29 | + |
| 30 | + - name: Run linting |
| 31 | + run: pnpm lint |
| 32 | + |
| 33 | + - name: Validate referential integrity |
| 34 | + run: | |
| 35 | + #!/bin/bash |
| 36 | + |
| 37 | + # Colors for output |
| 38 | + RED='\033[0;31m' |
| 39 | + GREEN='\033[0;32m' |
| 40 | + YELLOW='\033[1;33m' |
| 41 | + NC='\033[0m' # No Color |
| 42 | + |
| 43 | + echo "🔍 Checking referential integrity..." |
| 44 | + echo "" |
| 45 | + |
| 46 | + # Track if any errors were found |
| 47 | + ERRORS_FOUND=0 |
| 48 | + |
| 49 | + # Find all SKILL.md files |
| 50 | + SKILL_FILES=$(find skills -name "SKILL.md") |
| 51 | + |
| 52 | + for skill_file in $SKILL_FILES; do |
| 53 | + skill_dir=$(dirname "$skill_file") |
| 54 | + skill_name=$(basename "$skill_dir") |
| 55 | + |
| 56 | + echo "Checking skill: $skill_name" |
| 57 | + |
| 58 | + # Find all rule files in the rules directory |
| 59 | + if [ -d "$skill_dir/rules" ]; then |
| 60 | + rule_files=$(find "$skill_dir/rules" -name "*.md" -type f) |
| 61 | + |
| 62 | + for rule_file in $rule_files; do |
| 63 | + rule_basename=$(basename "$rule_file") |
| 64 | + rule_name="${rule_basename%.md}" |
| 65 | + |
| 66 | + # Check if the rule is registered in SKILL.md |
| 67 | + if ! grep -q "(rules/$rule_basename)" "$skill_file"; then |
| 68 | + echo -e "${RED}❌ ERROR: Rule '$rule_name' exists but is not registered in $skill_file${NC}" |
| 69 | + ERRORS_FOUND=1 |
| 70 | + else |
| 71 | + echo -e "${GREEN}✓${NC} $rule_name" |
| 72 | + fi |
| 73 | + done |
| 74 | + fi |
| 75 | + |
| 76 | + echo "" |
| 77 | + done |
| 78 | + |
| 79 | + # Check for rules referenced in SKILL.md that don't exist |
| 80 | + for skill_file in $SKILL_FILES; do |
| 81 | + skill_dir=$(dirname "$skill_file") |
| 82 | + skill_name=$(basename "$skill_dir") |
| 83 | + |
| 84 | + # Extract rule references from markdown links like [rule-name](rules/rule-name.md) |
| 85 | + # Note: Uses grep -P (Perl regex) which is available on GitHub Actions Ubuntu runners |
| 86 | + referenced_rules=$(grep -oP '\[.*?\]\(rules/\K[^)]+(?=\))' "$skill_file" || true) |
| 87 | + |
| 88 | + if [ -n "$referenced_rules" ]; then |
| 89 | + echo "Validating referenced rules in $skill_name..." |
| 90 | + |
| 91 | + while IFS= read -r rule_ref; do |
| 92 | + rule_path="$skill_dir/rules/$rule_ref" |
| 93 | + |
| 94 | + if [ ! -f "$rule_path" ]; then |
| 95 | + echo -e "${RED}❌ ERROR: Rule referenced in $skill_file does not exist: $rule_path${NC}" |
| 96 | + ERRORS_FOUND=1 |
| 97 | + else |
| 98 | + echo -e "${GREEN}✓${NC} $(basename $rule_ref)" |
| 99 | + fi |
| 100 | + done <<< "$referenced_rules" |
| 101 | + |
| 102 | + echo "" |
| 103 | + fi |
| 104 | + done |
| 105 | + |
| 106 | + # Final result |
| 107 | + if [ $ERRORS_FOUND -eq 0 ]; then |
| 108 | + echo -e "${GREEN}✅ All referential integrity checks passed!${NC}" |
| 109 | + exit 0 |
| 110 | + else |
| 111 | + echo -e "${RED}❌ Referential integrity checks failed. Please fix the errors above.${NC}" |
| 112 | + exit 1 |
| 113 | + fi |
| 114 | +
|
| 115 | + - name: Validate YAML frontmatter |
| 116 | + run: | |
| 117 | + #!/bin/bash |
| 118 | + |
| 119 | + # Colors for output |
| 120 | + RED='\033[0;31m' |
| 121 | + GREEN='\033[0;32m' |
| 122 | + NC='\033[0m' |
| 123 | + |
| 124 | + echo "🔍 Validating YAML frontmatter in rule files..." |
| 125 | + echo "" |
| 126 | + |
| 127 | + ERRORS_FOUND=0 |
| 128 | + |
| 129 | + # Find all rule files |
| 130 | + rule_files=$(find skills/*/rules -name "*.md" -type f) |
| 131 | + |
| 132 | + for rule_file in $rule_files; do |
| 133 | + # Check if file has YAML frontmatter |
| 134 | + if ! head -n 1 "$rule_file" | grep -q "^---$"; then |
| 135 | + echo -e "${RED}❌ ERROR: Missing YAML frontmatter in $rule_file${NC}" |
| 136 | + ERRORS_FOUND=1 |
| 137 | + continue |
| 138 | + fi |
| 139 | + |
| 140 | + # Extract frontmatter |
| 141 | + frontmatter=$(awk '/^---$/{f=!f;next}f' "$rule_file" | head -n 20) |
| 142 | + |
| 143 | + # Check required fields |
| 144 | + required_fields=("title" "impact" "impactDescription" "type" "tags") |
| 145 | + |
| 146 | + for field in "${required_fields[@]}"; do |
| 147 | + if ! echo "$frontmatter" | grep -q "^$field:"; then |
| 148 | + echo -e "${RED}❌ ERROR: Missing required field '$field' in $rule_file${NC}" |
| 149 | + ERRORS_FOUND=1 |
| 150 | + fi |
| 151 | + done |
| 152 | + |
| 153 | + # Validate impact value |
| 154 | + impact_value=$(echo "$frontmatter" | grep "^impact:" | cut -d':' -f2 | tr -d ' ') |
| 155 | + if [[ ! "$impact_value" =~ ^(HIGH|MEDIUM|LOW)$ ]]; then |
| 156 | + echo -e "${RED}❌ ERROR: Invalid impact value '$impact_value' in $rule_file (must be HIGH, MEDIUM, or LOW)${NC}" |
| 157 | + ERRORS_FOUND=1 |
| 158 | + fi |
| 159 | + |
| 160 | + # Validate type value |
| 161 | + type_value=$(echo "$frontmatter" | grep "^type:" | cut -d':' -f2 | tr -d ' ') |
| 162 | + if [[ ! "$type_value" =~ ^(capability|efficiency)$ ]]; then |
| 163 | + echo -e "${RED}❌ ERROR: Invalid type value '$type_value' in $rule_file (must be capability or efficiency)${NC}" |
| 164 | + ERRORS_FOUND=1 |
| 165 | + fi |
| 166 | + |
| 167 | + # Check for Impact Line after H1 (skip all blank lines) |
| 168 | + line_after_h1=$(awk '/^# /{found=1; next} found && NF {print; exit}' "$rule_file") |
| 169 | + if ! echo "$line_after_h1" | grep -q '^\*\*Impact:'; then |
| 170 | + echo -e "${RED}❌ ERROR: Missing Impact Line after H1 title in $rule_file${NC}" |
| 171 | + ERRORS_FOUND=1 |
| 172 | + fi |
| 173 | + done |
| 174 | + |
| 175 | + if [ $ERRORS_FOUND -eq 0 ]; then |
| 176 | + echo -e "${GREEN}✅ All YAML frontmatter validations passed!${NC}" |
| 177 | + exit 0 |
| 178 | + else |
| 179 | + echo -e "${RED}❌ YAML frontmatter validation failed. Please fix the errors above.${NC}" |
| 180 | + exit 1 |
| 181 | + fi |
0 commit comments