-
Notifications
You must be signed in to change notification settings - Fork 0
ci: validate dash-app manifests in Android build #163
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
+85
−0
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| "use strict"; | ||
| const fs = require("node:fs"); | ||
| const path = require("node:path"); | ||
|
|
||
| const SCHEMA_PATH = path.join(__dirname, "..", "docs", "dashapp-manifest.schema.json"); | ||
| const APPS_DIR = path.join(__dirname, "..", "dash-apps"); | ||
|
|
||
| const ROOT_KEYS = new Set(["$schema", "manifestVersion", "id", "perf", "settings"]); | ||
| const PERF_KEYS = new Set(["gate", "reason", "root"]); | ||
| const GATE_VALUES = new Set(["standard", "exempt"]); | ||
|
|
||
| const schema = JSON.parse(fs.readFileSync(SCHEMA_PATH, "utf8")); | ||
| const validSettings = new Set(schema.properties.settings.items.enum); | ||
| const idRe = new RegExp(schema.properties.id.pattern); | ||
|
|
||
| const dirs = fs.readdirSync(APPS_DIR).filter((name) => name.startsWith("web-")); | ||
| if (dirs.length === 0) { | ||
| console.error("No dash-apps found in dash-apps/web-*/"); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const errors = []; | ||
| for (const folder of dirs) { | ||
| const manifestPath = path.join(APPS_DIR, folder, "manifest.json"); | ||
| if (!fs.existsSync(manifestPath)) { | ||
| errors.push(`${folder}: missing manifest.json`); | ||
| continue; | ||
| } | ||
|
|
||
| const m = JSON.parse(fs.readFileSync(manifestPath, "utf8")); | ||
|
|
||
| for (const key of Object.keys(m)) { | ||
| if (!ROOT_KEYS.has(key)) errors.push(`${folder}: unknown property "${key}"`); | ||
| } | ||
| const expectedVersion = schema.properties.manifestVersion.const; | ||
| if (!Number.isInteger(m.manifestVersion) || m.manifestVersion !== expectedVersion) { | ||
| errors.push(`${folder}: manifestVersion must be ${expectedVersion}`); | ||
| } | ||
| if (typeof m.id !== "string" || !idRe.test(m.id)) { | ||
| errors.push(`${folder}: id must match ${schema.properties.id.pattern}`); | ||
| } | ||
| if (!Array.isArray(m.settings)) { | ||
| errors.push(`${folder}: settings must be an array`); | ||
| } else { | ||
| const seen = new Set(); | ||
| for (const s of m.settings) { | ||
| if (!validSettings.has(s)) errors.push(`${folder}/settings: "${s}" is not a valid setting`); | ||
| if (seen.has(s)) errors.push(`${folder}/settings: "${s}" is duplicated`); | ||
| seen.add(s); | ||
| } | ||
| } | ||
|
|
||
| if (m.perf !== undefined) { | ||
| if (typeof m.perf !== "object" || m.perf === null) { | ||
| errors.push(`${folder}/perf: must be an object`); | ||
| } else { | ||
| for (const key of Object.keys(m.perf)) { | ||
| if (!PERF_KEYS.has(key)) errors.push(`${folder}/perf: unknown property "${key}"`); | ||
| } | ||
| if (m.perf.gate !== undefined && !GATE_VALUES.has(m.perf.gate)) { | ||
| errors.push(`${folder}/perf/gate: must be "standard" or "exempt"`); | ||
| } | ||
| if (m.perf.gate === "exempt" && (typeof m.perf.reason !== "string" || m.perf.reason.length < 10)) { | ||
| errors.push(`${folder}/perf/reason: required when gate is "exempt" (min 10 chars)`); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (m.id !== undefined && typeof m.id === "string") { | ||
| const expectedFolder = `web-${m.id}`; | ||
| if (folder !== expectedFolder) { | ||
| errors.push(`${folder}: folder name does not match id "${m.id}" (expected "${expectedFolder}")`); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (errors.length > 0) { | ||
| console.error(`Manifest validation failed:\n${errors.map((e) => ` - ${e}`).join("\n")}`); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| console.log(`${dirs.length} dash-app manifests valid`); | ||
Oops, something went wrong.
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.
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.
What is this perf gate thing?
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.
The perf block validates the optional perf-gate field that ships in #161 (the performance harness). That PR adds
perfto the schema anddash-apps/README.mddocuments the gate values. The validator is forward-compatible - it was written against the contract that #161 establishes, so it works correctly once that PR merges.