summaryrefslogtreecommitdiff
path: root/.github/workflows/validate.yml
blob: fb83c6b01e56124d67fed05914120ca31143901c (plain)
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
name: Validate

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

permissions:
  contents: read

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  validate:
    name: Validate plugins and skills
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd  # v6.0.2
        with:
          persist-credentials: false

      - name: Validate JSON files
        run: |
          echo "Validating marketplace.json..."
          python3 -m json.tool .claude-plugin/marketplace.json > /dev/null

          echo "Validating plugin.json files..."
          for f in plugins/*/.claude-plugin/plugin.json; do
            echo "  Checking $f"
            python3 -m json.tool "$f" > /dev/null
          done

      - name: Check marketplace consistency
        run: |
          echo "Checking all marketplace plugins have directories..."
          python3 -c "
          import json
          import os
          import sys

          with open('.claude-plugin/marketplace.json') as f:
              marketplace = json.load(f)

          errors = []
          for plugin in marketplace['plugins']:
              name = plugin['name']
              source = plugin['source']
              # source is like ./plugins/name
              path = source.lstrip('./')
              if not os.path.isdir(path):
                  errors.append(f'Plugin {name}: directory {path} not found')

              plugin_json = os.path.join(path, '.claude-plugin', 'plugin.json')
              if not os.path.isfile(plugin_json):
                  errors.append(f'Plugin {name}: missing {plugin_json}')

          if errors:
              for e in errors:
                  print(f'ERROR: {e}', file=sys.stderr)
              sys.exit(1)

          print(f'All {len(marketplace[\"plugins\"])} plugins validated')
          "

      - name: Validate SKILL.md frontmatter
        run: |
          echo "Checking SKILL.md frontmatter..."
          python3 -c "
          import os
          import re
          import sys

          errors = []
          skill_count = 0

          for root, dirs, files in os.walk('plugins'):
              for f in files:
                  if f == 'SKILL.md':
                      path = os.path.join(root, f)
                      skill_count += 1
                      with open(path) as fp:
                          content = fp.read()

                      # Check for frontmatter
                      if not content.startswith('---'):
                          errors.append(f'{path}: missing YAML frontmatter')
                          continue

                      # Extract frontmatter
                      match = re.match(r'^---\n(.*?)\n---', content, re.DOTALL)
                      if not match:
                          errors.append(f'{path}: malformed frontmatter')
                          continue

                      frontmatter = match.group(1)

                      # Check for required fields
                      if 'name:' not in frontmatter:
                          errors.append(f'{path}: missing \"name\" in frontmatter')
                      if 'description:' not in frontmatter:
                          errors.append(f'{path}: missing \"description\" in frontmatter')

          if errors:
              for e in errors:
                  print(f'ERROR: {e}', file=sys.stderr)
              sys.exit(1)

          print(f'All {skill_count} SKILL.md files have valid frontmatter')
          "

      - name: Check for hardcoded paths
        run: |
          echo "Checking for hardcoded user paths..."
          if grep -rE '/home/[a-z]|/Users/[A-Z]' plugins/ --include='*.md' --include='*.py' --include='*.json' | grep -v '/path/to'; then
            echo "ERROR: Found hardcoded user paths (see above)"
            exit 1
          fi
          echo "No hardcoded user paths found"

      - name: Check for personal emails
        run: |
          echo "Checking for personal emails..."
          if grep -r '@trailofbits.com' . --include='*.json' --include='*.toml' | grep -v 'opensource@trailofbits.com' | grep -v '.git'; then
            echo "ERROR: Found personal emails (should use opensource@trailofbits.com)"
            exit 1
          fi
          echo "No personal emails found"