Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c597a7a

Browse files
committed
Emit diagnostic if file is not installed
1 parent 8ea1a11 commit c597a7a

6 files changed

Lines changed: 55 additions & 5 deletions

File tree

lib/actions-util.js

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/actions-util.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action.js

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/actions-util.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,14 @@ export function getWorkflowRunAttempt(): number {
426426
return workflowRunAttempt;
427427
}
428428

429+
export class FileCmdNotFoundError extends Error {
430+
constructor(msg: string) {
431+
super(msg);
432+
433+
this.name = "FileCmdNotFoundError";
434+
}
435+
}
436+
429437
/**
430438
* Tries to obtain the output of the `file` command for the file at the specified path.
431439
* The output will vary depending on the type of `file`, which operating system we are running on, etc.
@@ -442,7 +450,7 @@ export const getFileType = async (filePath: string): Promise<string> => {
442450
core.info(
443451
"The `file` program is required, but does not appear to be installed. Please install it.",
444452
);
445-
throw e;
453+
throw new FileCmdNotFoundError(`${e}`);
446454
}
447455

448456
try {

src/init-action.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { safeWhich } from "@chrisgavin/safe-which";
66
import { v4 as uuidV4 } from "uuid";
77

88
import {
9+
FileCmdNotFoundError,
910
getActionVersion,
1011
getFileType,
1112
getOptionalInput,
@@ -15,6 +16,7 @@ import {
1516
import { getGitHubVersion } from "./api-client";
1617
import { CodeQL } from "./codeql";
1718
import * as configUtils from "./config-utils";
19+
import { addDiagnostic, makeDiagnostic } from "./diagnostics";
1820
import { EnvVar } from "./environment";
1921
import { Feature, Features } from "./feature-flags";
2022
import { checkInstallPython311, initCodeQL, initConfig, runInit } from "./init";
@@ -362,6 +364,27 @@ async function run() {
362364
logger.warning(
363365
`Analyzing Go on Linux, but failed to install wrapper script. Tracing custom builds may fail: ${e}`,
364366
);
367+
368+
if (e instanceof FileCmdNotFoundError) {
369+
addDiagnostic(
370+
config,
371+
Language.go,
372+
makeDiagnostic(
373+
"go/workflow/file-program-unavailable",
374+
"The `file` program is required, but does not appear to be installed",
375+
{
376+
markdownMessage:
377+
"CodeQL was unable to find the `file` program on this system. Ensure that the `file` program is installed on the runner and accessible.",
378+
visibility: {
379+
statusPage: true,
380+
telemetry: true,
381+
cliSummaryTable: true,
382+
},
383+
severity: "warning",
384+
},
385+
),
386+
);
387+
}
365388
}
366389
} else {
367390
// Store the location of the original Go binary, so we can check that no setup tasks were performed after the

0 commit comments

Comments
 (0)