Produce a clearer error message when file is not installed

This commit is contained in:
Michael B. Gale 2024-04-11 12:57:47 +01:00
parent 24a01703e4
commit 8ea1a11e72
No known key found for this signature in database
GPG key ID: FF5E2765BD00628F
3 changed files with 31 additions and 15 deletions

10
lib/actions-util.js generated
View file

@ -387,11 +387,19 @@ exports.getWorkflowRunAttempt = getWorkflowRunAttempt;
const getFileType = async (filePath) => {
let stderr = "";
let stdout = "";
let fileCmdPath;
try {
fileCmdPath = await safeWhich.safeWhich("file");
}
catch (e) {
core.info("The `file` program is required, but does not appear to be installed. Please install it.");
throw e;
}
try {
// The `file` command will output information about the type of file pointed at by `filePath`.
// For binary files, this may include e.g. whether they are static of dynamic binaries.
// The `-L` switch instructs the command to follow symbolic links.
await new toolrunner.ToolRunner(await safeWhich.safeWhich("file"), ["-L", filePath], {
await new toolrunner.ToolRunner(fileCmdPath, ["-L", filePath], {
silent: true,
listeners: {
stdout: (data) => {

File diff suppressed because one or more lines are too long

View file

@ -433,25 +433,33 @@ export function getWorkflowRunAttempt(): number {
export const getFileType = async (filePath: string): Promise<string> => {
let stderr = "";
let stdout = "";
let fileCmdPath: string;
try {
fileCmdPath = await safeWhich.safeWhich("file");
} catch (e) {
core.info(
"The `file` program is required, but does not appear to be installed. Please install it.",
);
throw e;
}
try {
// The `file` command will output information about the type of file pointed at by `filePath`.
// For binary files, this may include e.g. whether they are static of dynamic binaries.
// The `-L` switch instructs the command to follow symbolic links.
await new toolrunner.ToolRunner(
await safeWhich.safeWhich("file"),
["-L", filePath],
{
silent: true,
listeners: {
stdout: (data) => {
stdout += data.toString();
},
stderr: (data) => {
stderr += data.toString();
},
await new toolrunner.ToolRunner(fileCmdPath, ["-L", filePath], {
silent: true,
listeners: {
stdout: (data) => {
stdout += data.toString();
},
stderr: (data) => {
stderr += data.toString();
},
},
).exec();
}).exec();
return stdout.trim();
} catch (e) {
core.info(