Skip to content

Commit 181019c

Browse files
authored
Merge pull request #26 from ppl-ai/kesku/test-validation
feat: Update MDX validation workflow
2 parents 0c52fa9 + bdbbbf2 commit 181019c

File tree

3 files changed

+34
-21
lines changed

3 files changed

+34
-21
lines changed

.github/workflows/pr-validation.yml

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
- '.github/workflows/**'
99

1010
jobs:
11-
validate-mdx:
11+
mdx-validation:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- name: Checkout repo
@@ -21,27 +21,10 @@ jobs:
2121
cache: 'npm'
2222

2323
- name: MDX validation dependencies
24-
run: npm install --save-dev @mdx-js/mdx @mdx-js/loader
24+
run: npm install --save-dev @mdx-js/mdx @mdx-js/loader glob
2525

2626
- name: Validate MDX files
27-
run: |
28-
# Find and validate all MDX files in the docs directory
29-
find docs -name "*.mdx" -type f | while read file; do
30-
echo "Validating: $file"
31-
node -e "
32-
const fs = require('fs');
33-
const { compile } = require('@mdx-js/mdx');
34-
35-
try {
36-
const content = fs.readFileSync('$file', 'utf8');
37-
compile(content, { jsx: true });
38-
console.log('✅ $file - Valid MDX');
39-
} catch (error) {
40-
console.error('❌ $file - MDX Error:', error.message);
41-
process.exit(1);
42-
}
43-
"
44-
done
27+
run: node scripts/validate-mdx.js
4528

4629
- name: Check for broken links
4730
run: |

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
2+
"type": "module",
23
"devDependencies": {
34
"@mdx-js/loader": "^3.1.0",
4-
"@mdx-js/mdx": "^3.1.0"
5+
"@mdx-js/mdx": "^3.1.0",
6+
"glob": "^10.3.10"
57
}
68
}

scripts/validate-mdx.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import fs from 'fs';
2+
import { compile } from '@mdx-js/mdx';
3+
import { glob } from 'glob';
4+
5+
async function validateMDX() {
6+
try {
7+
const mdxFiles = await glob('docs/**/*.mdx');
8+
9+
for (const file of mdxFiles) {
10+
console.log(`Validating: ${file}`);
11+
try {
12+
const content = fs.readFileSync(file, 'utf8');
13+
await compile(content, { jsx: true });
14+
console.log(`✅ ${file} - Valid MDX`);
15+
} catch (error) {
16+
console.error(`❌ ${file} - MDX Error:`, error.message);
17+
process.exit(1);
18+
}
19+
}
20+
21+
console.log(`\n🎉 All ${mdxFiles.length} MDX files are valid!`);
22+
} catch (error) {
23+
console.error('❌ Validation failed:', error.message);
24+
process.exit(1);
25+
}
26+
}
27+
28+
validateMDX();

0 commit comments

Comments
 (0)