name: 14. _CodeQL Scan

on:
  workflow_call:
  workflow_dispatch:

jobs:
  analyze:
    name: Analyze
    runs-on: ubuntu-latest
    permissions:
      actions: read
      contents: read
      security-events: write

    strategy:
      fail-fast: false
      matrix:
        language: [ 'python', 'cpp' ]

    steps:
    - name: Checkout repository
      uses: actions/checkout@v6
      with:
        submodules: recursive

    - name: Set up Python
      uses: actions/setup-python@v6
      with:
        python-version: '3.11'

    - name: Set up Go
      uses: actions/setup-go@v6
      with:
        go-version: 'stable'

    - name: Install uv
      uses: astral-sh/setup-uv@v7
      with:
        enable-cache: true

    - name: Install system dependencies
      run: |
        sudo apt-get update
        sudo apt-get install -y cmake build-essential

    - name: Install dependencies
      run: |
        uv sync --frozen
        uv pip install setuptools pybind11 cmake wheel

    - name: Initialize CodeQL
      uses: github/codeql-action/init@v4
      with:
        languages: ${{ matrix.language }}
        queries: security-and-quality

    - name: Build extensions
      if: matrix.language == 'cpp'
      run: uv run python setup.py build_ext --inplace

    - name: Perform CodeQL Analysis
      uses: github/codeql-action/analyze@v4
      with:
        category: "/language:${{ matrix.language }}"
