Skip to content

Commit 4087f37

Browse files
committed
Add extra integration test for packaging
Also, update the options and inputs documentation.
1 parent 6e577cf commit 4087f37

File tree

11 files changed

+83
-21
lines changed

11 files changed

+83
-21
lines changed

.github/workflows/pr-checks.yml

+49-1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ jobs:
101101
fi
102102
103103
# Packaging test that runs against a javascript database
104+
# Specifying packs in the config file.
104105
test-packaging-javascript-config:
105106
needs: [check-js, check-node-modules]
106107
runs-on: ubuntu-latest
@@ -143,7 +144,8 @@ jobs:
143144
exit 1
144145
fi
145146
146-
# tests that we can run packages through actions inputs
147+
# Packaging test that runs against a javascript database
148+
# Specifying packs as an input.
147149
test-packaging-javascript-inputs:
148150
needs: [check-js, check-node-modules]
149151
runs-on: ubuntu-latest
@@ -187,6 +189,52 @@ jobs:
187189
exit 1
188190
fi
189191
192+
# Packaging test that runs against a javascript database
193+
# Specifying packs in the config file and inputs.
194+
test-packaging-javascript-config-and-inputs:
195+
needs: [check-js, check-node-modules]
196+
runs-on: ubuntu-latest
197+
198+
steps:
199+
- uses: actions/checkout@v2
200+
- name: Move codeql-action
201+
shell: bash
202+
run: |
203+
mkdir ../action
204+
mv * .github ../action/
205+
mv ../action/tests/multi-language-repo/{*,.github} .
206+
mv ../action/.github/workflows .github
207+
- uses: ./../action/init
208+
with:
209+
config-file: ".github/codeql/codeql-config-packaging3.yml"
210+
packs: +dsp-testing/[email protected]
211+
languages: javascript
212+
# TODO: this can be removed when cli v2.5.6 is released and available in the tool cache
213+
tools: https://github.com/dsp-testing/aeisenberg-codeql-action-packaging/releases/download/codeql-bundle-20210615/codeql-bundle-linux64.tar.gz
214+
215+
- name: Build code
216+
shell: bash
217+
run: ./build.sh
218+
- uses: ./../action/analyze
219+
with:
220+
output: "${{ runner.temp }}/results"
221+
env:
222+
TEST_MODE: true
223+
- name: Assert Results
224+
run: |
225+
cd "$RUNNER_TEMP/results"
226+
# We should have 3 hits from these rules
227+
EXPECTED_RULES="javascript/example/empty-or-one-block javascript/example/empty-or-one-block javascript/example/two-block"
228+
229+
# use tr to replace newlines with spaces and xargs to trim leading and trailing whitespace
230+
RULES="$(cat javascript.sarif | jq -r '.runs[0].results[].ruleId' | sort | tr "\n" " " | xargs)"
231+
echo "Found matching rules '$RULES'"
232+
if [ "$RULES" != "$EXPECTED_RULES" ]; then
233+
echo "Did not match expected rules '$EXPECTED_RULES'."
234+
exit 1
235+
fi
236+
237+
190238
# Identify the CodeQL tool versions to integration test against.
191239
check-codeql-versions:
192240
needs: [check-js, check-node-modules]

init/action.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ inputs:
2424
required: false
2525
packs:
2626
description: >-
27-
Comma-separated list of packs to run. Reference a pack in the format `scope/name[@version]`. If `version` is not
27+
[Experimental] Comma-separated list of packs to run. Reference a pack in the format `scope/name[@version]`. If `version` is not
2828
specified, then the latest version of the pack is used. By default, this overrides the same setting in a
2929
configuration file; prefix with "+" to use both sets of packs.
3030
31-
This input is only available in single-language analyses.
31+
This input is only available in single-language analyses. To use packs in multi-language
32+
analyses, you must specify packs in the codeql-config.yml file.
3233
required: false
3334
external-repository-token:
3435
description: A token for fetching external config files and queries if they reside in a private repository.

lib/config-utils.js

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/config-utils.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/config-utils.test.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/runner.js

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/runner.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config-utils.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1596,7 +1596,7 @@ test(
15961596
{},
15971597
" + ",
15981598
[Language.cpp],
1599-
/Remove the '\+'/
1599+
/remove the '\+'/
16001600
);
16011601

16021602
test(

src/config-utils.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ export async function getDefaultConfig(
843843
);
844844
}
845845

846-
const packs = parsePacksInput(packsInput, languages) ?? {};
846+
const packs = parsePacksFromInput(packsInput, languages) ?? {};
847847

848848
return {
849849
languages,
@@ -1075,7 +1075,7 @@ export function parsePacksFromConfig(
10751075
return packs;
10761076
}
10771077

1078-
function parsePacksInput(
1078+
function parsePacksFromInput(
10791079
packsInput: string | undefined,
10801080
languages: Language[]
10811081
): Packs | undefined {
@@ -1085,7 +1085,7 @@ function parsePacksInput(
10851085

10861086
if (languages.length > 1) {
10871087
throw new Error(
1088-
"Cannot specify a 'packs' input in a multi-language analysis. Use a codeql-config.yml file instead and specify packs by library."
1088+
"Cannot specify a 'packs' input in a multi-language analysis. Use a codeql-config.yml file instead and specify packs by language."
10891089
);
10901090
} else if (languages.length === 0) {
10911091
throw new Error("No languages specified. Cannot process the packs input.");
@@ -1095,7 +1095,9 @@ function parsePacksInput(
10951095
if (packsInput.startsWith("+")) {
10961096
packsInput = packsInput.substring(1).trim();
10971097
if (!packsInput) {
1098-
throw new Error("Remove the '+' from the packs input.");
1098+
throw new Error(
1099+
"A '+' was used in the 'packs' input to specify that you wished to add some packs to your CodeQL analysis. However, no packs were specified. Please either remove the '+' or specify some packs."
1100+
);
10991101
}
11001102
}
11011103

@@ -1139,7 +1141,7 @@ export function parsePacks(
11391141
languages: Language[],
11401142
configFile: string
11411143
) {
1142-
const packsFromInput = parsePacksInput(rawPacksInput, languages);
1144+
const packsFromInput = parsePacksFromInput(rawPacksInput, languages);
11431145
const packsFomConfig = parsePacksFromConfig(
11441146
rawPacksFromConfig,
11451147
languages,

src/runner.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,12 @@ program
132132
)
133133
.option(
134134
"--packs <packs>",
135-
`Comma-separated list of packs to run. Reference a pack in the format scope/name[@version]. If version is not
135+
`[Experimental] Comma-separated list of packs to run. Reference a pack in the format scope/name[@version]. If version is not
136136
specified, then the latest version of the pack is used. By default, this overrides the same setting in a
137137
configuration file; prefix with "+" to use both sets of packs.
138138
139-
This option is only available in single-language analyses.`
139+
This option is only available in single-language analyses. To use packs in multi-language
140+
analyses, you must specify packs in the codeql-config.yml file.`
140141
)
141142
.option("--config-file <file>", "Path to config file.")
142143
.option(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: Pack testing in the CodeQL Action
2+
3+
disable-default-queries: true
4+
packs:
5+
javascript:
6+
- dsp-testing/codeql-pack2 # latest
7+
paths-ignore:
8+
- tests
9+
- lib

0 commit comments

Comments
 (0)