Skip to content

Commit c6a8ae1

Browse files
committed
feat: allows validation of specified plugins
1 parent 414d215 commit c6a8ae1

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

.github/workflows/validate-plugin-toml.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,31 @@ jobs:
1616
uses: actions/checkout@v4
1717
with:
1818
submodules: recursive
19+
fetch-depth: 0
20+
21+
- name: Get changed plugins
22+
id: changed
23+
run: |
24+
CHANGED_PLUGINS=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep '^plugins/' | cut -d'/' -f2 | sort -u | tr '\n' ' ')
25+
echo "plugins=$CHANGED_PLUGINS" >> $GITHUB_OUTPUT
26+
echo "Changed plugins: $CHANGED_PLUGINS"
1927
2028
- name: Setup Node.js
29+
if: steps.changed.outputs.plugins != ''
2130
uses: actions/setup-node@v4
2231
with:
2332
node-version: '22'
2433

2534
- name: Setup pnpm
35+
if: steps.changed.outputs.plugins != ''
2636
uses: pnpm/action-setup@v4
2737
with:
2838
version: 10
2939

3040
- name: Install dependencies
41+
if: steps.changed.outputs.plugins != ''
3142
run: pnpm install
3243

3344
- name: Validate plugin.toml files
34-
run: pnpm validate
45+
if: steps.changed.outputs.plugins != ''
46+
run: pnpm validate ${{ steps.changed.outputs.plugins }}

validate.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,22 @@ function main() {
9999
process.exit(0)
100100
}
101101

102-
const pluginDirs = fs.readdirSync(pluginsDir, { withFileTypes: true })
103-
.filter(entry => entry.isDirectory() && !entry.name.startsWith('.'))
104-
.map(entry => entry.name)
102+
// 支持命令行参数指定要验证的插件
103+
const args = process.argv.slice(2)
104+
let pluginDirs: string[]
105+
106+
if (args.length > 0) {
107+
// 验证指定的插件
108+
pluginDirs = args.filter(name => {
109+
const pluginPath = path.join(pluginsDir, name)
110+
return fs.existsSync(pluginPath)
111+
})
112+
} else {
113+
// 验证所有插件
114+
pluginDirs = fs.readdirSync(pluginsDir, { withFileTypes: true })
115+
.filter(entry => entry.isDirectory() && !entry.name.startsWith('.'))
116+
.map(entry => entry.name)
117+
}
105118

106119
console.log(`验证 ${pluginDirs.length} 个插件...\n`)
107120

0 commit comments

Comments
 (0)