|
7 | 7 | push: |
8 | 8 | branches: [main, v1] |
9 | 9 | pull_request: |
| 10 | + workflow_dispatch: |
10 | 11 |
|
11 | 12 | jobs: |
12 | 13 | lint-js: |
@@ -119,9 +120,6 @@ jobs: |
119 | 120 | with: |
120 | 121 | config-file: ".github/codeql/codeql-config-packaging.yml" |
121 | 122 | 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 | | - |
125 | 123 | - name: Build code |
126 | 124 | shell: bash |
127 | 125 | run: ./build.sh |
@@ -164,8 +162,6 @@ jobs: |
164 | 162 | config-file: ".github/codeql/codeql-config-packaging2.yml" |
165 | 163 | languages: javascript |
166 | 164 | |
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 |
169 | 165 |
|
170 | 166 | - name: Build code |
171 | 167 | shell: bash |
@@ -209,8 +205,6 @@ jobs: |
209 | 205 | config-file: ".github/codeql/codeql-config-packaging3.yml" |
210 | 206 | |
211 | 207 | 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 | 208 |
|
215 | 209 | - name: Build code |
216 | 210 | shell: bash |
@@ -234,13 +228,67 @@ jobs: |
234 | 228 | exit 1 |
235 | 229 | fi |
236 | 230 |
|
| 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 | + |
| 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 |
237 | 284 |
|
238 | 285 | # Identify the CodeQL tool versions to integration test against. |
239 | 286 | check-codeql-versions: |
240 | 287 | needs: [check-js, check-node-modules] |
241 | 288 | runs-on: ubuntu-latest |
242 | 289 | outputs: |
243 | 290 | versions: ${{ steps.compare.outputs.versions }} |
| 291 | + nightly-url: ${{ steps.get-url.outputs.nightly-url }} |
244 | 292 |
|
245 | 293 | steps: |
246 | 294 | - uses: actions/checkout@v2 |
@@ -266,22 +314,45 @@ jobs: |
266 | 314 | with: |
267 | 315 | tools: latest |
268 | 316 | 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 |
270 | 337 | id: compare |
271 | 338 | env: |
272 | 339 | CODEQL_DEFAULT: ${{ steps.init-default.outputs.codeql-path }} |
273 | 340 | 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 }} |
274 | 343 | run: | |
275 | 344 | CODEQL_VERSION_DEFAULT="$("$CODEQL_DEFAULT" version --format terse)" |
276 | 345 | CODEQL_VERSION_LATEST="$("$CODEQL_LATEST" version --format terse)" |
| 346 | + CODEQL_VERSION_NIGHTLY="$("$CODEQL_NIGHTLY" version --format terse)" |
277 | 347 | echo "Default CodeQL bundle version is $CODEQL_VERSION_DEFAULT" |
278 | 348 | echo "Latest CodeQL bundle version is $CODEQL_VERSION_LATEST" |
| 349 | + echo "Nightly CodeQL bundle version is $CODEQL_VERSION_NIGHTLY" |
279 | 350 | 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\"]" |
282 | 353 | 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\"]" |
285 | 356 | fi |
286 | 357 | # Output a JSON-encoded list with the distinct versions to test against. |
287 | 358 | echo "Suggested matrix config for integration tests: $VERSIONS_JSON" |
@@ -803,3 +874,23 @@ jobs: |
803 | 874 | # Deliberately don't use TEST_MODE here. This is specifically testing |
804 | 875 | # the compatibility with the API. |
805 | 876 | 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 |