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

View file

@ -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",
{}
),
{