Skip to content

Commit 7167f07

Browse files
committed
Merge branch 'main' into henrymercer/mergeback-3.8
2 parents 2b10e4b + a85de2b commit 7167f07

File tree

2,013 files changed

+98837
-101285
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,013 files changed

+98837
-101285
lines changed

.github/ISSUE_TEMPLATE/ql--false-positive.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
name: CodeQL False positive
2+
name: CodeQL false positive
33
about: Report CodeQL alerts that you think should not have been detected (not applicable, not exploitable, etc.)
44
title: False positive
55
labels: false-positive
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Cache query compilation
2+
description: Caches CodeQL compilation caches - should be run both on PRs and pushes to main.
3+
4+
inputs:
5+
key:
6+
description: 'The cache key to use - should be unique to the workflow'
7+
required: true
8+
9+
outputs:
10+
cache-dir:
11+
description: "The directory where the cache was stored"
12+
value: ${{ steps.fill-compilation-dir.outputs.compdir }}
13+
14+
runs:
15+
using: composite
16+
steps:
17+
# calculate the merge-base with main, in a way that works both on PRs and pushes to main.
18+
- name: Calculate merge-base
19+
shell: bash
20+
if: ${{ github.event_name == 'pull_request' }}
21+
env:
22+
BASE_BRANCH: ${{ github.base_ref }}
23+
run: |
24+
MERGE_BASE=$(git cat-file commit $GITHUB_SHA | grep '^parent ' | head -1 | cut -f 2 -d " ")
25+
echo "merge_base=$MERGE_BASE" >> $GITHUB_ENV
26+
- name: Restore read-only cache (PR)
27+
if: ${{ github.event_name == 'pull_request' }}
28+
uses: erik-krogh/actions-cache@a88d0603fe5fb5606db9f002dfcadeb32b5f84c6
29+
with:
30+
path: '**/.cache'
31+
read-only: true
32+
key: codeql-compile-${{ inputs.key }}-pr-${{ github.sha }}
33+
restore-keys: |
34+
codeql-compile-${{ inputs.key }}-${{ github.base_ref }}-${{ env.merge_base }}
35+
codeql-compile-${{ inputs.key }}-${{ github.base_ref }}-
36+
codeql-compile-${{ inputs.key }}-main-
37+
- name: Fill cache (push)
38+
if: ${{ github.event_name != 'pull_request' }}
39+
uses: erik-krogh/actions-cache@a88d0603fe5fb5606db9f002dfcadeb32b5f84c6
40+
with:
41+
path: '**/.cache'
42+
key: codeql-compile-${{ inputs.key }}-${{ github.ref_name }}-${{ github.sha }} # just fill on main
43+
restore-keys: | # restore the latest cache if the exact cache is unavailable, to speed up compilation.
44+
codeql-compile-${{ inputs.key }}-${{ github.ref_name }}-
45+
codeql-compile-${{ inputs.key }}-main-
46+
- name: Fill compilation cache directory
47+
id: fill-compilation-dir
48+
shell: bash
49+
run: |
50+
# Move all the existing cache into another folder, so we only preserve the cache for the current queries.
51+
node $GITHUB_WORKSPACE/.github/actions/cache-query-compilation/move-caches.js ${COMBINED_CACHE_DIR}
52+
53+
echo "compdir=${COMBINED_CACHE_DIR}" >> $GITHUB_OUTPUT
54+
env:
55+
COMBINED_CACHE_DIR: ${{ runner.temp }}/compilation-dir
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// # Move all the existing cache into another folder, so we only preserve the cache for the current queries.
2+
// mkdir -p ${COMBINED_CACHE_DIR}
3+
// rm -f **/.cache/{lock,size} # -f to avoid errors if the cache is empty.
4+
// # copy the contents of the .cache folders into the combined cache folder.
5+
// cp -r **/.cache/* ${COMBINED_CACHE_DIR}/ || : # ignore missing files
6+
// # clean up the .cache folders
7+
// rm -rf **/.cache/*
8+
9+
const fs = require("fs");
10+
const path = require("path");
11+
12+
// the first argv is the cache folder to create.
13+
const COMBINED_CACHE_DIR = process.argv[2];
14+
15+
function* walkCaches(dir) {
16+
const files = fs.readdirSync(dir, { withFileTypes: true });
17+
for (const file of files) {
18+
if (file.isDirectory()) {
19+
const filePath = path.join(dir, file.name);
20+
yield* walkCaches(filePath);
21+
if (file.name === ".cache") {
22+
yield filePath;
23+
}
24+
}
25+
}
26+
}
27+
28+
async function copyDir(src, dest) {
29+
for await (const file of await fs.promises.readdir(src, { withFileTypes: true })) {
30+
const srcPath = path.join(src, file.name);
31+
const destPath = path.join(dest, file.name);
32+
if (file.isDirectory()) {
33+
if (!fs.existsSync(destPath)) {
34+
fs.mkdirSync(destPath);
35+
}
36+
await copyDir(srcPath, destPath);
37+
} else {
38+
await fs.promises.copyFile(srcPath, destPath);
39+
}
40+
}
41+
}
42+
43+
async function main() {
44+
const cacheDirs = [...walkCaches(".")];
45+
46+
for (const dir of cacheDirs) {
47+
console.log(`Found .cache dir at ${dir}`);
48+
}
49+
50+
// mkdir -p ${COMBINED_CACHE_DIR}
51+
fs.mkdirSync(COMBINED_CACHE_DIR, { recursive: true });
52+
53+
// rm -f **/.cache/{lock,size} # -f to avoid errors if the cache is empty.
54+
await Promise.all(
55+
cacheDirs.map((cacheDir) =>
56+
(async function () {
57+
await fs.promises.rm(path.join(cacheDir, "lock"), { force: true });
58+
await fs.promises.rm(path.join(cacheDir, "size"), { force: true });
59+
})()
60+
)
61+
);
62+
63+
// # copy the contents of the .cache folders into the combined cache folder.
64+
// cp -r **/.cache/* ${COMBINED_CACHE_DIR}/ || : # ignore missing files
65+
await Promise.all(
66+
cacheDirs.map((cacheDir) => copyDir(cacheDir, COMBINED_CACHE_DIR))
67+
);
68+
69+
// # clean up the .cache folders
70+
// rm -rf **/.cache/*
71+
await Promise.all(
72+
cacheDirs.map((cacheDir) => fs.promises.rm(cacheDir, { recursive: true }))
73+
);
74+
}
75+
main();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Find Latest CodeQL Bundle
2+
description: Finds the URL of the latest released version of the CodeQL bundle.
3+
outputs:
4+
url:
5+
description: The download URL of the latest CodeQL bundle release
6+
value: ${{ steps.find-latest.outputs.url }}
7+
runs:
8+
using: composite
9+
steps:
10+
- name: Find Latest Release
11+
id: find-latest
12+
shell: pwsh
13+
run: |
14+
$Latest = gh release list --repo github/codeql-action --exclude-drafts --limit 1000 |
15+
ForEach-Object { $C = $_ -split "`t"; return @{ type = $C[1]; tag = $C[2]; } } |
16+
Where-Object { $_.type -eq 'Latest' }
17+
18+
$Tag = $Latest.tag
19+
if ($Tag -eq '') {
20+
throw 'Failed to find latest bundle release.'
21+
}
22+
23+
Write-Output "Latest bundle tag is '${Tag}'."
24+
"url=https://github.com/github/codeql-action/releases/download/${Tag}/codeql-bundle-linux64.tar.gz" >> $env:GITHUB_OUTPUT
25+
env:
26+
GITHUB_TOKEN: ${{ github.token }}

.github/workflows/check-query-ids.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Check query IDs
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "**/src/**/*.ql"
7+
- misc/scripts/check-query-ids.py
8+
- .github/workflows/check-query-ids.yml
9+
branches:
10+
- main
11+
- "rc/*"
12+
workflow_dispatch:
13+
14+
jobs:
15+
check:
16+
name: Check query IDs
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v3
20+
- name: Check for duplicate query IDs
21+
run: python3 misc/scripts/check-query-ids.py

.github/workflows/compile-queries.yml

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,58 +14,24 @@ jobs:
1414

1515
steps:
1616
- uses: actions/checkout@v3
17-
# calculate the merge-base with main, in a way that works both on PRs and pushes to main.
18-
- name: Calculate merge-base
19-
if: ${{ github.event_name == 'pull_request' }}
20-
env:
21-
BASE_BRANCH: ${{ github.base_ref }}
22-
run: |
23-
MERGE_BASE=$(git cat-file commit $GITHUB_SHA | grep '^parent ' | head -1 | cut -f 2 -d " ")
24-
echo "merge-base=$MERGE_BASE" >> $GITHUB_ENV
25-
- name: Read CodeQL query compilation - PR
26-
if: ${{ github.event_name == 'pull_request' }}
27-
uses: actions/cache@v3
28-
with:
29-
path: '*/ql/src/.cache'
30-
key: codeql-compile-pr-${{ github.sha }} # deliberately not using the `compile-compile-main` keys here.
31-
restore-keys: |
32-
codeql-compile-${{ github.base_ref }}-${{ env.merge-base }}
33-
codeql-compile-${{ github.base_ref }}-
34-
codeql-compile-main-
35-
- name: Fill CodeQL query compilation cache - main
36-
if: ${{ github.event_name != 'pull_request' }}
37-
uses: actions/cache@v3
38-
with:
39-
path: '*/ql/src/.cache'
40-
key: codeql-compile-${{ github.ref_name }}-${{ github.sha }} # just fill on main
41-
restore-keys: | # restore from another random commit, to speed up compilation.
42-
codeql-compile-${{ github.ref_name }}-
43-
codeql-compile-main-
4417
- name: Setup CodeQL
4518
uses: ./.github/actions/fetch-codeql
4619
with:
4720
channel: 'release'
21+
- name: Cache compilation cache
22+
id: query-cache
23+
uses: ./.github/actions/cache-query-compilation
24+
with:
25+
key: all-queries
4826
- name: check formatting
4927
run: find */ql -type f \( -name "*.qll" -o -name "*.ql" \) -print0 | xargs -0 codeql query format --check-only
5028
- name: compile queries - check-only
5129
# run with --check-only if running in a PR (github.sha != main)
5230
if : ${{ github.event_name == 'pull_request' }}
5331
shell: bash
54-
run: codeql query compile -j0 */ql/src --keep-going --warnings=error --check-only
32+
run: codeql query compile -j0 */ql/{src,examples} --keep-going --warnings=error --check-only --compilation-cache "${{ steps.query-cache.outputs.cache-dir }}"
5533
- name: compile queries - full
5634
# do full compile if running on main - this populates the cache
5735
if : ${{ github.event_name != 'pull_request' }}
5836
shell: bash
59-
run: |
60-
# Move all the existing cache into another folder, so we only preserve the cache for the current queries.
61-
mkdir -p ${COMBINED_CACHE_DIR}
62-
rm */ql/src/.cache/{lock,size}
63-
# copy the contents of the .cache folders into the combined cache folder.
64-
cp -r */ql/src/.cache/* ${COMBINED_CACHE_DIR}/
65-
# clean up the .cache folders
66-
rm -rf */ql/src/.cache/*
67-
68-
# compile the queries
69-
codeql query compile -j0 */ql/src --keep-going --warnings=error --compilation-cache ${COMBINED_CACHE_DIR}
70-
env:
71-
COMBINED_CACHE_DIR: ${{ github.workspace }}/compilation-dir
37+
run: codeql query compile -j0 */ql/{src,examples} --keep-going --warnings=error --compilation-cache "${{ steps.query-cache.outputs.cache-dir }}"

.github/workflows/csharp-qltest.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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 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 }}"
71+
env:
72+
GITHUB_TOKEN: ${{ github.token }}
73+
unit-tests:
74+
runs-on: ubuntu-latest
75+
steps:
76+
- uses: actions/checkout@v3
77+
- name: Setup dotnet
78+
uses: actions/setup-dotnet@v3
79+
with:
80+
dotnet-version: 6.0.202
81+
- name: Extractor unit tests
82+
run: |
83+
dotnet test -p:RuntimeFrameworkVersion=6.0.4 "${{ github.workspace }}/csharp/extractor/Semmle.Util.Tests"
84+
dotnet test -p:RuntimeFrameworkVersion=6.0.4 "${{ github.workspace }}/csharp/extractor/Semmle.Extraction.Tests"
85+
dotnet test -p:RuntimeFrameworkVersion=6.0.4 "${{ github.workspace }}/csharp/autobuilder/Semmle.Autobuild.CSharp.Tests"
86+
dotnet test -p:RuntimeFrameworkVersion=6.0.4 "${{ github.workspace }}/cpp/autobuilder/Semmle.Autobuild.Cpp.Tests"

0 commit comments

Comments
 (0)