Merge pull request #4055 from backstage/rugvip/nodep

workflows: run link verification as part of microsite CI checks
This commit is contained in:
Patrik Oldsberg
2021-01-14 14:58:45 +01:00
committed by GitHub
2 changed files with 30 additions and 8 deletions
@@ -27,6 +27,9 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- name: verify doc links
run: node scripts/verify-links.js
# Skip caching of microsite dependencies, it keeps the global cache size
# smaller, which make Windows builds a lot faster for the rest of the project.
- name: yarn install
+27 -8
View File
@@ -18,8 +18,27 @@
/* eslint-disable import/no-extraneous-dependencies */
const { resolve: resolvePath, join: joinPath, dirname } = require('path');
const fs = require('fs-extra');
const recursive = require('recursive-readdir');
const fs = require('fs').promises;
const { existsSync } = require('fs');
const IGNORED_DIRS = ['node_modules', 'dist', 'bin', '.git'];
async function listFiles(dir) {
const files = await fs.readdir(dir);
const paths = await Promise.all(
files
.filter(file => !IGNORED_DIRS.includes(file))
.map(async file => {
const path = joinPath(dir, file);
if ((await fs.stat(path)).isDirectory()) {
return listFiles(path);
}
return path;
}),
);
return paths.flat();
}
const projectRoot = resolvePath(__dirname, '..');
@@ -65,7 +84,7 @@ async function verifyUrl(basePath, absUrl, docPages) {
}
const staticPath = resolvePath(projectRoot, 'microsite/static', `.${url}`);
if (await fs.pathExists(staticPath)) {
if (existsSync(staticPath)) {
return undefined;
}
@@ -82,8 +101,7 @@ async function verifyUrl(basePath, absUrl, docPages) {
return { url, basePath, problem: 'out-of-docs' };
}
const exists = await fs.pathExists(path);
if (!exists) {
if (!existsSync(path)) {
return { url, basePath, problem: 'missing' };
}
@@ -110,7 +128,7 @@ async function verifyFile(filePath, docPages) {
// It is used to validate microsite links from outside /docs/, as those
// are not transformed from the markdown file representation by docusaurus.
async function findExternalDocsLinks(dir) {
const allFiles = await recursive(dir);
const allFiles = await listFiles(dir);
const mdFiles = allFiles.filter(p => p.endsWith('.md'));
const paths = new Map();
@@ -138,14 +156,15 @@ async function findExternalDocsLinks(dir) {
async function main() {
process.chdir(projectRoot);
const files = await recursive('.', ['node_modules', 'dist', 'bin']);
const files = await listFiles('.');
const mdFiles = files.filter(f => f.endsWith('.md'));
const badUrls = [];
const docPages = await findExternalDocsLinks('docs');
const docPageSet = new Set(docPages.values());
for (const mdFile of mdFiles) {
const badFileUrls = await verifyFile(mdFile, new Set(docPages.values()));
const badFileUrls = await verifyFile(mdFile, docPageSet);
badUrls.push(...badFileUrls);
}