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:
parent
9f2aa7ec75
commit
8f05fcd048
6 changed files with 90 additions and 25 deletions
|
|
@ -537,7 +537,8 @@ test("getCategoryInputOrThrow returns category for simple workflow with category
|
|||
- uses: github/codeql-action/analyze@v2
|
||||
with:
|
||||
category: some-category
|
||||
`) as Workflow,
|
||||
`) as Workflow,
|
||||
"analysis",
|
||||
{}
|
||||
),
|
||||
"some-category"
|
||||
|
|
@ -555,13 +556,45 @@ test("getCategoryInputOrThrow returns undefined for simple workflow without cate
|
|||
- uses: actions/checkout@v2
|
||||
- uses: github/codeql-action/init@v2
|
||||
- uses: github/codeql-action/analyze@v2
|
||||
`) as Workflow,
|
||||
`) as Workflow,
|
||||
"analysis",
|
||||
{}
|
||||
),
|
||||
undefined
|
||||
);
|
||||
});
|
||||
|
||||
test("getCategoryInputOrThrow returns category for workflow with multiple jobs", (t) => {
|
||||
t.is(
|
||||
getCategoryInputOrThrow(
|
||||
yaml.load(`
|
||||
jobs:
|
||||
foo:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: github/codeql-action/init@v2
|
||||
- runs: ./build foo
|
||||
- uses: github/codeql-action/analyze@v2
|
||||
with:
|
||||
category: foo-category
|
||||
bar:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: github/codeql-action/init@v2
|
||||
- runs: ./build bar
|
||||
- uses: github/codeql-action/analyze@v2
|
||||
with:
|
||||
category: bar-category
|
||||
`) as Workflow,
|
||||
"bar",
|
||||
{}
|
||||
),
|
||||
"bar-category"
|
||||
);
|
||||
});
|
||||
|
||||
test("getCategoryInputOrThrow finds category for workflow with language matrix", (t) => {
|
||||
t.is(
|
||||
getCategoryInputOrThrow(
|
||||
|
|
@ -580,7 +613,8 @@ test("getCategoryInputOrThrow finds category for workflow with language matrix",
|
|||
- uses: github/codeql-action/analyze@v2
|
||||
with:
|
||||
category: "/language:\${{ matrix.language }}"
|
||||
`) as Workflow,
|
||||
`) as Workflow,
|
||||
"analysis",
|
||||
{ language: "javascript" }
|
||||
),
|
||||
"/language:javascript"
|
||||
|
|
@ -600,7 +634,8 @@ test("getCategoryInputOrThrow throws error for workflow with dynamic category",
|
|||
- uses: github/codeql-action/analyze@v2
|
||||
with:
|
||||
category: "\${{ github.workflow }}"
|
||||
`) as Workflow,
|
||||
`) as Workflow,
|
||||
"analysis",
|
||||
{}
|
||||
),
|
||||
{
|
||||
|
|
@ -628,7 +663,8 @@ test("getCategoryInputOrThrow throws error for workflow with multiple categories
|
|||
- uses: github/codeql-action/analyze@v2
|
||||
with:
|
||||
category: another-category
|
||||
`) as Workflow,
|
||||
`) as Workflow,
|
||||
"analysis",
|
||||
{}
|
||||
),
|
||||
{
|
||||
|
|
|
|||
|
|
@ -316,6 +316,7 @@ export function getStepsCallingAction(
|
|||
*/
|
||||
function getInputOrThrow(
|
||||
workflow: Workflow,
|
||||
jobName: string,
|
||||
actionName: string,
|
||||
inputName: string,
|
||||
matrixVars: { [key: string]: string }
|
||||
|
|
@ -325,13 +326,14 @@ function getInputOrThrow(
|
|||
`Could not get ${inputName} input to ${actionName} since the workflow has no jobs.`
|
||||
);
|
||||
}
|
||||
const inputs: string[] = Object.values(workflow.jobs)
|
||||
.map((job) =>
|
||||
getStepsCallingAction(job, actionName).map(
|
||||
(step) => step.with?.[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) => step.with?.[inputName])
|
||||
.filter((input) => input !== undefined)
|
||||
.map((input) => input!);
|
||||
|
||||
|
|
@ -369,10 +371,12 @@ function getInputOrThrow(
|
|||
*/
|
||||
export function getCategoryInputOrThrow(
|
||||
workflow: Workflow,
|
||||
jobName: string,
|
||||
matrixVars: { [key: string]: string }
|
||||
): string | undefined {
|
||||
return getInputOrThrow(
|
||||
workflow,
|
||||
jobName,
|
||||
"github/codeql-action/analyze",
|
||||
"category",
|
||||
matrixVars
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue