Skip to content

Add initial QL for QL support #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions .github/workflows/codeql-ql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: CodeQL for QL

on:
workflow_call:
workflow_dispatch:

permissions:
contents: read
security-events: write

jobs:
ql-for-ql:
runs-on: ubuntu-latest

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

steps:
- name: "Checkout repository"
uses: actions/checkout@v4

- name: "Set up Rust"
uses: dtolnay/rust-toolchain@nightly

- name: "Build QL-for-QL"
env:
GH_TOKEN: ${{ github.token }}
CODEQL_REPOSITORY_PATH: ${{ runner.temp }}/codeql
run: |
set -e

CODEQL_REPOSITORY_PATH="${CODEQL_REPOSITORY_PATH:-$HOME/.codeql/codeql-ql}"
echo "CodeQL repository path: $CODEQL_REPOSITORY_PATH"

if [ ! -d "$CODEQL_REPOSITORY_PATH" ]; then
echo "CodeQL repository not found. Cloning..."
mkdir -p "$HOME/.codeql"

git clone \
--depth 1 \
https://github.com/github/codeql.git \
"$CODEQL_REPOSITORY_PATH"
fi

pushd "$CODEQL_REPOSITORY_PATH/ql" > /dev/null

echo "Building QL Extractor..."
./scripts/create-extractor-pack.sh

popd > /dev/null

- name: "Run QL-for-QL"
id: run_ql
env:
GH_TOKEN: ${{ github.token }}
CODEQL_REPOSITORY_PATH: ${{ runner.temp }}/codeql
run: |
set -e

SARIF_FILE="${SARIF_FILE:-ql-for-ql.sarif}"
CODEQL_REPOSITORY_PATH="${CODEQL_REPOSITORY_PATH:-$HOME/.codeql/codeql-ql}"
CODEQL_SUITE="${CODEQL_SUITE:-$CODEQL_REPOSITORY_PATH/ql/ql/src/codeql-suites/ql-code-scanning.qls}"

# Glob for Actions toolcache
CODEQL_GLOB='$RUNNER_TOOL_CACHE/CodeQL/*/x64/codeql/codeql'

if [ -f "$CODEQL_GLOB" ]; then
CODEQL_BINARY=$(echo $CODEQL_GLOB)
elif which codeql >/dev/null; then
CODEQL_BINARY="codeql"
elif gh codeql >/dev/null; then
CODEQL_BINARY="gh codeql"
else
gh extension install github/gh-codeql
CODEQL_BINARY="gh codeql"
fi
echo "[+] Using codeql binary: $CODEQL_BINARY"

$CODEQL_BINARY database create \
--language ql --overwrite \
--search-path "$CODEQL_REPOSITORY_PATH/ql/extractor-pack" \
../ql-for-ql-db

$CODEQL_BINARY database analyze \
--format=sarif-latest \
--additional-packs "$CODEQL_REPOSITORY_PATH/ql" \
--output=$SARIF_FILE \
../ql-for-ql-db \
$CODEQL_SUITE

echo "sarif=$SARIF_FILE" >> "$GITHUB_OUTPUT"

- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ${{ steps.run_ql.outputs.sarif }}
Loading