diff --git a/.github/scripts/validate-content-tree.js b/.github/scripts/validate-content-tree.js new file mode 100644 index 00000000000..98386de582a --- /dev/null +++ b/.github/scripts/validate-content-tree.js @@ -0,0 +1,22 @@ +const { readdirSync } = require('node:fs'); + +let exitCode = 0; + +const next = ['concepts', 'terms']; + +function checkPath(path, i) { + for (const entry of readdirSync(path)) { + const entryDir = readdirSync(`${path}/${entry}`); + if (!entryDir.includes(`${entry}.md`)) { + console.error(`\n${path}/${entry} should contain a ${entry}.md file\n`); + exitCode = 1; + } + if (i < 2 && entryDir.includes(next[i])) { + checkPath(`${path}/${entry}/${next[i]}`, i + 1); + } + } +} + +checkPath('content', 0); + +process.exit(exitCode); diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index c666a7e3c87..10609797248 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - command: ["compile", "format:verify", "lint:js", "lint:md", "test"] + command: ["compile", "format:verify", "lint:js", "lint:md", "test", "validate-content-tree"] on: push: diff --git a/package.json b/package.json index d1c0b64275a..25ccb7da153 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,8 @@ "lint:md": "markdownlint \"./content/**/*.md\"", "lint": "yarn lint:md && yarn lint:js", "test": "jest", - "prepare": "husky install" + "prepare": "husky install", + "validate-content-tree": "node .github/scripts/validate-content-tree.js" }, "license": "UNLICENSED", "version": "1.0.0"