Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/android-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Validate dash-app manifests
run: node scripts/validate-manifests.js

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
Expand Down
82 changes: 82 additions & 0 deletions scripts/validate-manifests.js
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)) {

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Collaborator Author

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 perf to the schema and dash-apps/README.md documents 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.

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`);
Loading