Add utility function to run file command

This commit is contained in:
Michael B. Gale 2023-09-28 11:46:00 +01:00
parent c08086a26a
commit 3c15d2383b
No known key found for this signature in database
GPG key ID: FF5E2765BD00628F
3 changed files with 58 additions and 2 deletions

28
lib/actions-util.js generated
View file

@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
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.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,4 +380,30 @@ function getWorkflowRunAttempt() {
return workflowRunAttempt;
}
exports.getWorkflowRunAttempt = getWorkflowRunAttempt;
/**
* Tries to obtain the output of the `file` command for the file at the specified path.
*/
const getFileType = async (fp) => {
let stderr = "";
try {
let fileOut = "";
await new toolrunner.ToolRunner(await safeWhich.safeWhich("file"), ["-L", fp], {
silent: true,
listeners: {
stdout: (data) => {
fileOut += data.toString();
},
stderr: (data) => {
stderr += data.toString();
},
},
}).exec();
return fileOut;
}
catch (e) {
core.info(`Could not determine type of ${fp}. ${stderr}`);
throw e;
}
};
exports.getFileType = getFileType;
//# sourceMappingURL=actions-util.js.map