Skip to content

Commit 500dad9

Browse files
authored
Merge pull request #616 from github/update-v1.0.5-1c26d408
Merge main into v1
2 parents 03450ff + aa03f9b commit 500dad9

25 files changed

+394
-211
lines changed

.github/workflows/pr-checks.yml

+103-12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
push:
88
branches: [main, v1]
99
pull_request:
10+
workflow_dispatch:
1011

1112
jobs:
1213
lint-js:
@@ -119,9 +120,6 @@ jobs:
119120
with:
120121
config-file: ".github/codeql/codeql-config-packaging.yml"
121122
languages: javascript
122-
# TODO: this can be removed when cli v2.5.6 is released and available in the tool cache
123-
tools: https://github.com/dsp-testing/aeisenberg-codeql-action-packaging/releases/download/codeql-bundle-20210615/codeql-bundle-linux64.tar.gz
124-
125123
- name: Build code
126124
shell: bash
127125
run: ./build.sh
@@ -164,8 +162,6 @@ jobs:
164162
config-file: ".github/codeql/codeql-config-packaging2.yml"
165163
languages: javascript
166164
packs: dsp-testing/codeql-pack1@0.0.4, dsp-testing/codeql-pack2
167-
# TODO: this can be removed when cli v2.5.6 is released and available in the tool cache
168-
tools: https://github.com/dsp-testing/aeisenberg-codeql-action-packaging/releases/download/codeql-bundle-20210615/codeql-bundle-linux64.tar.gz
169165

170166
- name: Build code
171167
shell: bash
@@ -209,8 +205,6 @@ jobs:
209205
config-file: ".github/codeql/codeql-config-packaging3.yml"
210206
packs: +dsp-testing/codeql-pack1@0.0.4
211207
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
214208

215209
- name: Build code
216210
shell: bash
@@ -234,13 +228,67 @@ jobs:
234228
exit 1
235229
fi
236230
231+
# Tests a split workflow where database construction and query execution happen in different steps
232+
test-split-workflow:
233+
needs: [check-js, check-node-modules]
234+
runs-on: ubuntu-latest
235+
236+
steps:
237+
- uses: actions/checkout@v2
238+
- name: Move codeql-action
239+
shell: bash
240+
run: |
241+
mkdir ../action
242+
mv * .github ../action/
243+
mv ../action/tests/multi-language-repo/{*,.github} .
244+
mv ../action/.github/workflows .github
245+
- uses: ./../action/init
246+
with:
247+
config-file: ".github/codeql/codeql-config-packaging3.yml"
248+
packs: +dsp-testing/codeql-pack1@0.0.4
249+
languages: javascript
250+
tools: latest
251+
- name: Build code
252+
shell: bash
253+
run: ./build.sh
254+
- uses: ./../action/analyze
255+
with:
256+
skip-queries: true
257+
output: "${{ runner.temp }}/results"
258+
env:
259+
TEST_MODE: true
260+
- name: Assert No Results
261+
run: |
262+
if [ "$(ls -A $RUNNER_TEMP/results)" ]; then
263+
echo "Expected results directory to be empty after skipping query execution!"
264+
exit 1
265+
fi
266+
- uses: ./../action/analyze
267+
with:
268+
output: "${{ runner.temp }}/results"
269+
env:
270+
TEST_MODE: true
271+
- name: Assert Results
272+
run: |
273+
cd "$RUNNER_TEMP/results"
274+
# We should have 3 hits from these rules
275+
EXPECTED_RULES="javascript/example/empty-or-one-block javascript/example/empty-or-one-block javascript/example/two-block"
276+
277+
# use tr to replace newlines with spaces and xargs to trim leading and trailing whitespace
278+
RULES="$(cat javascript.sarif | jq -r '.runs[0].results[].ruleId' | sort | tr "\n" " " | xargs)"
279+
echo "Found matching rules '$RULES'"
280+
if [ "$RULES" != "$EXPECTED_RULES" ]; then
281+
echo "Did not match expected rules '$EXPECTED_RULES'."
282+
exit 1
283+
fi
237284
238285
# Identify the CodeQL tool versions to integration test against.
239286
check-codeql-versions:
240287
needs: [check-js, check-node-modules]
241288
runs-on: ubuntu-latest
242289
outputs:
243290
versions: ${{ steps.compare.outputs.versions }}
291+
nightly-url: ${{ steps.get-url.outputs.nightly-url }}
244292

245293
steps:
246294
- uses: actions/checkout@v2
@@ -266,22 +314,45 @@ jobs:
266314
with:
267315
tools: latest
268316
languages: javascript
269-
- name: Compare default and latest CodeQL bundle versions
317+
- name: Remove empty database
318+
# allows us to run init a third time
319+
run: |
320+
rm -rf "$RUNNER_TEMP/codeql_databases"
321+
- name: Get nightly release URL
322+
id: get-url
323+
env:
324+
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
325+
shell: bash
326+
# This workflow step gets an unstable testing version of the CodeQL CLI. It should not be used outside of these tests.
327+
run: |
328+
export LATEST=`gh release list --repo dsp-testing/codeql-cli-nightlies -L 1 | cut -f 3`
329+
echo "::set-output name=nightly-url::https://github.com/dsp-testing/codeql-cli-nightlies/releases/download/$LATEST/codeql-bundle.tar.gz"
330+
- name: Init with a CodeQL bundle from a nightly release
331+
id: init-nightly
332+
uses: ./../action/init
333+
with:
334+
tools: ${{ steps.get-url.outputs.nightly-url }}
335+
languages: javascript
336+
- name: Compare CodeQL bundle versions
270337
id: compare
271338
env:
272339
CODEQL_DEFAULT: ${{ steps.init-default.outputs.codeql-path }}
273340
CODEQL_LATEST: ${{ steps.init-latest.outputs.codeql-path }}
341+
CODEQL_NIGHTLY: ${{ steps.init-nightly.outputs.codeql-path }}
342+
NIGHTLY_URL: ${{ steps.get-url.outputs.nightly-url }}
274343
run: |
275344
CODEQL_VERSION_DEFAULT="$("$CODEQL_DEFAULT" version --format terse)"
276345
CODEQL_VERSION_LATEST="$("$CODEQL_LATEST" version --format terse)"
346+
CODEQL_VERSION_NIGHTLY="$("$CODEQL_NIGHTLY" version --format terse)"
277347
echo "Default CodeQL bundle version is $CODEQL_VERSION_DEFAULT"
278348
echo "Latest CodeQL bundle version is $CODEQL_VERSION_LATEST"
349+
echo "Nightly CodeQL bundle version is $CODEQL_VERSION_NIGHTLY"
279350
if [[ "$CODEQL_VERSION_DEFAULT" == "$CODEQL_VERSION_LATEST" ]]; then
280-
# Just use `tools: null` to avoid duplication in the integration tests.
281-
VERSIONS_JSON='[null]'
351+
# Skip `tools: latest` since it would be the same as `tools: null`
352+
VERSIONS_JSON="[null, \"$NIGHTLY_URL\"]"
282353
else
283-
# Use both `tools: null` and `tools: latest` in the integration tests.
284-
VERSIONS_JSON='[null, "latest"]'
354+
# Run integration tests with all three bundles.
355+
VERSIONS_JSON="[null, \"$NIGHTLY_URL\", \"latest\"]"
285356
fi
286357
# Output a JSON-encoded list with the distinct versions to test against.
287358
echo "Suggested matrix config for integration tests: $VERSIONS_JSON"
@@ -803,3 +874,23 @@ jobs:
803874
# Deliberately don't use TEST_MODE here. This is specifically testing
804875
# the compatibility with the API.
805876
runner/dist/codeql-runner-linux upload --sarif-file src/testdata/empty-sarif.sarif --repository $GITHUB_REPOSITORY --commit $GITHUB_SHA --ref $GITHUB_REF --github-url $GITHUB_SERVER_URL --github-auth ${{ github.token }}
877+
878+
multi-language-repo_test-local-codeql:
879+
needs: [check-js, check-node-modules, check-codeql-versions]
880+
runs-on: ubuntu-latest
881+
882+
steps:
883+
- uses: actions/checkout@v2
884+
- name: Move codeql-action
885+
run: |
886+
wget ${{ needs.check-codeql-versions.outputs.nightly-url }}
887+
mkdir ../action
888+
mv * .github ../action/
889+
mv ../action/tests/multi-language-repo/{*,.github} .
890+
mv ../action/.github/workflows .github
891+
- uses: ./../action/init
892+
with:
893+
tools: ../action/codeql-bundle.tar.gz
894+
- name: Build code
895+
run: ./build.sh
896+
- uses: ./../action/analyze

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CodeQL Action and CodeQL Runner Changelog
22

3+
## 1.0.5 - 12 Jul 2021
4+
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)
6+
- Update the warning message when the baseline lines of code count is unavailable. [#608](https://github.com/github/codeql-action/pull/608)
7+
38
## 1.0.4 - 28 Jun 2021
49

510
- Fix `RUNNER_TEMP environment variable must be set` when using runner. [#594](https://github.com/github/codeql-action/pull/594)

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,11 @@ By default, this will override any queries specified in a config file. If you wi
128128
## Troubleshooting
129129

130130
Read about [troubleshooting code scanning](https://help.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/troubleshooting-code-scanning).
131+
132+
### Note on "missing analysis" message
133+
134+
The very first time code scanning is run and if it is on a pull request, you will probably get a message mentioning a "missing analysis". This is expected.
135+
136+
After code scanning has analyzed the code in a pull request, it needs to compare the analysis of the topic branch (the merge commit of the branch you used to create the pull request) with the analysis of the base branch (the branch into which you want to merge the pull request). This allows code scanning to compute which alerts are newly introduced by the pull request, which alerts were already present in the base branch, and whether any existing alerts are fixed by the changes in the pull request. Initially, if you use a pull request to add code scanning to a repository, the base branch has not yet been analyzed, so it's not possible to compute these details. In this case, when you click through from the results check on the pull request you will see the "Missing analysis for base commit SHA-HASH" message.
137+
138+
For more information and other causes of this message, see [Reasons for the "missing analysis" message](https://docs.github.com/en/code-security/secure-coding/automatically-scanning-your-code-for-vulnerabilities-and-errors/setting-up-code-scanning-for-a-repository#reasons-for-the-missing-analysis-message)

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.

0 commit comments

Comments
 (0)