name: "CodeQL"

on:
  push:
    branches: [main, 3.x, 2.x]
  pull_request:
    # Must match 'push' so PRs targeting release branches also get scanned.
    # The ruleset requires CodeQL as a status check on main, 3.x, and 2.x;
    # without these in pull_request, PRs to 3.x/2.x would wait forever for
    # a required check that never fires.
    branches: [main, 3.x, 2.x]
  schedule:
    - cron: '0 19 * * 4'

permissions:
  contents: read

jobs:
  analyze:
    permissions:
      actions: read          # for github/codeql-action/init to get workflow details
      contents: read         # for actions/checkout to fetch code
      security-events: write # for github/codeql-action/autobuild to send a status report
    name: Analyze
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false
      matrix:
        # Override automatic language detection by changing the below list
        # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
        language: ['javascript']
        # Learn more...
        # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection

    steps:
    - name: Harden the runner (Audit all outbound calls)
      uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
      with:
        egress-policy: audit

    - name: Checkout repository
      uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      with:
        persist-credentials: false
        # Default fetch-depth is fine. The old 'git checkout HEAD^2' dance
        # from legacy CodeQL templates is no longer needed - modern
        # codeql-action handles PR head checkout itself, and under this
        # repo's linear-history ruleset PRs aren't two-parent merges anyway.

    # Initializes the CodeQL tools for scanning.
    - name: Initialize CodeQL
      uses: github/codeql-action/init@e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81 # v4.37.3
      with:
         languages: ${{ matrix.language }}

    # Autobuild attempts to build any compiled languages  (C/C++, C#, or Java).
    # If this step fails, then you should remove it and run the build manually (see below)
    - name: Autobuild
      uses: github/codeql-action/autobuild@e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81 # v4.37.3

    # ℹ️ Command-line programs to run using the OS shell.
    # 📚 https://git.io/JvXDl

    # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
    #    and modify them (or add more) to build your code if your project
    #    uses a compiled language

    #- run: |
    #   make bootstrap
    #   make release

    - name: Perform CodeQL Analysis
      uses: github/codeql-action/analyze@e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81 # v4.37.3
