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+ # Glob for Actions toolcache
66+ CODEQL_GLOB='$RUNNER_TOOL_CACHE/CodeQL/*/x64/codeql/codeql'
67+
68+ if [ -f "$CODEQL_GLOB" ]; then
69+ CODEQL_BINARY=$(echo $CODEQL_GLOB)
70+ elif which codeql >/dev/null; then
71+ CODEQL_BINARY="codeql"
72+ elif gh codeql >/dev/null; then
73+ CODEQL_BINARY="gh codeql"
74+ else
75+ gh extension install github/gh-codeql
76+ CODEQL_BINARY="gh codeql"
77+ fi
78+ echo "[+] Using codeql binary: $CODEQL_BINARY"
79+
80+ $CODEQL_BINARY database create \
81+ --language ql --overwrite \
82+ --search-path "$CODEQL_REPOSITORY_PATH/ql/extractor-pack" \
83+ ../ql-for-ql-db
84+
85+ $CODEQL_BINARY database analyze \
86+ --format=sarif-latest \
87+ --additional-packs "$CODEQL_REPOSITORY_PATH/ql" \
88+ --output=$SARIF_FILE \
89+ ../ql-for-ql-db \
90+ $CODEQL_SUITE
91+
92+ echo "sarif=$SARIF_FILE" >> "$GITHUB_OUTPUT"
93+
94+ - name : Upload SARIF file
95+ uses : github/codeql-action/upload-sarif@v3
96+ with :
97+ sarif_file : ${{ steps.run_ql.outputs.sarif }}
0 commit comments