Skip to content

Commit 1464dba

Browse files
committed
feat: allows validation of specified plugins
1 parent 432083e commit 1464dba

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

.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: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function validatePluginToml(pluginName: string, pluginPath: string): ValidationE
4343
errors.push({
4444
plugin: pluginName,
4545
field: 'plugin.toml',
46-
message: `解析失败: ${e instanceof Error ? e.message : String(e)}`,
46+
message: `解析失败: ${ e instanceof Error ? e.message : String(e) }`,
4747
})
4848
return errors
4949
}
@@ -99,11 +99,24 @@ function main() {
9999
process.exit(0)
100100
}
101101

102-
const pluginDirs = fs.readdirSync(pluginsDir, { withFileTypes: true })
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 })
103115
.filter(entry => entry.isDirectory() && !entry.name.startsWith('.'))
104116
.map(entry => entry.name)
117+
}
105118

106-
console.log(`验证 ${pluginDirs.length} 个插件...\n`)
119+
console.log(`验证 ${ pluginDirs.length } 个插件...\n`)
107120

108121
for (const pluginName of pluginDirs) {
109122
const pluginPath = path.join(pluginsDir, pluginName)
@@ -113,21 +126,21 @@ function main() {
113126

114127
if (allErrors.length === 0) {
115128
console.log('所有插件验证通过')
116-
console.log(`\n允许的 tags: ${VALID_TAGS.join(', ')}`)
117-
console.log(`允许的 database: ${VALID_DATABASES.join(', ')}`)
129+
console.log(`\n允许的 tags: ${ VALID_TAGS.join(', ') }`)
130+
console.log(`允许的 database: ${ VALID_DATABASES.join(', ') }`)
118131
process.exit(0)
119132
}
120133

121134
console.error('验证失败:\n')
122135
for (const error of allErrors) {
123-
console.error(`[${error.plugin}] ${error.field}: ${error.message}`)
136+
console.error(`[${ error.plugin }] ${ error.field }: ${ error.message }`)
124137
if (error.invalidValues) {
125-
console.error(` 无效值: ${error.invalidValues.join(', ')}`)
138+
console.error(` 无效值: ${ error.invalidValues.join(', ') }`)
126139
}
127140
}
128141

129-
console.error(`\n允许的 tags: ${VALID_TAGS.join(', ')}`)
130-
console.error(`允许的 database: ${VALID_DATABASES.join(', ')}`)
142+
console.error(`\n允许的 tags: ${ VALID_TAGS.join(', ') }`)
143+
console.error(`允许的 database: ${ VALID_DATABASES.join(', ') }`)
131144
process.exit(1)
132145
}
133146

0 commit comments

Comments
 (0)