on:
  push:
    branches:
    - main
    paths:
    - '.github/workflows/doc-check.yml'
  pull_request:
    branches:
    - main
    paths:
    - '.github/workflows/doc-check.yml'
  workflow_dispatch:
  schedule:
    - cron: 0 6 * * 1

permissions:
  contents: read

name: Documentation check for Magick++
jobs:
  doxygen-check:
    name: Documentation check
    runs-on: ubuntu-24.04

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

      - uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 #v6.3.0
        with:
          python-version: 3.14

      - name: Install Python dependencies
        run: python -m pip install --user -r .github/build/python/requirements.txt --require-hashes

      - name: Install Doxygen
        run: sudo apt-get update && sudo apt-get install -y doxygen

      - name: Compare documentation
        run: |
          diff=""
          # first generate the Magick++ documentation to be up to date with the current code
          cd config && doxygen Magick++.dox.in &> /dev/null
          cd ..

          # documentation files with function signatures that we can compare with their corresponding doxygen file (currently)
          DOC_HTML=("Blob.html" "CoderInfo.html" "Geometry.html" "Image++.html" "Montage.html" "Pixels.html")
          DOXY_HTML=("Blob.html" "CoderInfo.html" "Geometry.html" "Image.html" "Montage.html" "Pixels.html")  # Image.html is the only one that differs from the doxygen file
          for i in "${!DOC_HTML[@]}"; do
              python3 .github/build/scripts/compare-signatures.py www/Magick++/"${DOC_HTML[$i]}" www/api/Magick++/classMagick_1_1"${DOXY_HTML[$i]}"
              if [ $? -eq -1 ]; then
                  diff="true"
              fi
          done

          if [ -n "$diff" ]; then
              echo "Mismatches detected!" && exit 1
          fi
          exit 0

