mirror of
https://github.com/github/codeql-action.git
synced 2026-04-27 01:08:46 +00:00
Add function to read the analysis category from a workflow
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
CodedError,
|
||||
formatWorkflowCause,
|
||||
formatWorkflowErrors,
|
||||
getCategoryInput,
|
||||
getWorkflowErrors,
|
||||
patternIsSuperset,
|
||||
Workflow,
|
||||
@@ -522,3 +523,93 @@ test("getWorkflowErrors() should not report an error if PRs are totally unconfig
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
test("getCategoryInput returns category for simple workflow with category", (t) => {
|
||||
t.is(
|
||||
getCategoryInput(
|
||||
yaml.load(`
|
||||
jobs:
|
||||
analysis:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: github/codeql-action/init@v2
|
||||
- uses: github/codeql-action/analyze@v2
|
||||
with:
|
||||
category: some-category
|
||||
`) as Workflow
|
||||
),
|
||||
"some-category"
|
||||
);
|
||||
});
|
||||
|
||||
test("getCategoryInput returns undefined for simple workflow without category", (t) => {
|
||||
t.is(
|
||||
getCategoryInput(
|
||||
yaml.load(`
|
||||
jobs:
|
||||
analysis:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: github/codeql-action/init@v2
|
||||
- uses: github/codeql-action/analyze@v2
|
||||
`) as Workflow
|
||||
),
|
||||
undefined
|
||||
);
|
||||
});
|
||||
|
||||
test("getCategoryInput throws error for workflow with dynamic category", (t) => {
|
||||
t.throws(
|
||||
() =>
|
||||
getCategoryInput(
|
||||
yaml.load(`
|
||||
jobs:
|
||||
analysis:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
language: [javascript, python]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: github/codeql-action/init@v2
|
||||
with:
|
||||
language: \${{ matrix.language }}
|
||||
- uses: github/codeql-action/analyze@v2
|
||||
with:
|
||||
category: "/language:\${{ matrix.language }}"
|
||||
`) as Workflow
|
||||
),
|
||||
{
|
||||
message:
|
||||
"Could not get category input since it contained a dynamic value.",
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test("getCategoryInput throws error for workflow with multiple categories", (t) => {
|
||||
t.throws(
|
||||
() =>
|
||||
getCategoryInput(
|
||||
yaml.load(`
|
||||
jobs:
|
||||
analysis:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: github/codeql-action/init@v2
|
||||
- uses: github/codeql-action/analyze@v2
|
||||
with:
|
||||
category: some-category
|
||||
- uses: github/codeql-action/analyze@v2
|
||||
with:
|
||||
category: another-category
|
||||
`) as Workflow
|
||||
),
|
||||
{
|
||||
message:
|
||||
"Could not get category input since multiple categories were specified by the analysis step.",
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user