|
| 1 | +name: Check Plugin Structure |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [staged] |
| 6 | + paths: |
| 7 | + - "plugins/**" |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + pull-requests: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + check-materialized-files: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Checkout |
| 18 | + uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Check for materialized files in plugin directories |
| 21 | + uses: actions/github-script@v7 |
| 22 | + with: |
| 23 | + script: | |
| 24 | + const { execSync } = require('child_process'); |
| 25 | + const fs = require('fs'); |
| 26 | + const path = require('path'); |
| 27 | +
|
| 28 | + const pluginsDir = 'plugins'; |
| 29 | + const errors = []; |
| 30 | +
|
| 31 | + if (!fs.existsSync(pluginsDir)) { |
| 32 | + console.log('No plugins directory found'); |
| 33 | + return; |
| 34 | + } |
| 35 | +
|
| 36 | + const pluginDirs = fs.readdirSync(pluginsDir, { withFileTypes: true }) |
| 37 | + .filter(d => d.isDirectory()) |
| 38 | + .map(d => d.name); |
| 39 | +
|
| 40 | + for (const plugin of pluginDirs) { |
| 41 | + const pluginPath = path.join(pluginsDir, plugin); |
| 42 | +
|
| 43 | + // Check for materialized agent/command/skill files |
| 44 | + for (const subdir of ['agents', 'commands', 'skills']) { |
| 45 | + const subdirPath = path.join(pluginPath, subdir); |
| 46 | + if (!fs.existsSync(subdirPath)) continue; |
| 47 | +
|
| 48 | + const stat = fs.lstatSync(subdirPath); |
| 49 | + if (stat.isSymbolicLink()) { |
| 50 | + errors.push(`${pluginPath}/${subdir} is a symlink — symlinks should not exist in plugin directories`); |
| 51 | + continue; |
| 52 | + } |
| 53 | +
|
| 54 | + if (stat.isDirectory()) { |
| 55 | + const files = fs.readdirSync(subdirPath); |
| 56 | + if (files.length > 0) { |
| 57 | + errors.push( |
| 58 | + `${pluginPath}/${subdir}/ contains ${files.length} file(s): ${files.join(', ')}. ` + |
| 59 | + `Plugin directories on staged should only contain .github/plugin/plugin.json and README.md. ` + |
| 60 | + `Agent, command, and skill files are materialized automatically during publish to main.` |
| 61 | + ); |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | +
|
| 66 | + // Check for symlinks anywhere in the plugin directory |
| 67 | + try { |
| 68 | + const allFiles = execSync(`find "${pluginPath}" -type l`, { encoding: 'utf-8' }).trim(); |
| 69 | + if (allFiles) { |
| 70 | + errors.push(`${pluginPath} contains symlinks:\n${allFiles}`); |
| 71 | + } |
| 72 | + } catch (e) { |
| 73 | + // find returns non-zero if no matches, ignore |
| 74 | + } |
| 75 | + } |
| 76 | +
|
| 77 | + if (errors.length > 0) { |
| 78 | + const prBranch = context.payload.pull_request.head.ref; |
| 79 | + const prRepo = context.payload.pull_request.head.repo.full_name; |
| 80 | + const isFork = context.payload.pull_request.head.repo.fork; |
| 81 | +
|
| 82 | + const body = [ |
| 83 | + '⚠️ **Materialized files or symlinks detected in plugin directories**', |
| 84 | + '', |
| 85 | + 'Plugin directories on the `staged` branch should only contain:', |
| 86 | + '- `.github/plugin/plugin.json` (metadata)', |
| 87 | + '- `README.md`', |
| 88 | + '', |
| 89 | + 'Agent, command, and skill files are copied in automatically when publishing to `main`.', |
| 90 | + '', |
| 91 | + '**Issues found:**', |
| 92 | + ...errors.map(e => `- ${e}`), |
| 93 | + '', |
| 94 | + '---', |
| 95 | + '', |
| 96 | + '### How to fix', |
| 97 | + '', |
| 98 | + 'It looks like your branch may be based on `main` (which contains materialized files). Here are two options:', |
| 99 | + '', |
| 100 | + '**Option 1: Rebase onto `staged`** (recommended if you have few commits)', |
| 101 | + '```bash', |
| 102 | + `git fetch origin staged`, |
| 103 | + `git rebase --onto origin/staged origin/main ${prBranch}`, |
| 104 | + `git push --force-with-lease`, |
| 105 | + '```', |
| 106 | + '', |
| 107 | + '**Option 2: Remove the extra files manually**', |
| 108 | + '```bash', |
| 109 | + '# Remove materialized files from plugin directories', |
| 110 | + 'find plugins/ -mindepth 2 -maxdepth 2 -type d \\( -name agents -o -name commands -o -name skills \\) -exec rm -rf {} +', |
| 111 | + '# Remove any symlinks', |
| 112 | + 'find plugins/ -type l -delete', |
| 113 | + 'git add -A && git commit -m "fix: remove materialized plugin files"', |
| 114 | + 'git push', |
| 115 | + '```', |
| 116 | + ].join('\n'); |
| 117 | +
|
| 118 | + await github.rest.pulls.createReview({ |
| 119 | + owner: context.repo.owner, |
| 120 | + repo: context.repo.repo, |
| 121 | + pull_number: context.issue.number, |
| 122 | + event: 'REQUEST_CHANGES', |
| 123 | + body |
| 124 | + }); |
| 125 | +
|
| 126 | + core.setFailed('Plugin directories contain materialized files or symlinks that should not be on staged'); |
| 127 | + } else { |
| 128 | + console.log('✅ All plugin directories are clean'); |
| 129 | + } |
0 commit comments