|
| 1 | +name: documentation |
| 2 | +on: |
| 3 | + workflow_call: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +jobs: |
| 7 | + documentation: |
| 8 | + name: Documentation / MDX checks |
| 9 | + permissions: |
| 10 | + contents: read |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Checkout code |
| 14 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 15 | + with: |
| 16 | + persist-credentials: false |
| 17 | + |
| 18 | + - name: Setup Node.js |
| 19 | + uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0 |
| 20 | + with: |
| 21 | + node-version-file: application/ui/.nvmrc |
| 22 | + package-manager-cache: false |
| 23 | + |
| 24 | + - name: Validate MDX syntax in Documentation |
| 25 | + shell: bash |
| 26 | + run: | |
| 27 | + echo "Validating MDX/JSX syntax in Documentation files..." |
| 28 | + WORKDIR=$(mktemp -d) |
| 29 | + cd "$WORKDIR" |
| 30 | + npm init -y >/dev/null 2>&1 |
| 31 | + npm install --no-save @mdx-js/mdx@3 remark-comment@1.0.0 fast-glob@3.3.2 >/dev/null 2>&1 |
| 32 | + cat > "$WORKDIR/validate-mdx.mjs" << 'SCRIPT' |
| 33 | + import { readFile } from "node:fs/promises"; |
| 34 | + import fg from "fast-glob"; |
| 35 | + import { compile } from "@mdx-js/mdx"; |
| 36 | + import remarkComment from 'remark-comment'; |
| 37 | + const workspace = process.env.WORKSPACE; |
| 38 | + process.chdir(workspace); |
| 39 | + const files = await fg(["application/docs/**/*.md", "library/docs/**/*.md"], { |
| 40 | + ignore: [ |
| 41 | + "**/node_modules/**", |
| 42 | + "**/.git/**", |
| 43 | + "**/.venv/**", |
| 44 | + "**/dist/**", |
| 45 | + "**/build/**", |
| 46 | + "**/.next/**" |
| 47 | + ] |
| 48 | + }); |
| 49 | + console.log(`Found ${files.length} documentation file(s) to validate\n`); |
| 50 | + let hasErrors = false; |
| 51 | + let errorCount = 0; |
| 52 | + for (const file of files) { |
| 53 | + try { |
| 54 | + const source = await readFile(file, "utf8"); |
| 55 | + await compile(source, { filepath: file, remarkPlugins: [remarkComment] }); |
| 56 | + process.stdout.write("."); |
| 57 | + } catch (error) { |
| 58 | + hasErrors = true; |
| 59 | + errorCount++; |
| 60 | + process.stdout.write("\n"); |
| 61 | + console.error(`\n❌ MDX parse error in ${file}:`); |
| 62 | + console.error(error.message ?? error); |
| 63 | + if (error.position) { |
| 64 | + console.error(` Line ${error.position.start.line}, Column ${error.position.start.column}`); |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | + console.log("\n"); |
| 69 | + if (hasErrors) { |
| 70 | + console.error(`❌ Found ${errorCount} file(s) with MDX/JSX syntax errors`); |
| 71 | + process.exit(1); |
| 72 | + } else { |
| 73 | + console.log(`✅ All ${files.length} file(s) passed MDX validation`); |
| 74 | + } |
| 75 | + SCRIPT |
| 76 | + WORKSPACE="$GITHUB_WORKSPACE" NODE_PATH="$WORKDIR/node_modules" node "$WORKDIR/validate-mdx.mjs" |
0 commit comments