name: "CodeQL Security Analysis"
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
schedule:
# Run weekly on Sundays at 1:30 AM UTC
- cron: '30 1 * * 0'
permissions:
actions: read
contents: read
security-events: write
jobs:
analyze:
name: Analyze Code
runs-on: ubuntu-latest
timeout-minutes: 360
strategy:
fail-fast: false
matrix:
language: [ 'python' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
# Initialize CodeQL tools for scanning
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file
# queries: security-extended,security-and-quality
# Install dependencies to improve analysis
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
# Install dev dependencies for more comprehensive analysis
pip install pytest black isort mypy ruff
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java)
# If this step fails, then you should remove it and run the build manually
- name: Autobuild
uses: github/codeql-action/autobuild@v3
# Alternative build command for Python projects if autobuild doesn't work
# - name: Manual build
# run: |
# echo "No compilation required for Python"
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
# Upload SARIF results to GitHub Security tab
upload: true