Skip to content

Commit 53cf5d9

Browse files
Merge pull request #602 from edoardopirovano/split-create-analysis
Support splitting of DB creation and query execution
2 parents 24ef87c + 93214ec commit 53cf5d9

12 files changed

+186
-66
lines changed

.github/workflows/pr-checks.yml

+53-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ jobs:
122122
languages: javascript
123123
# TODO: this can be removed when cli v2.5.6 is released and available in the tool cache
124124
tools: https://github.com/dsp-testing/aeisenberg-codeql-action-packaging/releases/download/codeql-bundle-20210615/codeql-bundle-linux64.tar.gz
125-
126125
- name: Build code
127126
shell: bash
128127
run: ./build.sh
@@ -235,6 +234,59 @@ jobs:
235234
exit 1
236235
fi
237236
237+
# Tests a split workflow where database construction and query execution happen in different steps
238+
test-split-workflow:
239+
needs: [check-js, check-node-modules]
240+
runs-on: ubuntu-latest
241+
242+
steps:
243+
- uses: actions/checkout@v2
244+
- name: Move codeql-action
245+
shell: bash
246+
run: |
247+
mkdir ../action
248+
mv * .github ../action/
249+
mv ../action/tests/multi-language-repo/{*,.github} .
250+
mv ../action/.github/workflows .github
251+
- uses: ./../action/init
252+
with:
253+
config-file: ".github/codeql/codeql-config-packaging3.yml"
254+
packs: +dsp-testing/[email protected]
255+
languages: javascript
256+
tools: latest
257+
- name: Build code
258+
shell: bash
259+
run: ./build.sh
260+
- uses: ./../action/analyze
261+
with:
262+
skip-queries: true
263+
output: "${{ runner.temp }}/results"
264+
env:
265+
TEST_MODE: true
266+
- name: Assert No Results
267+
run: |
268+
if [ "$(ls -A $RUNNER_TEMP/results)" ]; then
269+
echo "Expected results directory to be empty after skipping query execution!"
270+
exit 1
271+
fi
272+
- uses: ./../action/analyze
273+
with:
274+
output: "${{ runner.temp }}/results"
275+
env:
276+
TEST_MODE: true
277+
- name: Assert Results
278+
run: |
279+
cd "$RUNNER_TEMP/results"
280+
# We should have 3 hits from these rules
281+
EXPECTED_RULES="javascript/example/empty-or-one-block javascript/example/empty-or-one-block javascript/example/two-block"
282+
283+
# use tr to replace newlines with spaces and xargs to trim leading and trailing whitespace
284+
RULES="$(cat javascript.sarif | jq -r '.runs[0].results[].ruleId' | sort | tr "\n" " " | xargs)"
285+
echo "Found matching rules '$RULES'"
286+
if [ "$RULES" != "$EXPECTED_RULES" ]; then
287+
echo "Did not match expected rules '$EXPECTED_RULES'."
288+
exit 1
289+
fi
238290
239291
# Identify the CodeQL tool versions to integration test against.
240292
check-codeql-versions:

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## [UNRELEASED]
44

5-
No user facing changes.
5+
- The `analyze` step of the Action now supports a `skip-queries` option to merely build the CodeQL database without analyzing. This functionality is not present in the runner. Additionally, the step will no longer fail if it encounters a finalized database, and will instead continue with query execution. [#602](https://github.com/github/codeql-action/pull/602)
66

77
## 1.0.4 - 28 Jun 2021
88

analyze/action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ inputs:
2424
description: Specify whether or not to add code snippets to the output sarif file.
2525
required: false
2626
default: "false"
27+
skip-queries:
28+
description: If this option is set, the CodeQL database will be built but no queries will be run on it. Thus, no results will be produced.
29+
required: false
30+
default: "false"
2731
threads:
2832
description: The number of threads to be used by CodeQL.
2933
required: false

lib/analyze-action.js

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

lib/analyze-action.js.map

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

lib/analyze.js

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

0 commit comments

Comments
 (0)