Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
spacevx committed Mar 7, 2024
1 parent dde8f66 commit 7d8776c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/scripts/checkDocs.js
Original file line number Diff line number Diff line change
@@ -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('./');
29 changes: 29 additions & 0 deletions .github/workflows/error.yml
Original file line number Diff line number Diff line change
@@ -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 }}

0 comments on commit 7d8776c

Please sign in to comment.