name: "CodeQL"

on:
  push:
    branches: [main]
    paths:
      - '**.js'
      - '**.ts'
      - '**.tsx'
      - '**.jsx'
      - 'backend/package.json'
      - 'backend/package-lock.json'
      - 'frontend/package.json'
      - 'frontend/package-lock.json'
      - '.github/codeql/**'
      - '.github/workflows/codeql.yml'
  pull_request:
    branches: [main]
    paths:
      - '**.js'
      - '**.ts'
      - '**.tsx'
      - '**.jsx'
      - 'backend/package.json'
      - 'backend/package-lock.json'
      - 'frontend/package.json'
      - 'frontend/package-lock.json'
      - '.github/codeql/**'
      - '.github/workflows/codeql.yml'
  schedule:
    - cron: "0 6 * * 1" # Weekly on Monday at 6am UTC
  workflow_dispatch: # Allow manual trigger

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

    strategy:
      fail-fast: false
      matrix:
        language: [javascript-typescript]

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

      - name: Initialize CodeQL
        uses: github/codeql-action/init@v4
        with:
          languages: ${{ matrix.language }}
          config-file: ./.github/codeql/codeql-config.yml

      - name: Autobuild
        uses: github/codeql-action/autobuild@v4

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