Skip to content

Commit 3137675

Browse files
committed
C#: Add workflow for running QL tests
1 parent 8a73675 commit 3137675

File tree

6 files changed

+116
-4
lines changed

6 files changed

+116
-4
lines changed

.github/workflows/csharp-qltest.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: "C#: Run QL Tests"
2+
3+
on:
4+
push:
5+
paths:
6+
- "csharp/**"
7+
- "shared/**"
8+
- .github/actions/fetch-codeql/action.yml
9+
- codeql-workspace.yml
10+
branches:
11+
- main
12+
- "rc/*"
13+
pull_request:
14+
paths:
15+
- "csharp/**"
16+
- "shared/**"
17+
- .github/workflows/csharp-qltest.yml
18+
- .github/actions/fetch-codeql/action.yml
19+
- codeql-workspace.yml
20+
branches:
21+
- main
22+
- "rc/*"
23+
24+
defaults:
25+
run:
26+
working-directory: csharp
27+
28+
jobs:
29+
qlupgrade:
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v3
33+
- uses: ./.github/actions/fetch-codeql
34+
- name: Check DB upgrade scripts
35+
run: |
36+
echo >empty.trap
37+
codeql dataset import -S ql/lib/upgrades/initial/semmlecode.csharp.dbscheme testdb empty.trap
38+
codeql dataset upgrade testdb --additional-packs ql/lib
39+
diff -q testdb/semmlecode.csharp.dbscheme ql/lib/semmlecode.csharp.dbscheme
40+
- name: Check DB downgrade scripts
41+
run: |
42+
echo >empty.trap
43+
rm -rf testdb; codeql dataset import -S ql/lib/semmlecode.csharp.dbscheme testdb empty.trap
44+
codeql resolve upgrades --format=lines --allow-downgrades --additional-packs downgrades \
45+
--dbscheme=ql/lib/semmlecode.csharp.dbscheme --target-dbscheme=downgrades/initial/semmlecode.csharp.dbscheme |
46+
xargs codeql execute upgrades testdb
47+
diff -q testdb/semmlecode.csharp.dbscheme downgrades/initial/semmlecode.csharp.dbscheme
48+
qltest:
49+
runs-on: ubuntu-latest-xl
50+
strategy:
51+
fail-fast: false
52+
matrix:
53+
slice: ["1/2", "2/2"]
54+
steps:
55+
- uses: actions/checkout@v3
56+
- uses: ./.github/actions/fetch-codeql
57+
- uses: ./csharp/actions/create-extractor-pack
58+
- name: Cache compilation cache
59+
id: query-cache
60+
uses: ./.github/actions/cache-query-compilation
61+
with:
62+
key: csharp-qltest-${{ matrix.slice }}
63+
- name: Run QL tests
64+
run: |
65+
CODEQL_PATH=$(gh codeql version --format=json | jq -r .unpackedLocation)
66+
# The legacy ASP extractor is not in this repo, so take the one from the nightly build
67+
mv "$CODEQL_PATH/csharp/tools/extractor-asp.jar" "${{ github.workspace }}/csharp/extractor-pack/tools"
68+
# Safe guard against using the bundled extractor
69+
rm -rf "$CODEQL_PATH/csharp"
70+
codeql test run --threads=0 --ram 52000 --slice ${{ matrix.slice }} --search-path "${{ github.workspace }}/csharp/extractor-pack" --check-databases --check-undefined-labels --check-repeated-labels --check-redefined-labels --consistency-queries ql/consistency-queries ql/test --compilation-cache "${{ steps.query-cache.outputs.cache-dir }}"
71+
env:
72+
GITHUB_TOKEN: ${{ github.token }}

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
# It's useful (though not required) to be able to unpack codeql in the ql checkout itself
2828
/codeql/
2929

30-
csharp/extractor/Semmle.Extraction.CSharp.Driver/Properties/launchSettings.json
31-
3230
# Avoid committing cached package components
3331
.codeql
3432

csharp/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ csharp.log
1111
*.tlog
1212
.vs
1313
*.user
14-
.vscode/launch.json
14+
.vscode/launch.json
15+
16+
extractor/Semmle.Extraction.CSharp.Driver/Properties/launchSettings.json
17+
extractor-pack
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Build C# CodeQL pack
2+
description: Builds the C# CodeQL pack
3+
runs:
4+
using: composite
5+
steps:
6+
- name: Setup dotnet
7+
uses: actions/setup-dotnet@v3
8+
with:
9+
dotnet-version: 6.0.202
10+
- name: Build Extractor
11+
shell: bash
12+
run: scripts/create-extractor-pack.sh
13+
working-directory: csharp

csharp/ql/lib/semmle/code/csharp/controlflow/internal/Completion.qll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ abstract class Completion extends TCompletion {
103103
* otherwise it is a normal non-Boolean completion.
104104
*/
105105
predicate isValidFor(ControlFlowElement cfe) {
106-
cfe instanceof NonReturningCall and
107106
this = cfe.(NonReturningCall).getACompletion()
108107
or
109108
this = TThrowCompletion(cfe.(TriedControlFlowElement).getAThrownException())
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
set -eux
3+
4+
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
5+
platform="linux64"
6+
dotnet_platform="linux-x64"
7+
elif [[ "$OSTYPE" == "darwin"* ]]; then
8+
platform="osx64"
9+
dotnet_platform="osx-x64"
10+
else
11+
echo "Unknown OS"
12+
exit 1
13+
fi
14+
15+
rm -rf extractor-pack
16+
mkdir -p extractor-pack
17+
mkdir -p extractor-pack/tools/${platform}
18+
19+
function dotnet_publish {
20+
dotnet publish --self-contained --configuration Release --runtime ${dotnet_platform} -p:RuntimeFrameworkVersion=6.0.4 $1 --output extractor-pack/tools/${platform}
21+
}
22+
23+
dotnet_publish extractor/Semmle.Extraction.CSharp.Standalone
24+
dotnet_publish extractor/Semmle.Extraction.CSharp.Driver
25+
dotnet_publish autobuilder/Semmle.Autobuild.CSharp
26+
27+
cp -r codeql-extractor.yml tools/* downgrades tools ql/lib/semmlecode.csharp.dbscheme ql/lib/semmlecode.csharp.dbscheme.stats extractor-pack/

0 commit comments

Comments
 (0)