From 7d8776c50e678ac6214abc8285068e593219a890 Mon Sep 17 00:00:00 2001 From: Space V <40030799+ahcenezdh@users.noreply.github.com> Date: Thu, 7 Mar 2024 17:54:09 +0100 Subject: [PATCH] test --- .github/scripts/checkDocs.js | 38 ++++++++++++++++++++++++++++++++++++ .github/workflows/error.yml | 29 +++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 .github/scripts/checkDocs.js create mode 100644 .github/workflows/error.yml diff --git a/.github/scripts/checkDocs.js b/.github/scripts/checkDocs.js new file mode 100644 index 000000000..7b8e70a65 --- /dev/null +++ b/.github/scripts/checkDocs.js @@ -0,0 +1,38 @@ +const fs = require('fs'); +const path = require('path'); + +/** + * Recursively checks documentation in the specified directory. + * @param {string} dir The directory to check. + */ +const checkDocumentation = (dir) => { + fs.readdirSync(dir, { withFileTypes: true }).forEach((file) => { + if (file.isDirectory()) { + const workspacePath = path.join(dir, file.name); + fs.readdirSync(workspacePath).forEach((doc) => { + const docPath = path.join(workspacePath, doc); + if (doc.endsWith('.md')) { + const content = fs.readFileSync(docPath, 'utf8'); + + // Check for the ns header + const nsHeaderRegex = /^---\nns: (.*)\n---/m; + const nsMatch = content.match(nsHeaderRegex); + if (!nsMatch) { + console.error(`Invalid or missing 'ns' header in ${docPath}`); + process.exit(1); + } + + // Verify if ns matches the directory name (workspace) + const nsValue = nsMatch[1]; + if (nsValue !== file.name) { + console.error(`The native \`${doc}\` is located in the '${file.name}' directory but should be in '${nsValue}' (based on the ns).`); + process.exit(1); + } + } + }); + } + }); +}; + +// Start checking from the project's workspace directories under the root +checkDocumentation('./'); \ No newline at end of file diff --git a/.github/workflows/error.yml b/.github/workflows/error.yml new file mode 100644 index 000000000..a88714370 --- /dev/null +++ b/.github/workflows/error.yml @@ -0,0 +1,29 @@ +name: Validate Markdown Documentation + +on: + push: + paths: + - '**/*.md' + +jobs: + check-markdown-docs: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + with: + path: './' + fetch-depth: 2 + + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: '12' + + - name: Get modified .md files + id: get-modified-files + run: | + echo "::set-output name=modified_md_files::$(git diff --name-only HEAD HEAD~ -- '*.md')" + + - name: Check Markdown Documentation + run: node .github/scripts/checkDocs.js ${{ steps.get-modified-files.outputs.modified_md_files }}