-
Notifications
You must be signed in to change notification settings - Fork 3.9k
129 lines (113 loc) · 5.04 KB
/
check-plugin-structure.yml
File metadata and controls
129 lines (113 loc) · 5.04 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
name: Check Plugin Structure
on:
pull_request:
branches: [staged]
paths:
- "plugins/**"
permissions:
contents: read
pull-requests: write
jobs:
check-materialized-files:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Check for materialized files in plugin directories
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
with:
script: |
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const pluginsDir = 'plugins';
const errors = [];
if (!fs.existsSync(pluginsDir)) {
console.log('No plugins directory found');
return;
}
const pluginDirs = fs.readdirSync(pluginsDir, { withFileTypes: true })
.filter(d => d.isDirectory())
.map(d => d.name);
for (const plugin of pluginDirs) {
const pluginPath = path.join(pluginsDir, plugin);
// Check for materialized agent/command/skill files
for (const subdir of ['agents', 'commands', 'skills']) {
const subdirPath = path.join(pluginPath, subdir);
if (!fs.existsSync(subdirPath)) continue;
const stat = fs.lstatSync(subdirPath);
if (stat.isSymbolicLink()) {
errors.push(`${pluginPath}/${subdir} is a symlink — symlinks should not exist in plugin directories`);
continue;
}
if (stat.isDirectory()) {
const files = fs.readdirSync(subdirPath);
if (files.length > 0) {
errors.push(
`${pluginPath}/${subdir}/ contains ${files.length} file(s): ${files.join(', ')}. ` +
`Plugin directories on staged should only contain .github/plugin/plugin.json and README.md. ` +
`Agent, command, and skill files are materialized automatically during publish to main.`
);
}
}
}
// Check for symlinks anywhere in the plugin directory
try {
const allFiles = execSync(`find "${pluginPath}" -type l`, { encoding: 'utf-8' }).trim();
if (allFiles) {
errors.push(`${pluginPath} contains symlinks:\n${allFiles}`);
}
} catch (e) {
// find returns non-zero if no matches, ignore
}
}
if (errors.length > 0) {
const prBranch = context.payload.pull_request.head.ref;
const prRepo = context.payload.pull_request.head.repo.full_name;
const isFork = context.payload.pull_request.head.repo.fork;
const body = [
'⚠️ **Materialized files or symlinks detected in plugin directories**',
'',
'Plugin directories on the `staged` branch should only contain:',
'- `.github/plugin/plugin.json` (metadata)',
'- `README.md`',
'',
'Agent, command, and skill files are copied in automatically when publishing to `main`.',
'',
'**Issues found:**',
...errors.map(e => `- ${e}`),
'',
'---',
'',
'### How to fix',
'',
'It looks like your branch may be based on `main` (which contains materialized files). Here are two options:',
'',
'**Option 1: Rebase onto `staged`** (recommended if you have few commits)',
'```bash',
`git fetch origin staged`,
`git rebase --onto origin/staged origin/main ${prBranch}`,
`git push --force-with-lease`,
'```',
'',
'**Option 2: Remove the extra files manually**',
'```bash',
'# Remove materialized files from plugin directories',
'find plugins/ -mindepth 2 -maxdepth 2 -type d \\( -name agents -o -name commands -o -name skills \\) -exec rm -rf {} +',
'# Remove any symlinks',
'find plugins/ -type l -delete',
'git add -A && git commit -m "fix: remove materialized plugin files"',
'git push',
'```',
].join('\n');
await github.rest.pulls.createReview({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
event: 'REQUEST_CHANGES',
body
});
core.setFailed('Plugin directories contain materialized files or symlinks that should not be on staged');
} else {
console.log('✅ All plugin directories are clean');
}