Skip to content

Commit 64b50fa

Browse files
committed
Code scanning: Compare the default and latest CodeQL tools bundles
Create a prerequisite job that runs the init step twice, with `tools: null` and `tools: latest`. Use the outputs of these steps to compare the two CodeQL versions. Pass the list of distinct tool versions for the analysis job to matrix over. This lets us test the analysis against both versions, while avoiding duplication when they are actually the same version.
1 parent 51b1d7d commit 64b50fa

1 file changed

Lines changed: 46 additions & 1 deletion

File tree

.github/workflows/codeql.yml

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,56 @@ on:
77
branches: [main, v1]
88

99
jobs:
10+
# Identify the CodeQL tool versions to use in the analysis job.
11+
check-codeql-versions:
12+
runs-on: ubuntu-latest
13+
outputs:
14+
versions: ${{ steps.compare.outputs.versions }}
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Init with default CodeQL bundle from the VM image
19+
id: init-default
20+
uses: ./init
21+
with:
22+
languages: javascript
23+
- name: Remove empty database
24+
# allows us to run init a second time
25+
run: |
26+
rm -rf "$RUNNER_TEMP/codeql_databases"
27+
- name: Init with latest CodeQL bundle
28+
id: init-latest
29+
uses: ./init
30+
with:
31+
tools: latest
32+
languages: javascript
33+
- name: Compare default and latest CodeQL bundle versions
34+
id: compare
35+
env:
36+
CODEQL_DEFAULT: ${{ steps.init-default.outputs.codeql-path }}
37+
CODEQL_LATEST: ${{ steps.init-latest.outputs.codeql-path }}
38+
run: |
39+
CODEQL_VERSION_DEFAULT="$("$CODEQL_DEFAULT" version --format terse)"
40+
CODEQL_VERSION_LATEST="$("$CODEQL_LATEST" version --format terse)"
41+
echo "Default CodeQL bundle version is $CODEQL_VERSION_DEFAULT"
42+
echo "Latest CodeQL bundle version is $CODEQL_VERSION_LATEST"
43+
if [[ "$CODEQL_VERSION_DEFAULT" == "$CODEQL_VERSION_LATEST" ]]; then
44+
# Just use `tools: null` to avoid duplication in the analysis job.
45+
VERSIONS_JSON='[null]'
46+
else
47+
# Use both `tools: null` and `tools: latest` in the analysis job.
48+
VERSIONS_JSON='[null, "latest"]'
49+
fi
50+
# Output a JSON-encoded list with the distinct versions to test against.
51+
echo "Suggested matrix config for analysis job: $VERSIONS_JSON"
52+
echo "::set-output name=versions::${VERSIONS_JSON}"
53+
1054
build:
55+
needs: [check-codeql-versions]
1156
strategy:
1257
matrix:
1358
os: [ubuntu-latest,windows-latest,macos-latest]
14-
tools: [~, latest]
59+
tools: ${{ fromJson(needs.check-codeql-versions.outputs.versions) }}
1560
runs-on: ${{ matrix.os }}
1661

1762
steps:

0 commit comments

Comments
 (0)