diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6e70ba4..42b0aa7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,6 +50,9 @@ jobs: pnpm build diff -r "$RUNNER_TEMP/schemas-before-docs" dist + - name: Check reference code samples + run: node tests/reference-code-samples.cjs + - name: Dry run release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.shins/index.js b/.shins/index.js index a5eb4fb..62a90de 100644 --- a/.shins/index.js +++ b/.shins/index.js @@ -213,7 +213,8 @@ function clean(s) { s = s.split('<=').join('$3$'); let a = s.split('```'); for (let i=0;i` as a tag and drops it. + if (!a[i].startsWith('xml') && !a[i].startsWith('php')) { a[i] = sanitizeHtml(a[i],sanitizeOptions); } } diff --git a/tests/reference-code-samples.cjs b/tests/reference-code-samples.cjs new file mode 100644 index 0000000..260a5af --- /dev/null +++ b/tests/reference-code-samples.cjs @@ -0,0 +1,19 @@ +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const path = require('node:path'); + +// Reads the reference produced by `pnpm build:docs`. +const html = fs.readFileSync(path.resolve(__dirname, '..', 'build/docs/index.html'), 'utf8'); + +const samples = (lang) => html.split('

([\\s\\S]*?)`, 'g'); + return [...section.matchAll(pattern)].map((match) => ({ id, code: match[1] })); +}); + +const php = samples('php'); +assert.ok(php.length > 0, 'no PHP samples in build/docs/index.html'); +const truncated = php.filter(({ code }) => !code.startsWith('<?php')); +assert.equal(truncated.length, 0, + `PHP samples missing their opening lines: ${truncated.map(({ id }) => id).join(', ')}`); +console.log(`PHP samples: ${php.length} complete`);