Skip to content

Commit d42f654

Browse files
committed
Add an integration test for packaging
Uses two pre-existing packages to run some simple queries on a javascript database.
1 parent 1cc5f1d commit d42f654

File tree

8 files changed

+78
-9
lines changed

8 files changed

+78
-9
lines changed

.github/workflows/pr-checks.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,50 @@ jobs:
8282
exit 1
8383
fi
8484
85+
# Packaging test that runs against a javascript database
86+
test-packaging-javascript:
87+
needs: [check-js, check-node-modules]
88+
runs-on: ubuntu-latest
89+
90+
steps:
91+
- uses: actions/checkout@v2
92+
- name: Move codeql-action
93+
shell: bash
94+
run: |
95+
mkdir ../action
96+
mv * .github ../action/
97+
mv ../action/tests/multi-language-repo/{*,.github} .
98+
mv ../action/.github/workflows .github
99+
- uses: ./../action/init
100+
with:
101+
db-location: "${{ runner.temp }}/customDbLocation"
102+
config-file: ".github/codeql/codeql-config-packaging.yml"
103+
languages: javascript
104+
# TODO: this is temporary until we have a release that includes the latest packaging work.
105+
tools: https://github.com/dsp-testing/aeisenberg-codeql-action-packaging/releases/download/codeql-bundle-20210606/codeql-bundle-linux64.tar.gz
106+
107+
- name: Build code
108+
shell: bash
109+
run: ./build.sh
110+
- uses: ./../action/analyze
111+
with:
112+
output: "${{ runner.temp }}/results"
113+
env:
114+
TEST_MODE: true
115+
- name: Assert Results
116+
run: |
117+
cd "$RUNNER_TEMP/results"
118+
# We should have 3 hits from these rules
119+
EXPECTED_RULES="javascript/example/empty-or-one-block javascript/example/empty-or-one-block javascript/example/two-block"
120+
121+
# use tr to replace newlines with spaces and xargs to trim leading and trailing whitespace
122+
RULES="$(cat javascript-custom.sarif | jq -r '.runs[0].results[].ruleId' | sort | tr "\n" " " | xargs)"
123+
echo "Found matching rules '$RULES'"
124+
if [ "$RULES" != "$EXPECTED_RULES" ]; then
125+
echo "Did not match expected rules '$EXPECTED_RULES'."
126+
exit 1
127+
fi
128+
85129
# Identify the CodeQL tool versions to integration test against.
86130
check-codeql-versions:
87131
needs: [check-js, check-node-modules]

lib/codeql.js

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/codeql.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/count-loc.test.js

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

src/codeql.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,10 @@ function getCodeQLForCmd(cmd: string): CodeQL {
799799
const parsedOutput: PackDownloadOutput = JSON.parse(output);
800800
if (
801801
Array.isArray(parsedOutput.packs) &&
802-
parsedOutput.packs.every((p) => p.name && p.version)
802+
// TODO PackDownloadOutput will not include the version if it is not specified
803+
// in the input. The version is always the latest version available.
804+
// It should be added to the output, but this requires a CLI change
805+
parsedOutput.packs.every((p) => p.name /* && p.version */)
803806
) {
804807
return parsedOutput;
805808
} else {

src/count-loc.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test("ensure lines of code works for cpp and js", async (t) => {
2020

2121
t.deepEqual(results, {
2222
cpp: 6,
23-
javascript: 3,
23+
javascript: 9,
2424
});
2525
});
2626

@@ -34,7 +34,7 @@ test("ensure lines of code can handle undefined language", async (t) => {
3434
);
3535

3636
t.deepEqual(results, {
37-
javascript: 3,
37+
javascript: 9,
3838
python: 5,
3939
});
4040
});
@@ -93,6 +93,6 @@ test("ensure lines of code can handle exclude", async (t) => {
9393
);
9494

9595
t.deepEqual(results, {
96-
javascript: 3,
96+
javascript: 9,
9797
});
9898
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: Pack testing in the CodeQL Action
2+
3+
disable-default-queries: true
4+
packs:
5+
javascript:
6+
- dsp-testing/[email protected]
7+
- dsp-testing/codeql-pack2 # latest
8+
paths-ignore:
9+
- tests
10+
- lib

tests/multi-language-repo/main.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
if (true) {
22
console.log("Hello, World!");
3+
console.log("Good-bye, World!");
4+
}
5+
6+
if (true) {
7+
console.log("Hello, World!");
8+
}
9+
10+
if (true) {
11+
// empty
312
}

0 commit comments

Comments
 (0)