Fix docs:build workflow run on a tag (#33064)
where js-sdk workflows are not available
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import fs from "node:fs";
|
import fs from "node:fs/promises";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import YAML from "yaml";
|
import YAML from "yaml";
|
||||||
import parseArgs from "minimist";
|
import parseArgs from "minimist";
|
||||||
@@ -288,16 +288,16 @@ function getTriggerNodes<K extends keyof WorkflowYaml["on"]>(key: K, workflow: W
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function readFile(...pathSegments: string[]): string {
|
function readFile(...pathSegments: string[]): Promise<string> {
|
||||||
return fs.readFileSync(path.join(...pathSegments), { encoding: "utf-8" });
|
return fs.readFile(path.join(...pathSegments), { encoding: "utf-8" });
|
||||||
}
|
}
|
||||||
|
|
||||||
function readJson<T extends object>(...pathSegments: string[]): T {
|
async function readJson<T extends object>(...pathSegments: string[]): Promise<T> {
|
||||||
return JSON.parse(readFile(...pathSegments));
|
return JSON.parse(await readFile(...pathSegments));
|
||||||
}
|
}
|
||||||
|
|
||||||
function readYaml<T extends object>(...pathSegments: string[]): T {
|
async function readYaml<T extends object>(...pathSegments: string[]): Promise<T> {
|
||||||
return YAML.parse(readFile(...pathSegments));
|
return YAML.parse(await readFile(...pathSegments));
|
||||||
}
|
}
|
||||||
|
|
||||||
function toArray<T>(v: T | T[]): T[] {
|
function toArray<T>(v: T | T[]): T[] {
|
||||||
@@ -442,9 +442,17 @@ export default async function main(dirs: string[], on?: string[], print = false,
|
|||||||
const {
|
const {
|
||||||
name,
|
name,
|
||||||
repository: { url },
|
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");
|
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 = {
|
const project: Project = {
|
||||||
name,
|
name,
|
||||||
url,
|
url,
|
||||||
@@ -452,8 +460,8 @@ export default async function main(dirs: string[], on?: string[], print = false,
|
|||||||
workflows: new Map(),
|
workflows: new Map(),
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const file of fs.readdirSync(workflowsPath).filter((f) => f.endsWith(".yml") || f.endsWith(".yaml"))) {
|
for (const file of files.filter((f) => f.endsWith(".yml") || f.endsWith(".yaml"))) {
|
||||||
const data = readYaml<WorkflowYaml>(workflowsPath, file);
|
const data = await readYaml<WorkflowYaml>(workflowsPath, file);
|
||||||
const name = data.name ?? file;
|
const name = data.name ?? file;
|
||||||
const workflow: Workflow = {
|
const workflow: Workflow = {
|
||||||
id: `${project.name}/${name}`,
|
id: `${project.name}/${name}`,
|
||||||
|
|||||||
Reference in New Issue
Block a user