name: CodeQL

# Static analysis security testing (findings P13.x). Analyses the Rust core and
# the Python / JavaScript binding surfaces with GitHub's CodeQL engine. Results
# appear under Security → Code scanning. `build-mode: none` analyses source
# directly — no compilation step — for every language here.
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
  schedule:
    - cron: '31 3 * * 0' # Sundays 03:31 UTC

# Least-privilege default for the auto-injected GITHUB_TOKEN. The analyze job
# raises exactly the scopes CodeQL needs (security-events: write to upload
# results) in its own job-level block below; this top-level read-only default
# covers any future job (OpenSSF Scorecard: Token-Permissions).
permissions:
  contents: read

jobs:
  analyze:
    name: Analyze (${{ matrix.language }})
    runs-on: ubuntu-latest
    permissions:
      security-events: write # upload CodeQL results to code-scanning
      packages: read
      actions: read
      contents: read
    strategy:
      fail-fast: false
      matrix:
        include:
          - language: rust
            build-mode: none
          - language: python
            build-mode: none
          - language: javascript-typescript
            build-mode: none
    steps:
      - name: Checkout
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          persist-credentials: false

      - name: Initialize CodeQL
        uses: github/codeql-action/init@03e4368ac7daa2bd82b3e85262f3bf87ee112f57 # v3.36.0
        with:
          languages: ${{ matrix.language }}
          build-mode: ${{ matrix.build-mode }}

      - name: Perform CodeQL analysis
        uses: github/codeql-action/analyze@03e4368ac7daa2bd82b3e85262f3bf87ee112f57 # v3.36.0
        with:
          category: "/language:${{ matrix.language }}"
