Skip to content

CodeQL Security Analysis #74

CodeQL Security Analysis

CodeQL Security Analysis #74

Workflow file for this run

name: CodeQL Security Analysis
on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop
schedule:
# Run every day at 6:00 AM UTC
- cron: '0 6 * * *'
workflow_dispatch:
permissions:
contents: read
security-events: write
actions: read
jobs:
analyze:
name: Analyze Code
runs-on: ubuntu-latest
timeout-minutes: 360
strategy:
fail-fast: false
matrix:
language: ['python']
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
queries: +security-and-quality
config: |
paths-ignore:
- '**/tests/**'
- '**/test_*.py'
- '**/*_test.py'
- '.venv/**'
- 'venv/**'
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: ".python-version"
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
- name: Install dependencies
run: |
uv sync --group dev --group test
- name: Autobuild
uses: github/codeql-action/autobuild@v3
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{ matrix.language }}"
upload: true
output: sarif-results
add-snippets: true
- name: Upload SARIF results
if: always()
uses: actions/upload-artifact@v4
with:
name: codeql-results-${{ matrix.language }}
path: sarif-results
retention-days: 30
- name: Filter SARIF for PRs
if: github.event_name == 'pull_request'
uses: advanced-security/filter-sarif@v1
with:
patterns: |
-**/tests/**
-**/test_*.py
input: sarif-results/${{ matrix.language }}.sarif
output: sarif-results/${{ matrix.language }}.sarif
summary:
name: Analysis Summary
runs-on: ubuntu-latest
needs: analyze
if: always()
steps:
- name: Generate summary
run: |
echo "## 🔐 CodeQL Analysis Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Language | Status |" >> $GITHUB_STEP_SUMMARY
echo "|----------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Python | ${{ needs.analyze.result == 'success' && '✅ No issues found' || '⚠️ Issues detected' }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ needs.analyze.result }}" != "success" ]; then
echo "### 🔍 Action Required" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Security issues were detected during the analysis." >> $GITHUB_STEP_SUMMARY
echo "Please review the Security tab for details." >> $GITHUB_STEP_SUMMARY
else
echo "✅ No security issues detected!" >> $GITHUB_STEP_SUMMARY
fi