Emit diagnostic if file is not installed
This commit is contained in:
parent
8ea1a11e72
commit
1829b70201
6 changed files with 57 additions and 5 deletions
11
lib/actions-util.js
generated
11
lib/actions-util.js
generated
|
|
@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getFileType = exports.getWorkflowRunAttempt = exports.getWorkflowRunID = exports.getUploadValue = exports.printDebugLogs = exports.isAnalyzingDefaultBranch = exports.getRelativeScriptPath = exports.isRunningLocalAction = exports.getWorkflowEventName = exports.getActionVersion = exports.getRef = exports.determineMergeBaseCommitOid = exports.getCommitOid = exports.getTemporaryDirectory = exports.getOptionalInput = exports.getRequiredInput = void 0;
|
||||
exports.getFileType = exports.FileCmdNotFoundError = exports.getWorkflowRunAttempt = exports.getWorkflowRunID = exports.getUploadValue = exports.printDebugLogs = exports.isAnalyzingDefaultBranch = exports.getRelativeScriptPath = exports.isRunningLocalAction = exports.getWorkflowEventName = exports.getActionVersion = exports.getRef = exports.determineMergeBaseCommitOid = exports.getCommitOid = exports.getTemporaryDirectory = exports.getOptionalInput = exports.getRequiredInput = void 0;
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const core = __importStar(require("@actions/core"));
|
||||
|
|
@ -380,6 +380,13 @@ function getWorkflowRunAttempt() {
|
|||
return workflowRunAttempt;
|
||||
}
|
||||
exports.getWorkflowRunAttempt = getWorkflowRunAttempt;
|
||||
class FileCmdNotFoundError extends Error {
|
||||
constructor(msg) {
|
||||
super(msg);
|
||||
this.name = "FileCmdNotFoundError";
|
||||
}
|
||||
}
|
||||
exports.FileCmdNotFoundError = FileCmdNotFoundError;
|
||||
/**
|
||||
* Tries to obtain the output of the `file` command for the file at the specified path.
|
||||
* The output will vary depending on the type of `file`, which operating system we are running on, etc.
|
||||
|
|
@ -393,7 +400,7 @@ const getFileType = async (filePath) => {
|
|||
}
|
||||
catch (e) {
|
||||
core.info("The `file` program is required, but does not appear to be installed. Please install it.");
|
||||
throw e;
|
||||
throw new FileCmdNotFoundError(`The \`file\` program is not installed: ${e}`);
|
||||
}
|
||||
try {
|
||||
// The `file` command will output information about the type of file pointed at by `filePath`.
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
12
lib/init-action.js
generated
12
lib/init-action.js
generated
|
|
@ -30,6 +30,7 @@ const safe_which_1 = require("@chrisgavin/safe-which");
|
|||
const uuid_1 = require("uuid");
|
||||
const actions_util_1 = require("./actions-util");
|
||||
const api_client_1 = require("./api-client");
|
||||
const diagnostics_1 = require("./diagnostics");
|
||||
const environment_1 = require("./environment");
|
||||
const feature_flags_1 = require("./feature-flags");
|
||||
const init_1 = require("./init");
|
||||
|
|
@ -223,6 +224,17 @@ async function run() {
|
|||
}
|
||||
catch (e) {
|
||||
logger.warning(`Failed to determine the location of the Go binary: ${e}`);
|
||||
if (e instanceof actions_util_1.FileCmdNotFoundError) {
|
||||
(0, diagnostics_1.addDiagnostic)(config, languages_1.Language.go, (0, diagnostics_1.makeDiagnostic)("go/workflow/file-program-unavailable", "The `file` program is required, but does not appear to be installed", {
|
||||
markdownMessage: "CodeQL was unable to find the `file` program on this system. Ensure that the `file` program is installed on the runner and accessible.",
|
||||
visibility: {
|
||||
statusPage: true,
|
||||
telemetry: true,
|
||||
cliSummaryTable: true,
|
||||
},
|
||||
severity: "warning",
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Limit RAM and threads for extractors. When running extractors, the CodeQL CLI obeys the
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -426,6 +426,14 @@ export function getWorkflowRunAttempt(): number {
|
|||
return workflowRunAttempt;
|
||||
}
|
||||
|
||||
export class FileCmdNotFoundError extends Error {
|
||||
constructor(msg: string) {
|
||||
super(msg);
|
||||
|
||||
this.name = "FileCmdNotFoundError";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to obtain the output of the `file` command for the file at the specified path.
|
||||
* 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> => {
|
|||
core.info(
|
||||
"The `file` program is required, but does not appear to be installed. Please install it.",
|
||||
);
|
||||
throw e;
|
||||
throw new FileCmdNotFoundError(
|
||||
`The \`file\` program is not installed: ${e}`,
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import { safeWhich } from "@chrisgavin/safe-which";
|
|||
import { v4 as uuidV4 } from "uuid";
|
||||
|
||||
import {
|
||||
FileCmdNotFoundError,
|
||||
getActionVersion,
|
||||
getFileType,
|
||||
getOptionalInput,
|
||||
|
|
@ -15,6 +16,7 @@ import {
|
|||
import { getGitHubVersion } from "./api-client";
|
||||
import { CodeQL } from "./codeql";
|
||||
import * as configUtils from "./config-utils";
|
||||
import { addDiagnostic, makeDiagnostic } from "./diagnostics";
|
||||
import { EnvVar } from "./environment";
|
||||
import { Feature, Features } from "./feature-flags";
|
||||
import { checkInstallPython311, initCodeQL, initConfig, runInit } from "./init";
|
||||
|
|
@ -372,6 +374,27 @@ async function run() {
|
|||
logger.warning(
|
||||
`Failed to determine the location of the Go binary: ${e}`,
|
||||
);
|
||||
|
||||
if (e instanceof FileCmdNotFoundError) {
|
||||
addDiagnostic(
|
||||
config,
|
||||
Language.go,
|
||||
makeDiagnostic(
|
||||
"go/workflow/file-program-unavailable",
|
||||
"The `file` program is required, but does not appear to be installed",
|
||||
{
|
||||
markdownMessage:
|
||||
"CodeQL was unable to find the `file` program on this system. Ensure that the `file` program is installed on the runner and accessible.",
|
||||
visibility: {
|
||||
statusPage: true,
|
||||
telemetry: true,
|
||||
cliSummaryTable: true,
|
||||
},
|
||||
severity: "warning",
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue