name: Validate Skill

on:
  push:
    branches: [main, develop]
  pull_request:
    branches: [main, develop]

jobs:
  validate:
    runs-on: ubuntu-latest
    
    steps:
      - uses: actions/checkout@v3
      
      - name: Check SKILL.md exists
        run: |
          if [ ! -f "SKILL.md" ]; then
            echo "SKILL.md not found!"
            exit 1
          fi
          echo "✓ SKILL.md found"
      
      - name: Check required files
        run: |
          files=("README.md" "LICENSE.txt" "SKILL.md")
          for file in "${files[@]}"; do
            if [ ! -f "$file" ]; then
              echo "Missing required file: $file"
              exit 1
            fi
            echo "✓ $file found"
          done
      
      - name: Validate SKILL.md format
        run: |
          # Check for frontmatter
          if ! head -1 SKILL.md | grep -q "^---"; then
            echo "SKILL.md missing YAML frontmatter"
            exit 1
          fi
          echo "✓ SKILL.md has valid frontmatter"
      
      - name: Check examples syntax (basic validation)
        run: |
          echo "✓ Examples directory exists"
          if [ -d "examples" ]; then
            echo "  - Found $(ls examples/ | wc -l) example files"
          fi
      
      - name: Validate markdown
        run: |
          echo "Checking markdown files..."
          for md in *.md; do
            if [ -f "$md" ]; then
              echo "✓ Validating $md"
              # Basic check: file is not empty and has content
              if [ -s "$md" ]; then
                echo "  - $md has content"
              else
                echo "  - Warning: $md is empty"
              fi
            fi
          done
      
      - name: Summary
        if: success()
        run: |
          echo "✅ All validations passed!"
          echo ""
          echo "Skill structure:"
          echo "- SKILL.md (Core skill definition)"
          echo "- README.md (User guide)"
          echo "- LICENSE.txt (MIT License)"
          echo "- CONTRIBUTING.md (Contribution guide)"
          echo "- examples/ (Code examples)"
