Skip to content

Commit b472a4d

Browse files
build: validate mdx and md (#6816)
1 parent 46af3e9 commit b472a4d

File tree

6 files changed

+3322
-156
lines changed

6 files changed

+3322
-156
lines changed

.github/workflows/docs.yaml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: Verify Docs Formatting
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
48

59
permissions:
610
contents: read

.github/workflows/test.yaml

+29-31
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,46 @@
1-
name: Verify Links
1+
name: ci
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
48

59
permissions:
610
contents: read
711

812
jobs:
913
lint:
10-
name: ESLint
14+
name: Lint
1115
runs-on: ubuntu-latest
1216
steps:
13-
- name: Checkout repository
14-
uses: actions/checkout@v4
15-
16-
- name: Install Node v18
17-
uses: actions/setup-node@v4
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-node@v4
1819
with:
19-
node-version: 18
20+
node-version: 20
2021
cache: npm
21-
22-
- name: Install dependencies
23-
run: npm ci
24-
25-
- name: Run ESLint
26-
run: npm run lint
27-
22+
- run: npm ci
23+
- run: npm run lint
24+
- run: npm run build
2825
links:
2926
name: Check Links
3027
runs-on: ubuntu-latest
3128
steps:
32-
- name: Checkout repository
33-
uses: actions/checkout@v4
34-
35-
- name: Install Node v18
36-
uses: actions/setup-node@v4
29+
- uses: actions/checkout@v4
30+
- uses: actions/setup-node@v4
3731
with:
38-
node-version: 18
32+
node-version: 20
3933
cache: npm
40-
41-
- name: Install dependencies
42-
run: npm ci
43-
44-
- name: Build
45-
run: npm run build
46-
47-
- name: Run Link Checks
48-
run: npm run test:links
34+
- run: npm ci
35+
- run: npm run test:links
36+
mdx:
37+
name: Validate mdx
38+
runs-on: ubuntu-latest
39+
steps:
40+
- uses: actions/checkout@v4
41+
- uses: actions/setup-node@v4
42+
with:
43+
node-version: 20
44+
cache: npm
45+
- run: npm ci
46+
- run: npm run test:build

ci/checkBuild.ts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import fs from "node:fs/promises";
2+
import path from "node:path";
3+
import { compile } from "@mdx-js/mdx";
4+
5+
const args = process.argv.slice(2);
6+
const bail = args.includes("--bail");
7+
8+
const ROOT_DIR = path.join(import.meta.dirname, "..");
9+
const DOCS_DIR = path.join(ROOT_DIR, "docs");
10+
11+
const extensions = [".mdx", ".md"];
12+
let hasErrors = false;
13+
14+
for (const docsRelativePath of await fs.readdir(DOCS_DIR, { recursive: true })) {
15+
const filePath = path.join(DOCS_DIR, docsRelativePath);
16+
const rootRelPath = path.relative(ROOT_DIR, filePath);
17+
18+
if (extensions.includes(path.extname(filePath))) {
19+
try {
20+
console.error(`Compiling ${rootRelPath}`);
21+
await compile(await fs.readFile(filePath), {
22+
format: path.extname(filePath) === ".mdx" ? "mdx" : "md",
23+
});
24+
} catch (error) {
25+
console.error(`Error compiling ${rootRelPath}:`);
26+
console.error(error);
27+
hasErrors = true;
28+
if (bail) {
29+
process.exit(1);
30+
}
31+
}
32+
}
33+
}
34+
35+
if (hasErrors) {
36+
process.exit(1);
37+
}

0 commit comments

Comments
 (0)