PoC - Run CodeQL and add comment to PR with the findings without sending to Security Tab #4
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "CodeQL CLI Analysis" | |
on: | |
pull_request: | |
branches: [ "main" ] | |
jobs: | |
analyze: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Java (required for CodeQL CLI) | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'temurin' | |
java-version: '21' | |
- name: Install CodeQL CLI | |
run: | | |
CODEQL_VERSION="2.19.1" | |
wget https://github.com/github/codeql-cli-binaries/releases/download/v${CODEQL_VERSION}/codeql-linux64.zip | |
unzip codeql-linux64.zip | |
sudo mv codeql /usr/local/bin/ | |
echo "/usr/local/bin/codeql" >> $GITHUB_PATH | |
echo "CodeQL installed" | |
- name: Initialize CodeQL database | |
run: | | |
codeql database create codeql-db --language=javascript --source-root=node-sample | |
echo "CodeQL database initialized" | |
- name: Run CodeQL analysis | |
run: | | |
codeql database analyze codeql-db \ | |
--format=sarif-latest \ | |
--output=results.sarif \ | |
- name: Run sarif-to-comment | |
run: | | |
npx @security-alert/sarif-to-comment \ | |
--commentUrl "$URL" \ | |
--sarifContentOwner "$OWNER" \ | |
--sarifContentRepo "$REPOSITORY" \ | |
--sarifContentBranch "$BRANCH" \ | |
"$File" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
REPOSITORY: "codeql_troubleshoot_container" | |
OWNER: "Perdiga" | |
URL: "https://github.com/Perdiga/codeql_troubleshoot_container/pull/1" | |
BRANCH: "main" | |
File: "./results.sarif" |