on:
  workflow_dispatch:
  schedule:
  - cron: 0 6 * * *
  push:
    branches:
    - main
    paths:
    - '.github/workflows/codeql-analysis.yml'

permissions:
  contents: read
  security-events: write

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

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

    steps:
      - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 #v6.0.3
        with:
          fetch-depth: 2
          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@8aad20d150bbac5944a9f9d289da16a4b0d87c1e #v4.36.2
        with:
          languages: cpp

      - name: Build ImageMagick
        run: |
          make

      - name: Perform CodeQL Analysis
        uses: github/codeql-action/analyze@8aad20d150bbac5944a9f9d289da16a4b0d87c1e #v4.36.2

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

    steps:
      - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 #v6.0.3
        with:
          persist-credentials: false

      - name: Initialize CodeQL
        uses: github/codeql-action/init@8aad20d150bbac5944a9f9d289da16a4b0d87c1e #v4.36.2
        with:
          languages: actions

      - name: Perform CodeQL Analysis
        uses: github/codeql-action/analyze@8aad20d150bbac5944a9f9d289da16a4b0d87c1e #v4.36.2
