From dc06d36b9f3ddf8a876ed9e5aee2e149e9c1fdbb Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 7 Apr 2026 22:48:52 +0100 Subject: [PATCH] Fix docs:build workflow run on a tag (#33064) where js-sdk workflows are not available --- scripts/gen-workflow-mermaid.ts | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/scripts/gen-workflow-mermaid.ts b/scripts/gen-workflow-mermaid.ts index fd4893e39f..9038a706de 100755 --- a/scripts/gen-workflow-mermaid.ts +++ b/scripts/gen-workflow-mermaid.ts @@ -1,4 +1,4 @@ -import fs from "node:fs"; +import fs from "node:fs/promises"; import path from "node:path"; import YAML from "yaml"; import parseArgs from "minimist"; @@ -288,16 +288,16 @@ function getTriggerNodes(key: K, workflow: W }); } -function readFile(...pathSegments: string[]): string { - return fs.readFileSync(path.join(...pathSegments), { encoding: "utf-8" }); +function readFile(...pathSegments: string[]): Promise { + return fs.readFile(path.join(...pathSegments), { encoding: "utf-8" }); } -function readJson(...pathSegments: string[]): T { - return JSON.parse(readFile(...pathSegments)); +async function readJson(...pathSegments: string[]): Promise { + return JSON.parse(await readFile(...pathSegments)); } -function readYaml(...pathSegments: string[]): T { - return YAML.parse(readFile(...pathSegments)); +async function readYaml(...pathSegments: string[]): Promise { + return YAML.parse(await readFile(...pathSegments)); } function toArray(v: T | T[]): T[] { @@ -442,9 +442,17 @@ export default async function main(dirs: string[], on?: string[], print = false, const { name, repository: { url }, - } = readJson<{ name: string; repository: { url: string } }>(projectPath, "package.json"); + } = await readJson<{ name: string; repository: { url: string } }>(projectPath, "package.json"); const workflowsPath = path.join(projectPath, ".github", "workflows"); + let files: string[]; + try { + files = await fs.readdir(workflowsPath); + } catch (e) { + console.error(`Could not read ${workflowsPath}`, e); + continue; + } + const project: Project = { name, url, @@ -452,8 +460,8 @@ export default async function main(dirs: string[], on?: string[], print = false, workflows: new Map(), }; - for (const file of fs.readdirSync(workflowsPath).filter((f) => f.endsWith(".yml") || f.endsWith(".yaml"))) { - const data = readYaml(workflowsPath, file); + for (const file of files.filter((f) => f.endsWith(".yml") || f.endsWith(".yaml"))) { + const data = await readYaml(workflowsPath, file); const name = data.name ?? file; const workflow: Workflow = { id: `${project.name}/${name}`,