Add utility function to run file command
This commit is contained in:
parent
c08086a26a
commit
3c15d2383b
3 changed files with 58 additions and 2 deletions
28
lib/actions-util.js
generated
28
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.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
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -425,3 +425,33 @@ export function getWorkflowRunAttempt(): number {
|
|||
}
|
||||
return workflowRunAttempt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to obtain the output of the `file` command for the file at the specified path.
|
||||
*/
|
||||
export const getFileType = async (fp: string): Promise<string> => {
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue