mirror of
https://github.com/github/codeql-action.git
synced 2026-11-05 12:39:48 +00:00
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import * as fs from "fs";
|
|
import * as path from "path";
|
|
|
|
import * as core from "@actions/core";
|
|
|
|
import type * as diagnostics from "../src/diagnostics";
|
|
|
|
const DIAGNOSTIC_ID = "codeql-action/forced-nightly-cli";
|
|
const diagnosticDirectory = process.env["DIAGNOSTICS_DIR"];
|
|
|
|
if (diagnosticDirectory === undefined) {
|
|
throw new Error("DIAGNOSTICS_DIR is undefined.");
|
|
}
|
|
|
|
const paths = fs
|
|
.readdirSync(diagnosticDirectory, {
|
|
recursive: true,
|
|
encoding: "utf-8",
|
|
})
|
|
.filter((p) => p.endsWith(".json"));
|
|
|
|
core.info(`Found ${paths.length} paths in '${diagnosticDirectory}'.`);
|
|
core.info(`Searching for a diagnostic with id '${DIAGNOSTIC_ID}'...`);
|
|
|
|
let found = false;
|
|
for (const diagnosticPath of paths) {
|
|
if (path.extname(diagnosticPath) !== ".json") {
|
|
core.info(`Skipping ${diagnosticPath}.`);
|
|
continue;
|
|
}
|
|
core.info(`Found ${diagnosticPath}.`);
|
|
|
|
const contents = JSON.parse(
|
|
fs.readFileSync(path.resolve(diagnosticDirectory, diagnosticPath), "utf-8"),
|
|
) as diagnostics.DiagnosticMessage;
|
|
|
|
if (contents.source.id === DIAGNOSTIC_ID) {
|
|
core.info(
|
|
`Found '${DIAGNOSTIC_ID}' in '${diagnosticPath}'. Skipping remaining files.`,
|
|
);
|
|
found = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!found) {
|
|
throw new Error(`Didn't find '${DIAGNOSTIC_ID}' diagnostic.`);
|
|
}
|