Skip to content

Commit 1829b70

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

File tree

6 files changed

+57
-5
lines changed

6 files changed

+57
-5
lines changed

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: 11 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,9 @@ 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(
454+
`The \`file\` program is not installed: ${e}`,
455+
);
446456
}
447457

448458
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";
@@ -372,6 +374,27 @@ async function run() {
372374
logger.warning(
373375
`Failed to determine the location of the Go binary: ${e}`,
374376
);
377+
378+
if (e instanceof FileCmdNotFoundError) {
379+
addDiagnostic(
380+
config,
381+
Language.go,
382+
makeDiagnostic(
383+
"go/workflow/file-program-unavailable",
384+
"The `file` program is required, but does not appear to be installed",
385+
{
386+
markdownMessage:
387+
"CodeQL was unable to find the `file` program on this system. Ensure that the `file` program is installed on the runner and accessible.",
388+
visibility: {
389+
statusPage: true,
390+
telemetry: true,
391+
cliSummaryTable: true,
392+
},
393+
severity: "warning",
394+
},
395+
),
396+
);
397+
}
375398
}
376399
}
377400

0 commit comments

Comments
 (0)