on:
  workflow_dispatch:
  push:
    branches:
    - main
    tags:
    - '!*'
  pull_request:
    branches:
    - main

permissions: {}

name: Codeql analysis
jobs:
  c_cpp:
    name: Linux Q${{matrix.quantum}}-x64 hdri=${{matrix.hdri}} (${{matrix.modules}})
    runs-on: ubuntu-24.04

    permissions:
      contents: read
      security-events: write

    strategy:
      fail-fast: false
      matrix:
        quantum: [ 16 ]
        hdri: [ yes ]
        modules: [ 'with-modules', 'without-modules' ]

    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 #v7.0.1
        with:
          persist-credentials: false

      - name: Install dependencies
        run: |
          set -e
          export DEBIAN_FRONTEND=noninteractive
          sudo apt-get update -y
          sudo apt-get install -y libltdl-dev

      - name: Configure ImageMagick
        run: |
          export CFLAGS="-Wno-deprecated-declarations"
          autoreconf -fiv
          ./configure --with-quantum-depth=${{matrix.quantum}} --enable-hdri=${{matrix.hdri}} --${{matrix.modules}}
          echo "" > config.status

      - name: Initialize CodeQL
        uses: github/codeql-action/init@7188fc363630916deb702c7fdcf4e481b751f97a #v4.37.1
        with:
          languages: c-cpp

      - name: Build ImageMagick
        run: |
          make

      - name: Perform CodeQL Analysis
        uses: github/codeql-action/analyze@7188fc363630916deb702c7fdcf4e481b751f97a #v4.37.1

  actions:
    name: CodeQL analysis (GitHub Actions)
    runs-on: ubuntu-24.04

    permissions:
      contents: read
      security-events: write

    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 #v7.0.1
        with:
          persist-credentials: false

      - name: Initialize CodeQL
        uses: github/codeql-action/init@7188fc363630916deb702c7fdcf4e481b751f97a #v4.37.1
        with:
          languages: actions

      - name: Perform CodeQL Analysis
        uses: github/codeql-action/analyze@7188fc363630916deb702c7fdcf4e481b751f97a #v4.37.1
