Add function to read the analysis category from a workflow
This commit is contained in:
parent
996d04b1e5
commit
e2d523ca5e
6 changed files with 227 additions and 3 deletions
31
lib/workflow.js
generated
31
lib/workflow.js
generated
|
|
@ -19,7 +19,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getWorkflowRunID = exports.getWorkflowPath = exports.getWorkflow = exports.formatWorkflowCause = exports.formatWorkflowErrors = exports.validateWorkflow = exports.getWorkflowErrors = exports.WorkflowErrors = exports.patternIsSuperset = void 0;
|
||||
exports.getCategoryInput = exports.getAnalyzeSteps = exports.getWorkflowRunID = exports.getWorkflowPath = exports.getWorkflow = exports.formatWorkflowCause = exports.formatWorkflowErrors = exports.validateWorkflow = exports.getWorkflowErrors = exports.WorkflowErrors = exports.patternIsSuperset = void 0;
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const core = __importStar(require("@actions/core"));
|
||||
|
|
@ -246,4 +246,33 @@ function getWorkflowRunID() {
|
|||
return workflowRunID;
|
||||
}
|
||||
exports.getWorkflowRunID = getWorkflowRunID;
|
||||
function getAnalyzeSteps(job) {
|
||||
const steps = job.steps;
|
||||
if (!Array.isArray(steps)) {
|
||||
throw new Error("Could not get analyze steps since job.steps was not an array.");
|
||||
}
|
||||
return steps.filter((step) => { var _a; return (_a = step.uses) === null || _a === void 0 ? void 0 : _a.includes("github/codeql-action/analyze"); });
|
||||
}
|
||||
exports.getAnalyzeSteps = getAnalyzeSteps;
|
||||
function getCategoryInput(workflow) {
|
||||
if (!workflow.jobs) {
|
||||
throw new Error("Could not get category input since workflow.jobs was undefined.");
|
||||
}
|
||||
const categories = Object.values(workflow.jobs)
|
||||
.map((job) => getAnalyzeSteps(job).map((step) => { var _a; return (_a = step.with) === null || _a === void 0 ? void 0 : _a.category; }))
|
||||
.flat()
|
||||
.filter((category) => category !== undefined)
|
||||
.map((category) => category);
|
||||
if (categories.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
if (!categories.every((category) => category === categories[0])) {
|
||||
throw new Error("Could not get category input since multiple categories were specified by the analysis step.");
|
||||
}
|
||||
if (categories[0].includes("${{")) {
|
||||
throw new Error("Could not get category input since it contained a dynamic value.");
|
||||
}
|
||||
return categories[0];
|
||||
}
|
||||
exports.getCategoryInput = getCategoryInput;
|
||||
//# sourceMappingURL=workflow.js.map
|
||||
Loading…
Add table
Add a link
Reference in a new issue