Filter set of possible Action inputs to those from a particular job

This better handles cases where customers have a monorepo and have
separate jobs for different components.
This commit is contained in:
Henry Mercer 2022-11-25 17:40:27 +00:00
parent 9f2aa7ec75
commit 8f05fcd048
6 changed files with 90 additions and 25 deletions

14
lib/workflow.js generated
View file

@ -262,13 +262,15 @@ exports.getStepsCallingAction = getStepsCallingAction;
* @throws an error if the value of the input could not be determined, or we could not
* determine that no such input is passed to the Action.
*/
function getInputOrThrow(workflow, actionName, inputName, matrixVars) {
function getInputOrThrow(workflow, jobName, actionName, inputName, matrixVars) {
if (!workflow.jobs) {
throw new Error(`Could not get ${inputName} input to ${actionName} since the workflow has no jobs.`);
}
const inputs = Object.values(workflow.jobs)
.map((job) => getStepsCallingAction(job, actionName).map((step) => { var _a; return (_a = step.with) === null || _a === void 0 ? void 0 : _a[inputName]; }))
.flat()
if (!workflow.jobs[jobName]) {
throw new Error(`Could not get ${inputName} input to ${actionName} since the workflow has no job named ${jobName}.`);
}
const inputs = getStepsCallingAction(workflow.jobs[jobName], actionName)
.map((step) => { var _a; return (_a = step.with) === null || _a === void 0 ? void 0 : _a[inputName]; })
.filter((input) => input !== undefined)
.map((input) => input);
if (inputs.length === 0) {
@ -296,8 +298,8 @@ function getInputOrThrow(workflow, actionName, inputName, matrixVars) {
* @returns the category input, or undefined if the category input is not defined
* @throws an error if the category input could not be determined
*/
function getCategoryInputOrThrow(workflow, matrixVars) {
return getInputOrThrow(workflow, "github/codeql-action/analyze", "category", matrixVars);
function getCategoryInputOrThrow(workflow, jobName, matrixVars) {
return getInputOrThrow(workflow, jobName, "github/codeql-action/analyze", "category", matrixVars);
}
exports.getCategoryInputOrThrow = getCategoryInputOrThrow;
//# sourceMappingURL=workflow.js.map