Skip to content

Commit e290c96

Browse files
committed
feat: Add initial QL for QL support
1 parent ed19480 commit e290c96

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

.github/workflows/codeql-ql.yml

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: CodeQL for QL
2+
3+
on:
4+
workflow_call:
5+
workflow_dispatch:
6+
7+
permissions:
8+
contents: read
9+
security-events: write
10+
11+
jobs:
12+
ql-for-ql:
13+
runs-on: ubuntu-latest
14+
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
17+
cancel-in-progress: true
18+
19+
steps:
20+
- name: "Checkout repository"
21+
uses: actions/checkout@v4
22+
23+
- name: "Set up Rust"
24+
uses: dtolnay/rust-toolchain@nightly
25+
26+
- name: "Build QL-for-QL"
27+
env:
28+
GH_TOKEN: ${{ github.token }}
29+
CODEQL_REPOSITORY_PATH: ${{ runner.temp }}/codeql
30+
run: |
31+
set -e
32+
33+
CODEQL_REPOSITORY_PATH="${CODEQL_REPOSITORY_PATH:-$HOME/.codeql/codeql-ql}"
34+
echo "CodeQL repository path: $CODEQL_REPOSITORY_PATH"
35+
36+
if [ ! -d "$CODEQL_REPOSITORY_PATH" ]; then
37+
echo "CodeQL repository not found. Cloning..."
38+
mkdir -p "$HOME/.codeql"
39+
40+
git clone \
41+
--depth 1 \
42+
https://github.com/github/codeql.git\
43+
"$CODEQL_REPOSITORY_PATH"
44+
fi
45+
46+
pushd "$CODEQL_REPOSITORY_PATH/ql" > /dev/null
47+
48+
echo "Building QL Extractor..."
49+
./scripts/create-extractor-pack.sh
50+
51+
popd > /dev/null
52+
53+
- name: "Run QL-for-QL"
54+
id: run_ql
55+
env:
56+
GH_TOKEN: ${{ github.token }}
57+
CODEQL_REPOSITORY_PATH: ${{ runner.temp }}/codeql
58+
run: |
59+
set -e
60+
61+
SARIF_FILE="${SARIF_FILE:-ql-for-ql.sarif}"
62+
CODEQL_REPOSITORY_PATH="${CODEQL_REPOSITORY_PATH:-$HOME/.codeql/codeql-ql}"
63+
CODEQL_SUITE="${CODEQL_SUITE:-$CODEQL_REPOSITORY_PATH/ql/ql/src/codeql-suites/ql-code-scanning.qls}"
64+
65+
if which codeql >/dev/null; then
66+
CODEQL_BINARY="codeql"
67+
elif gh codeql >/dev/null; then
68+
CODEQL_BINARY="gh codeql"
69+
else
70+
gh extension install github/gh-codeql
71+
CODEQL_BINARY="gh codeql"
72+
fi
73+
74+
$CODEQL_BINARY database create \
75+
--language ql --overwrite \
76+
--search-path "$CODEQL_REPOSITORY_PATH/ql/extractor-pack" \
77+
../ql-for-ql-db
78+
79+
$CODEQL_BINARY database analyze \
80+
--format=sarif-latest \
81+
--additional-packs "$CODEQL_REPOSITORY_PATH/ql" \
82+
--output=$SARIF_FILE \
83+
../ql-for-ql-db \
84+
$CODEQL_SUITE
85+
86+
echo "sarif=[$matrix]" >> "$GITHUB_OUTPUT"
87+
88+
- name: Upload SARIF file
89+
uses: github/codeql-action/upload-sarif@v3
90+
with:
91+
sarif_file: ${{ steps.run_ql.outputs.SARIF_FILE }}

0 commit comments

Comments
 (0)