Skip to content

Commit 4262fd5

Browse files
committed
C#: Add stub generator integration test
1 parent 06cb277 commit 4262fd5

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

.github/workflows/csharp-qltest.yml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ jobs:
5353
slice: ["1/2", "2/2"]
5454
steps:
5555
- uses: actions/checkout@v4
56-
- uses: ./.github/actions/fetch-codeql
5756
- uses: ./csharp/actions/create-extractor-pack
5857
- name: Cache compilation cache
5958
id: query-cache
@@ -62,12 +61,7 @@ jobs:
6261
key: csharp-qltest-${{ matrix.slice }}
6362
- name: Run QL tests
6463
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 50000 --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 }}"
64+
codeql test run --threads=0 --ram 50000 --slice ${{ matrix.slice }} --search-path 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 }}"
7165
env:
7266
GITHUB_TOKEN: ${{ github.token }}
7367
unit-tests:
@@ -80,7 +74,24 @@ jobs:
8074
dotnet-version: 7.0.102
8175
- name: Extractor unit tests
8276
run: |
83-
dotnet test -p:RuntimeFrameworkVersion=7.0.2 "${{ github.workspace }}/csharp/extractor/Semmle.Util.Tests"
84-
dotnet test -p:RuntimeFrameworkVersion=7.0.2 "${{ github.workspace }}/csharp/extractor/Semmle.Extraction.Tests"
85-
dotnet test -p:RuntimeFrameworkVersion=7.0.2 "${{ github.workspace }}/csharp/autobuilder/Semmle.Autobuild.CSharp.Tests"
77+
dotnet test -p:RuntimeFrameworkVersion=7.0.2 extractor/Semmle.Util.Tests
78+
dotnet test -p:RuntimeFrameworkVersion=7.0.2 extractor/Semmle.Extraction.Tests
79+
dotnet test -p:RuntimeFrameworkVersion=7.0.2 autobuilder/Semmle.Autobuild.CSharp.Tests
8680
dotnet test -p:RuntimeFrameworkVersion=7.0.2 "${{ github.workspace }}/cpp/autobuilder/Semmle.Autobuild.Cpp.Tests"
81+
stubgentest:
82+
runs-on: ubuntu-latest
83+
steps:
84+
- uses: actions/checkout@v4
85+
- uses: ./csharp/actions/create-extractor-pack
86+
- name: Run stub generator tests
87+
run: |
88+
# Generate (Asp)NetCore stubs
89+
STUBS_PATH=stubs_output
90+
python3 ql/src/Stubs/make_stubs_nuget.py webapp Swashbuckle.AspNetCore.Swagger latest "$STUBS_PATH"
91+
rm -rf ql/test/resources/stubs/_frameworks
92+
# Update existing stubs in the repo with the freshly generated ones
93+
mv "$STUBS_PATH/output/stubs/_frameworks" ql/test/resources/stubs/
94+
git status
95+
codeql test run --threads=0 --search-path extractor-pack --check-databases --check-undefined-labels --check-repeated-labels --check-redefined-labels --consistency-queries ql/consistency-queries -- ql/test/library-tests/dataflow/flowsources/aspremote
96+
env:
97+
GITHUB_TOKEN: ${{ github.token }}

csharp/actions/create-extractor-pack/action.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ description: Builds the C# CodeQL pack
33
runs:
44
using: composite
55
steps:
6+
- uses: ./.github/actions/fetch-codeql
67
- name: Setup dotnet
78
uses: actions/setup-dotnet@v3
89
with:
@@ -11,3 +12,13 @@ runs:
1112
shell: bash
1213
run: scripts/create-extractor-pack.sh
1314
working-directory: csharp
15+
- name: Patch bundle to include ASP extractor
16+
shell: bash
17+
run: |
18+
CODEQL_PATH=$(gh codeql version --format=json | jq -r .unpackedLocation)
19+
# The legacy ASP extractor is not in this repo, so take the one from the nightly build
20+
mv "$CODEQL_PATH/csharp/tools/extractor-asp.jar" "${{ github.workspace }}/csharp/extractor-pack/tools"
21+
# Safe guard against using the bundled extractor
22+
rm -rf "$CODEQL_PATH/csharp"
23+
env:
24+
GITHUB_TOKEN: ${{ github.token }}

csharp/ql/src/Stubs/make_stubs_nuget.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,16 +211,14 @@ def run_cmd(cmd, msg="Failed to run command"):
211211
copiedFiles.add(pathInfo)
212212
shutil.copy2(pathInfos[pathInfo], frameworkDir)
213213

214-
exitCode = 0
215214
for pathInfo in pathInfos:
216215
if pathInfo not in copiedFiles:
217216
print('Not copied to nuget or framework folder: ' + pathInfo)
218217
othersDir = os.path.join(stubsDir, 'others')
219218
if not os.path.exists(othersDir):
220219
os.makedirs(othersDir)
221220
shutil.copy2(pathInfos[pathInfo], othersDir)
222-
exitCode = 1
223221

224222
print("\n --> Generated structured stub files: " + stubsDir)
225223

226-
exit(exitCode)
224+
exit(0)

0 commit comments

Comments
 (0)