name: CodeQL - Analyze

on:
  push:
    branches: [ main, development, 'feature/**' ]
  pull_request:
    branches: [ main, development ]
  schedule:
    - cron: '0 3 * * 1'

permissions:
  contents: read
  security-events: write
  actions: read
  pull-requests: read

jobs:
  analyze:
    name: CodeQL analysis (${{ matrix.language }})
    runs-on: ubuntu-latest
    # Skip forked PRs where CPMP_TOKEN lacks security-events permissions
    if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false
    permissions:
      contents: read
      security-events: write
      actions: read
      pull-requests: read
    strategy:
      fail-fast: false
      matrix:
        language: [ 'go', 'javascript-typescript' ]
    steps:
      - name: Checkout repository
        uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6

      - name: Initialize CodeQL
        uses: github/codeql-action/init@1b168cd39490f61582a9beae412bb7057a6b2c4e # v4
        with:
          languages: ${{ matrix.language }}

      - name: Setup Go
        if: matrix.language == 'go'
        uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6
        with:
          go-version: '1.25.5'

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

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