name: CodeQL
on:
  push:
    branches: [main, rhel-*]
  pull_request:
    branches: [main, rhel-*]

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

    strategy:
      fail-fast: false
      matrix:
        language:
          - python
          - javascript
          # Let's enable these one by one
          #- cpp

    steps:
      - name: Checkout
        uses: actions/checkout@v4

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

      - name: Install build dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y --no-install-recommends gettext libssh-dev zlib1g-dev libkrb5-dev libxslt1-dev libglib2.0-dev libgnutls28-dev libsystemd-dev libpolkit-agent-1-dev libpcp3-dev libjson-glib-dev libpam0g-dev libpcp-import1-dev libpcp-pmda3-dev systemd xsltproc xmlto docbook-xsl
        if: ${{ matrix.language == 'cpp' }}

      - name: Build
        run: |
          # disable documentation building as this indirectly triggers a build of pkg/static
          ./autogen.sh --disable-doc
          # only build static/ -- it's the fastest one (just takes a few seconds)
          make -j$(nproc) NODE_ENV=development ONLYDIR=static
        if: ${{ matrix.language == 'cpp' }}

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