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: 1 addition & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ concurrency:
jobs:
lint:
name: Lint (sync, frontmatter, mermaid)
if: github.event_name == "pull_request"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -43,7 +42,7 @@ jobs:

deploy:
name: Deploy to GitHub Pages
if: github.event_name == "push" && github.ref == "refs/heads/main"
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: build
runs-on: ubuntu-latest
environment:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"lint:sync": "node scripts/sync-check.mjs",
"lint:mermaid": "node scripts/validate-mermaid.mjs",
"lint:gitbook": "node scripts/validate-gitbook-content.mjs",
"test:content": "node --test scripts/gitbook-content.test.mjs",
"test:content": "node --test scripts/gitbook-content.test.mjs scripts/ci-config.test.mjs",
"quality:gitbook": "npm run test:content && npm run lint:gitbook && npm run lint:mermaid",
"lint": "npm run lint:sync && npm run lint:frontmatter && npm run lint:mermaid"
},
Expand Down
34 changes: 34 additions & 0 deletions scripts/ci-config.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import test from "node:test";

const repositoryRoot = new URL("../", import.meta.url);

test("deploy workflow uses valid expressions and runs its lint dependency on every event", async () => {
const workflow = await readFile(
new URL(".github/workflows/deploy.yml", repositoryRoot),
"utf8",
);
const normalizedWorkflow = workflow.replace(/\r\n/g, "\n");
const lintMatch = normalizedWorkflow.match(/ lint:\n(?<body>[\s\S]*?)\n build:/);

assert.ok(lintMatch, "lint job block must be present");
assert.doesNotMatch(normalizedWorkflow, /^\s*if:\s+.*"/gm);
assert.doesNotMatch(lintMatch.groups.body, /^\s+if:/m);
});

test("Mermaid validation supplies the documented Chromium CI sandbox override", async () => {
const validator = await readFile(
new URL("scripts/validate-mermaid.mjs", repositoryRoot),
"utf8",
);
const configText = await readFile(
new URL("scripts/puppeteer-ci.json", repositoryRoot),
"utf8",
).catch(() => null);

assert.match(validator, /process\.env\.CI/);
assert.match(validator, /puppeteer-ci\.json/);
assert.ok(configText, "scripts/puppeteer-ci.json must exist");
assert.deepEqual(JSON.parse(configText), { args: ["--no-sandbox"] });
});
3 changes: 3 additions & 0 deletions scripts/puppeteer-ci.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"args": ["--no-sandbox"]
}
10 changes: 7 additions & 3 deletions scripts/validate-mermaid.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ let total = 0;

const manifest = JSON.parse(await readFile("content/translation-manifest.json", "utf8"));
const mmdc = join("node_modules", "@mermaid-js", "mermaid-cli", "src", "cli.js");
const puppeteerConfig = join("scripts", "puppeteer-ci.json");

const tmpDir = await mkdtemp(join(tmpdir(), "pi-docs-mermaid-"));

Expand All @@ -25,9 +26,12 @@ try {
const svgFile = join(tmpDir, `block-${total}.svg`);
await writeFile(mmdFile, block, "utf8");
const result = await new Promise((resolve) => {
const proc = spawn(process.execPath, [mmdc, "-i", mmdFile, "-o", svgFile, "-q"], {
stdio: "inherit",
});
const browserArgs = process.env.CI ? ["-p", puppeteerConfig] : [];
const proc = spawn(
process.execPath,
[mmdc, ...browserArgs, "-i", mmdFile, "-o", svgFile, "-q"],
{ stdio: "inherit" },
);
proc.once("error", (error) => resolve({ code: null, error }));
proc.once("close", (code) => resolve({ code, error: null }));
});
Expand Down
Loading