diff options
| -rw-r--r-- | .github/workflows/check.yml | 28 | ||||
| -rw-r--r-- | package-lock.json | 23 | ||||
| -rw-r--r-- | package.json | 6 | ||||
| -rw-r--r-- | scripts/check-frontmatter.mjs | 46 |
4 files changed, 98 insertions, 5 deletions
diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..6c19e6b --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,28 @@ +name: Check + +on: + pull_request: + push: + branches: + - main + +jobs: + frontmatter: + name: SKILL.md frontmatter + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 22 + + - name: Install dependencies + run: npm ci + + - name: Check frontmatter + run: npm run check-frontmatter diff --git a/package-lock.json b/package-lock.json index db12f08..2787482 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,17 @@ { "name": "mattpocock-skills", - "version": "0.0.0", + "version": "1.3.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "mattpocock-skills", - "version": "0.0.0", + "version": "1.3.2", "license": "MIT", "devDependencies": { "@changesets/changelog-github": "^0.7.0", - "@changesets/cli": "^2.30.0" + "@changesets/cli": "^2.30.0", + "yaml": "^2.9.1" } }, "node_modules/@babel/runtime": { @@ -1380,6 +1381,22 @@ "engines": { "node": ">= 8" } + }, + "node_modules/yaml": { + "version": "2.9.1", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.9.1.tgz", + "integrity": "sha512-3NxN8+78OdzbT7C/WjGsyfPAtJaN3FNDsWxv7Y7mcDsT/oOmgW8BpyQQFFBnvZE3j9Y2Sdz1ULFLezL7Eb2yFw==", + "dev": true, + "license": "ISC", + "bin": { + "yaml": "bin.mjs" + }, + "engines": { + "node": ">= 14.6" + }, + "funding": { + "url": "https://github.com/sponsors/eemeli" + } } } } diff --git a/package.json b/package.json index c5b9804..56dcdcd 100644 --- a/package.json +++ b/package.json @@ -11,11 +11,13 @@ "scripts": { "changeset": "changeset", "version": "changeset version && node scripts/sync-plugin-version.mjs", - "check-plugin-version": "node scripts/sync-plugin-version.mjs --check" + "check-plugin-version": "node scripts/sync-plugin-version.mjs --check", + "check-frontmatter": "node scripts/check-frontmatter.mjs" }, "devDependencies": { "@changesets/changelog-github": "^0.7.0", - "@changesets/cli": "^2.30.0" + "@changesets/cli": "^2.30.0", + "yaml": "^2.9.1" }, "packageManager": "npm@10.9.4" } diff --git a/scripts/check-frontmatter.mjs b/scripts/check-frontmatter.mjs new file mode 100644 index 0000000..f06a876 --- /dev/null +++ b/scripts/check-frontmatter.mjs @@ -0,0 +1,46 @@ +// Parses every SKILL.md's frontmatter with `yaml`, the parser the `skills` +// installer uses, so a skill that would be skipped on install fails here first. +import { readFileSync, readdirSync } from "node:fs"; +import { join, relative } from "node:path"; +import { parseDocument } from "yaml"; + +const root = new URL("..", import.meta.url).pathname; + +function* skillFiles(dir) { + for (const entry of readdirSync(dir, { withFileTypes: true })) { + const path = join(dir, entry.name); + if (entry.isDirectory()) yield* skillFiles(path); + else if (entry.name === "SKILL.md") yield path; + } +} + +const failures = []; + +for (const file of skillFiles(join(root, "skills"))) { + const where = relative(root, file); + const match = readFileSync(file, "utf8").match(/^---\r?\n([\s\S]*?)\r?\n---/); + if (!match) { + failures.push(`${where}: no frontmatter block`); + continue; + } + const doc = parseDocument(match[1], { strict: true, uniqueKeys: true }); + if (doc.errors.length > 0) { + failures.push(`${where}: ${doc.errors[0].message.split("\n")[0]}`); + continue; + } + const data = doc.toJS(); + for (const key of ["name", "description"]) { + if (typeof data?.[key] !== "string" || data[key].trim() === "") { + failures.push(`${where}: missing \`${key}\``); + } + } +} + +if (failures.length > 0) { + console.error(failures.join("\n")); + console.error( + `\n${failures.length} SKILL.md frontmatter error(s). Quote any value containing ": " or starting with a YAML indicator character.`, + ); + process.exit(1); +} +console.log("All SKILL.md frontmatter parses."); |
