-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add CI validation for plugin manifests #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| name: Validate Plugin Manifest | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - "**" | ||
| pull_request: | ||
| branches: | ||
| - main | ||
|
|
||
| jobs: | ||
| validate: | ||
| name: Validate marketplace.json & plugin.json | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 | ||
|
|
||
| - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 | ||
| with: | ||
| node-version: "22" | ||
|
|
||
| - name: Validate plugin manifests | ||
| run: node scripts/validate-marketplace.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| #!/usr/bin/env node | ||
| /** | ||
| * Validates .claude-plugin/marketplace.json and .claude-plugin/plugin.json | ||
| * against the Claude Code plugin schema. | ||
| * | ||
| * Schema rules derived from the Claude Code plugin system: | ||
| * - marketplace.json: validates the marketplace definition and all plugin entries | ||
| * - plugin.json: validates the root plugin definition | ||
| * | ||
| * Source field for marketplace plugin entries must be one of: | ||
| * - A relative path string starting with "./" (e.g. "./plugins/my-plugin") | ||
| * - A GitHub object: { source: "github", repo: "owner/name", path?: "..." } | ||
| */ | ||
|
|
||
| import { readFileSync, existsSync } from "fs"; | ||
| import { resolve } from "path"; | ||
|
|
||
| const ROOT = new URL("..", import.meta.url).pathname; | ||
|
|
||
| let exitCode = 0; | ||
|
|
||
| function error(file, msg) { | ||
| console.error(`β ${file}: ${msg}`); | ||
| exitCode = 1; | ||
| } | ||
|
|
||
| function ok(file, msg) { | ||
| console.log(`β ${file}: ${msg}`); | ||
| } | ||
|
|
||
| // βββ Source validation ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | ||
|
|
||
| function validateSource(source, pluginName, file) { | ||
| if (typeof source === "string") { | ||
| if (!source.startsWith("./")) { | ||
| error( | ||
| file, | ||
| `plugins["${pluginName}"].source: string source must start with "./" (got "${source}"). ` + | ||
| `Bare "." or absolute paths are not valid.` | ||
| ); | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| if (typeof source === "object" && source !== null) { | ||
| if (source.source !== "github") { | ||
| error( | ||
| file, | ||
| `plugins["${pluginName}"].source.source: object source must have source="github" (got "${source.source}")` | ||
| ); | ||
| return false; | ||
| } | ||
| if (typeof source.repo !== "string" || !source.repo.includes("/")) { | ||
| error( | ||
| file, | ||
| `plugins["${pluginName}"].source.repo: must be a string in "owner/repo" format (got ${JSON.stringify(source.repo)})` | ||
| ); | ||
| return false; | ||
| } | ||
| if (source.path !== undefined && typeof source.path !== "string") { | ||
| error( | ||
| file, | ||
| `plugins["${pluginName}"].source.path: must be a string if provided (got ${JSON.stringify(source.path)})` | ||
| ); | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| error( | ||
| file, | ||
| `plugins["${pluginName}"].source: Invalid input β must be a "./relative" string or a ` + | ||
| `{ source: "github", repo: "owner/name" } object (got ${JSON.stringify(source)})` | ||
| ); | ||
| return false; | ||
| } | ||
|
|
||
| // βββ marketplace.json βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | ||
|
|
||
| function validateMarketplace(filePath) { | ||
| const rel = filePath.replace(ROOT, ""); | ||
|
|
||
| if (!existsSync(filePath)) { | ||
| error(rel, "file not found"); | ||
| return; | ||
| } | ||
|
|
||
| let data; | ||
| try { | ||
| data = JSON.parse(readFileSync(filePath, "utf8")); | ||
| } catch (e) { | ||
| error(rel, `invalid JSON β ${e.message}`); | ||
| return; | ||
| } | ||
|
|
||
| if (typeof data.name !== "string" || !data.name) { | ||
| error(rel, "name: must be a non-empty string"); | ||
| } | ||
|
|
||
| if (!Array.isArray(data.plugins)) { | ||
| error(rel, "plugins: must be an array"); | ||
| return; | ||
| } | ||
|
|
||
| if (data.plugins.length === 0) { | ||
| error(rel, "plugins: array must not be empty"); | ||
| return; | ||
| } | ||
|
|
||
| let allValid = true; | ||
| for (const [i, plugin] of data.plugins.entries()) { | ||
| const label = plugin.name ?? `[${i}]`; | ||
|
|
||
| if (typeof plugin.name !== "string" || !plugin.name) { | ||
| error(rel, `plugins[${i}].name: must be a non-empty string`); | ||
| allValid = false; | ||
| } | ||
|
|
||
| if (plugin.source === undefined) { | ||
| error(rel, `plugins["${label}"].source: field is required`); | ||
| allValid = false; | ||
| } else { | ||
| if (!validateSource(plugin.source, label, rel)) allValid = false; | ||
| } | ||
|
|
||
| if (typeof plugin.description !== "string" || !plugin.description) { | ||
| error(rel, `plugins["${label}"].description: must be a non-empty string`); | ||
| allValid = false; | ||
| } | ||
|
|
||
| if (plugin.tags !== undefined) { | ||
| if (!Array.isArray(plugin.tags) || !plugin.tags.every((t) => typeof t === "string")) { | ||
| error(rel, `plugins["${label}"].tags: must be an array of strings`); | ||
| allValid = false; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (allValid) { | ||
| ok(rel, `${data.plugins.length} plugin(s) β all valid`); | ||
| } | ||
| } | ||
|
|
||
| // βββ plugin.json βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | ||
|
|
||
| function validatePlugin(filePath) { | ||
| const rel = filePath.replace(ROOT, ""); | ||
|
|
||
| if (!existsSync(filePath)) { | ||
| // plugin.json is optional for marketplaces that don't expose a root plugin | ||
| return; | ||
| } | ||
|
|
||
| let data; | ||
| try { | ||
| data = JSON.parse(readFileSync(filePath, "utf8")); | ||
| } catch (e) { | ||
| error(rel, `invalid JSON β ${e.message}`); | ||
| return; | ||
| } | ||
|
|
||
| if (typeof data.name !== "string" || !data.name) { | ||
| error(rel, "name: must be a non-empty string"); | ||
| } else if (typeof data.description !== "string" || !data.description) { | ||
| error(rel, "description: must be a non-empty string"); | ||
| } else { | ||
| ok(rel, `plugin "${data.name}" v${data.version ?? "unversioned"} β valid`); | ||
| } | ||
| } | ||
|
|
||
| // βββ Run ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | ||
|
|
||
| validateMarketplace(resolve(ROOT, ".claude-plugin/marketplace.json")); | ||
| validatePlugin(resolve(ROOT, ".claude-plugin/plugin.json")); | ||
|
|
||
| if (exitCode === 0) { | ||
| console.log("\nβ All plugin files are valid."); | ||
| } else { | ||
| console.error("\nβ Validation failed β see errors above."); | ||
| } | ||
|
|
||
| process.exit(exitCode); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Guard
pluginsentries before accessingplugin.*to avoid a TypeError when an entry isnullor a non-object, and emit a clear validation error instead of crashing.Prompt for AI agents