Add function to read the analysis category from a workflow

This commit is contained in:
Henry Mercer 2022-11-22 18:15:28 +00:00
parent 996d04b1e5
commit e2d523ca5e
6 changed files with 227 additions and 3 deletions

62
lib/workflow.test.js generated
View file

@ -355,4 +355,66 @@ function errorCodes(actual, expected) {
on: ["push"]
`)), []));
});
(0, ava_1.default)("getCategoryInput returns category for simple workflow with category", (t) => {
t.is((0, workflow_1.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
`)), "some-category");
});
(0, ava_1.default)("getCategoryInput returns undefined for simple workflow without category", (t) => {
t.is((0, workflow_1.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
`)), undefined);
});
(0, ava_1.default)("getCategoryInput throws error for workflow with dynamic category", (t) => {
t.throws(() => (0, workflow_1.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 }}"
`)), {
message: "Could not get category input since it contained a dynamic value.",
});
});
(0, ava_1.default)("getCategoryInput throws error for workflow with multiple categories", (t) => {
t.throws(() => (0, workflow_1.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
`)), {
message: "Could not get category input since multiple categories were specified by the analysis step.",
});
});
//# sourceMappingURL=workflow.test.js.map