forked from citizenfx/natives
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('./'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |