Skip to content

Commit fe71459

Browse files
committed
[WIP] Add packs and queries from input
This commit adds the packs and queries from the actions input to the config file used by the CodeQL CLI. When the `+` is used, the input is combined with the config and when it is not used, the input overrides the config. Fixes Fix
1 parent e44d818 commit fe71459

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1789
-201
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Check Code-Scanning Config
2+
description: |
3+
Checks the code scanning configuration file generated by the
4+
action to ensure it contains the expected contents
5+
inputs:
6+
languages:
7+
required: false
8+
description: The languages field passed to the init action.
9+
10+
packs:
11+
required: false
12+
description: The packs field passed to the init action.
13+
14+
queries:
15+
required: false
16+
description: The queries field passed to the init action.
17+
18+
config-file:
19+
required: false
20+
description: |
21+
The location of the config file to use. If empty,
22+
then no config file is used.
23+
24+
expected-config-file-contents:
25+
required: true
26+
description: |
27+
A JSON string containing the exact contents of the config file.
28+
29+
tools:
30+
required: true
31+
description: |
32+
The url of codeql to use.
33+
34+
runs:
35+
using: composite
36+
steps:
37+
- uses: ./../action/init
38+
with:
39+
languages: ${{ inputs.languages }}
40+
config-file: ${{ inputs.config-file }}
41+
queries: ${{ inputs.queries }}
42+
packs: ${{ inputs.packs }}
43+
tools: ${{ inputs.tools }}
44+
db-location: ${{ runner.temp }}/codescanning-config-cli-test
45+
46+
- name: Install dependencies
47+
shell: bash
48+
run: npm i -g ts-node js-yaml
49+
50+
- name: Check config
51+
working-directory: ${{ github.action_path }}
52+
shell: bash
53+
run: ts-node ./index.ts "${{ runner.temp }}/user-config.yaml" "${{ inputs.expected-config-file-contents }}"
54+
55+
- name: Clean up
56+
shell: bash
57+
run: |
58+
rm -rf ${{ runner.temp }}/codescanning-config-cli-test
59+
rm -rf ${{ runner.temp }}/user-config.yaml
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
import * as core from '@actions/core'
3+
import * as yaml from 'js-yaml'
4+
import * as fs from 'fs'
5+
import * as assert from 'assert'
6+
7+
const rawActualConfig = fs.readFileSync(process.argv[2], 'utf8')
8+
core.startGroup('Actual generated user config')
9+
core.info(rawActualConfig)
10+
core.endGroup()
11+
12+
const actualConfig = yaml.load(rawActualConfig)
13+
14+
const rawExpectedConfig = process.argv[3]
15+
core.startGroup('Expected generated user config')
16+
core.info(rawExpectedConfig)
17+
core.endGroup()
18+
19+
const expectedConfig = rawExpectedConfig ? JSON.parse(rawExpectedConfig) : undefined;
20+
21+
assert.deepStrictEqual(
22+
actualConfig,
23+
expectedConfig,
24+
'Expected configuration does not match actual configuration'
25+
);

.github/query-filter-test/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ runs:
4949
queries-not-run: ${{ inputs.queries-not-run}}
5050
- name: Cleanup after test
5151
shell: bash
52-
run: rm -rf "$RUNNER_TEMP/results" "$RUNNER_TEMP//query-filter-test"
52+
run: rm -rf "$RUNNER_TEMP/results" "$RUNNER_TEMP/query-filter-test"

.github/workflows/__ml-powered-queries.yml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/__packaging-config-inputs-js.yml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/__packaging-config-js.yml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/__packaging-inputs-js.yml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/__split-workflow.yml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# Tests that the generated code scanning config file contains the expected contents
2+
3+
name: Code-Scanning config CLI tests
4+
env:
5+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6+
CODEQL_PASS_CONFIG_TO_CLI: true
7+
8+
on:
9+
push:
10+
branches:
11+
- main
12+
- releases/v1
13+
- releases/v2
14+
pull_request:
15+
types:
16+
- opened
17+
- synchronize
18+
- reopened
19+
- ready_for_review
20+
workflow_dispatch: {}
21+
22+
jobs:
23+
code-scanning-config-tests:
24+
# Code-Scanning config not created because environment variable is not set
25+
name: Code Scanning Configuration tests
26+
timeout-minutes: 45
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Check out repository
30+
uses: actions/checkout@v3
31+
- name: Prepare test
32+
id: prepare-test
33+
uses: ./.github/prepare-test
34+
with:
35+
version: latest
36+
37+
- name: Empty file
38+
uses: ./../action/.github/check-codescanning-config
39+
with:
40+
expected-config-file-contents: "{}"
41+
languages: javascript
42+
tools: ${{ steps.prepare-test.outputs.tools-url }}
43+
44+
- name: Packs from input
45+
uses: ./../action/.github/check-codescanning-config
46+
with:
47+
expected-config-file-contents: |
48+
{
49+
"packs": [" dsp-testing/[email protected]", "dsp-testing/codeql-pack2" ]
50+
}
51+
languages: javascript
52+
packs: dsp-testing/[email protected], dsp-testing/codeql-pack2
53+
tools: ${{ steps.prepare-test.outputs.tools-url }}
54+
55+
- name: Packs from input with +
56+
uses: ./../action/.github/check-codescanning-config
57+
with:
58+
expected-config-file-contents: |
59+
{
60+
"packs": ["dsp-testing/[email protected]", "dsp-testing/codeql-pack2" ]
61+
}
62+
languages: javascript
63+
packs: + dsp-testing/[email protected], dsp-testing/codeql-pack2
64+
tools: ${{ steps.prepare-test.outputs.tools-url }}
65+
66+
- name: Queries from input
67+
uses: ./../action/.github/check-codescanning-config
68+
with:
69+
expected-config-file-contents: |
70+
{
71+
"queries": [{ "uses": "./codeql-qlpacks/complex-javascript-qlpack/show_ifs.ql" }]
72+
}
73+
languages: javascript
74+
queries: ./codeql-qlpacks/complex-javascript-qlpack/show_ifs.ql
75+
tools: ${{ steps.prepare-test.outputs.tools-url }}
76+
77+
- name: Queries from input with +
78+
uses: ./../action/.github/check-codescanning-config
79+
with:
80+
expected-config-file-contents: |
81+
{
82+
"queries": [{ "uses": "./codeql-qlpacks/complex-javascript-qlpack/show_ifs.ql" }]
83+
}
84+
languages: javascript
85+
queries: + ./codeql-qlpacks/complex-javascript-qlpack/show_ifs.ql
86+
tools: ${{ steps.prepare-test.outputs.tools-url }}
87+
88+
- name: Queries and packs from input with +
89+
uses: ./../action/.github/check-codescanning-config
90+
with:
91+
expected-config-file-contents: |
92+
{
93+
"queries": [{ "uses": "./codeql-qlpacks/complex-javascript-qlpack/show_ifs.ql" }],
94+
"packs": ["dsp-testing/[email protected]", "dsp-testing/codeql-pack2" ]
95+
}
96+
languages: javascript
97+
queries: + ./codeql-qlpacks/complex-javascript-qlpack/show_ifs.ql
98+
packs: + dsp-testing/[email protected], dsp-testing/codeql-pack2
99+
tools: ${{ steps.prepare-test.outputs.tools-url }}
100+
101+
- name: Queries and packs from config
102+
uses: ./../action/.github/check-codescanning-config
103+
with:
104+
expected-config-file-contents: |
105+
{
106+
"queries": [{ "uses": "./codeql-qlpacks/complex-javascript-qlpack/show_ifs.ql" }],
107+
"packs": {
108+
"javascript": ["dsp-testing/[email protected]", "dsp-testing/codeql-pack2" ]
109+
}
110+
}
111+
languages: javascript
112+
queries: + ./codeql-qlpacks/complex-javascript-qlpack/show_ifs.ql
113+
packs: + dsp-testing/[email protected], dsp-testing/codeql-pack2
114+
tools: ${{ steps.prepare-test.outputs.tools-url }}
115+
116+
- name: Queries and packs from config overriden by input
117+
uses: ./../action/.github/check-codescanning-config
118+
with:
119+
expected-config-file-contents: |
120+
{
121+
"queries": [{ "uses": "./codeql-qlpacks/complex-javascript-qlpack/show_ifs.ql" }],
122+
"packs": ["codeql/javascript-queries"]
123+
}
124+
languages: javascript
125+
queries: ./codeql-qlpacks/complex-javascript-qlpack/show_ifs.ql
126+
packs: codeql/javascript-queries
127+
tools: ${{ steps.prepare-test.outputs.tools-url }}
128+
129+
- name: Queries and packs from config merging with input
130+
uses: ./../action/.github/check-codescanning-config
131+
with:
132+
expected-config-file-contents: |
133+
{
134+
"queries": [
135+
{ "uses": "./codeql-qlpacks/complex-javascript-qlpack/show_ifs.ql" },
136+
{ "uses": "./codeql-qlpacks/complex-javascript-qlpack/foo2/show_ifs.ql" }
137+
],
138+
"packs": {
139+
"javascript": ["dsp-testing/[email protected]", "dsp-testing/codeql-pack2", "codeql/javascript-queries" ]
140+
}
141+
}
142+
languages: javascript
143+
queries: + ./codeql-qlpacks/complex-javascript-qlpack/show_ifs.ql
144+
packs: + codeql/javascript-queries
145+
config-file: tests/multi-language-repo/.github/codeql/queries-and-packs-config.yml
146+
tools: ${{ steps.prepare-test.outputs.tools-url }}
147+
148+
- name: Multi-language packs from config
149+
uses: ./../action/.github/check-codescanning-config
150+
with:
151+
expected-config-file-contents: |
152+
{
153+
"packs": {
154+
"javascript": ["dsp-testing/[email protected]", "dsp-testing/codeql-pack2", "codeql/javascript-queries" ],
155+
"ruby": ["codeql/i-dont-exist", "codeql/hucairz"]
156+
}
157+
}
158+
languages: javascript
159+
config-file: tests/multi-language-repo/.github/codeql/multi-language-packs-config copy.yml
160+
tools: ${{ steps.prepare-test.outputs.tools-url }}
161+
162+
- name: Other config properties
163+
uses: ./../action/.github/check-codescanning-config
164+
with:
165+
expected-config-file-contents: |
166+
{
167+
"name": "Config using all properties",
168+
"packs": ["codeql/javascript-queries" ],
169+
"disable-default-queries": true,
170+
"paths-ignore": ["xxx"],
171+
"paths": ["yyy"]
172+
}
173+
languages: javascript
174+
packs: + codeql/javascript-queries
175+
config-file: tests/multi-language-repo/.github/codeql/other-config-properties.yml
176+
tools: ${{ steps.prepare-test.outputs.tools-url }}

lib/analysis-paths.test.js

Lines changed: 15 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)