-
Notifications
You must be signed in to change notification settings - Fork 8
ci(mcp): validate package contents and version before npm publish #1706
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8897d37
feat: add MCP package validation script and integrate into npm publis…
dkalinovInfra 15b078e
chore: update package versions to 15.2.2-alpha.3 for multiple packages
dkalinovInfra 63ef259
refactor: rename PACKAGE_MIN_BYTES to FRAMEWORK_MIN_BYTES and simplif…
dkalinovInfra 184fbf6
Potential fix for pull request finding
dkalinovInfra fbda7a6
Merge branch 'master' into dkalinov/mcp-package-validation
damyanpetev 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
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
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
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
110 changes: 110 additions & 0 deletions
110
packages/igniteui-mcp/igniteui-doc-mcp/scripts/validate-package.ts
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,110 @@ | ||
| import { readdirSync, readFileSync, statSync, existsSync } from "fs"; | ||
| import { join, resolve } from "path"; | ||
| import { fileURLToPath } from "url"; | ||
|
|
||
| const PKG_ROOT = resolve(fileURLToPath(new URL("..", import.meta.url))); | ||
| const DB_PATH = join(PKG_ROOT, "dist", "igniteui-docs.db"); | ||
| const DB_MIN_BYTES = 20 * 1024 * 1024; // 20 MB minimum for the SQLite DB | ||
| const DOCS_ROOT = join(PKG_ROOT, "docs"); | ||
| const FRAMEWORK_DIRS = ["angular-api", "react-api", "webcomponents-api", "blazor-api"]; | ||
| const FRAMEWORK_MIN_BYTES = 300 * 1024; // 300 KB minimum for each docs/<framework>-api directory | ||
|
|
||
| const errors: string[] = []; | ||
|
|
||
| function getExpectedVersion(): string | null { | ||
| const idx = process.argv.indexOf("--expected-version"); | ||
| if (idx >= 0) { | ||
| const rawValue = process.argv[idx + 1]; | ||
| const value = rawValue?.trim(); | ||
| if (!value || value.startsWith("--")) { | ||
| console.error('Missing or invalid value for "--expected-version". Provide a version after the flag.'); | ||
| process.exit(1); | ||
| } | ||
| return value.replace(/^v/, ""); | ||
| } | ||
| if (process.env.EXPECTED_VERSION) return process.env.EXPECTED_VERSION.replace(/^v/, ""); | ||
| return null; | ||
| } | ||
|
|
||
| const expectedVersion = getExpectedVersion(); | ||
| if (expectedVersion) { | ||
| const pkgJsonPath = join(PKG_ROOT, "package.json"); | ||
| const pkgJson = JSON.parse(readFileSync(pkgJsonPath, "utf8")); | ||
| if (pkgJson.version !== expectedVersion) { | ||
| errors.push(`package.json version mismatch: got ${pkgJson.version}, expected ${expectedVersion}`); | ||
| } else { | ||
| console.log(`OK ver package.json ${pkgJson.version}`); | ||
| } | ||
|
|
||
| const serverJsonPath = join(PKG_ROOT, "server.json"); | ||
| if (!existsSync(serverJsonPath)) { | ||
| errors.push(`server.json missing: ${serverJsonPath}`); | ||
| } else { | ||
| const serverJson = JSON.parse(readFileSync(serverJsonPath, "utf8")); | ||
| if (serverJson.version !== expectedVersion) { | ||
| errors.push(`server.json version mismatch: got ${serverJson.version}, expected ${expectedVersion}`); | ||
| } else { | ||
| console.log(`OK ver server.json ${serverJson.version}`); | ||
| } | ||
| const pkgs: Array<{ identifier?: string; version?: string }> = serverJson.packages ?? []; | ||
| if (pkgs.length === 0) { | ||
| errors.push(`server.json has no entries in "packages"`); | ||
| } | ||
| pkgs.forEach((p, i) => { | ||
| const label = p.identifier ?? `packages[${i}]`; | ||
| if (p.version !== expectedVersion) { | ||
| errors.push(`server.json ${label} version mismatch: got ${p.version}, expected ${expectedVersion}`); | ||
| } else { | ||
| console.log(`OK ver server.json ${label.padEnd(20)} ${p.version}`); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| function formatSize(bytes: number): string { | ||
| if (bytes >= 1024 * 1024) return `${(bytes / 1024 / 1024).toFixed(2)} MB`; | ||
| if (bytes >= 1024) return `${(bytes / 1024).toFixed(2)} KB`; | ||
| return `${bytes} B`; | ||
| } | ||
|
|
||
| function dirSize(dir: string): number { | ||
| let total = 0; | ||
| for (const entry of readdirSync(dir, { withFileTypes: true })) { | ||
| const full = join(dir, entry.name); | ||
| if (entry.isDirectory()) total += dirSize(full); | ||
| else if (entry.isFile()) total += statSync(full).size; | ||
| } | ||
| return total; | ||
| } | ||
|
|
||
| if (!existsSync(DB_PATH)) { | ||
| errors.push(`DB missing: ${DB_PATH}`); | ||
| } else { | ||
| const size = statSync(DB_PATH).size; | ||
| if (size < DB_MIN_BYTES) { | ||
| errors.push(`DB too small: ${formatSize(size)} < ${formatSize(DB_MIN_BYTES)} (${DB_PATH})`); | ||
| } else { | ||
| console.log(`OK db ${formatSize(size)} ${DB_PATH}`); | ||
| } | ||
| } | ||
|
|
||
| for (const framework of FRAMEWORK_DIRS) { | ||
| const frameworkDir = join(DOCS_ROOT, framework); | ||
| if (!existsSync(frameworkDir)) { | ||
| errors.push(`Docs framework dir missing: ${frameworkDir}`); | ||
| continue; | ||
| } | ||
| const size = dirSize(frameworkDir); | ||
| if (size < FRAMEWORK_MIN_BYTES) { | ||
| errors.push(`Docs framework dir too small: ${framework} = ${formatSize(size)} < ${formatSize(FRAMEWORK_MIN_BYTES)}`); | ||
| } else { | ||
| console.log(`OK dir ${formatSize(size).padStart(10)} ${framework}`); | ||
| } | ||
| } | ||
|
|
||
| if (errors.length > 0) { | ||
| console.error(`\nValidation failed with ${errors.length} error(s):`); | ||
| for (const e of errors) console.error(` - ${e}`); | ||
| process.exit(1); | ||
| } | ||
| console.log("\nAll checks passed."); |
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
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
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
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.