---
inputs:
  debian-build-dependencies:
    default: >-
      apache2-dev
      libcairo2-dev
      libcurl4-gnutls-dev
      libglib2.0-dev
      libiniparser-dev
      libmemcached-dev
      librados-dev
  debian-mapnik-latest-build-dependencies:
    default: >-
      cmake
      git
      libboost-program-options-dev
      libboost-regex-dev
      libfreetype6-dev
      libgdal-dev
      libharfbuzz-dev
      libicu-dev
      libjpeg-dev
      libpq-dev
      libproj-dev
      libsqlite3-dev
      libtiff-dev
      libwebp-dev
      libxml2-dev
      postgresql-server-dev-all
  debian-test-dependencies:
    default: >-
      apache2
      jq
      lcov
      memcached
  fedora-build-dependencies:
    default: >-
      cairo-devel
      glib2-devel
      httpd-devel
      iniparser-devel
      libcurl-devel
      libmemcached-devel
      librados-devel
      mapnik-devel
      sqlite-devel
  fedora-test-dependencies:
    default: >-
      httpd
      jq
      lcov
      memcached
      procps
  freebsd-build-dependencies:
    default: >-
      apache24
      cairo
      coreutils
      curl
      glib
      iniparser
      libmemcached
      mapnik
      pkgconf
  freebsd-test-dependencies:
    default: >-
      jq
      lcov
      memcached
  macos-build-dependencies:
    default: >-
      apr
      cairo
      curl
      glib
      httpd
      iniparser
      libmemcached
      mapnik
      pkg-config
  macos-test-dependencies:
    default: >-
      coreutils
      jq
      lcov
      memcached
  opensuse-build-dependencies:
    default: >-
      apache2-devel
      cairo-devel
      curl
      glib2-devel
      libcurl-devel
      libiniparser-devel
      libmemcached-devel
      librados-devel
  opensuse-test-dependencies:
    default: >-
      apache2
      apache2-event
      apache2-prefork
      jq
      lcov
      memcached
  opensuse-mapnik-build-dependencies:
    default: >-
      cmake
      freetype-devel
      gdal-devel
      git
      harfbuzz-devel
      libboost_regex1_75_0-devel
      libicu-devel
      libjpeg8-devel
      libpng16-devel
      libtiff-devel
      libwebp-devel
      libxml2-devel
      postgresql-devel
      proj-devel
      sqlite3-devel
      zlib-devel
  rhel-build-dependencies:
    default: >-
      cairo-devel
      glib2-devel
      httpd-devel
      iniparser-devel
      libcurl-devel
      libmemcached-devel
      librados2-devel
  rhel-test-dependencies:
    default: >-
      httpd
      jq
      lcov
      memcached
      procps
  rhel-mapnik-build-dependencies:
    default: >-
      boost-devel
      cmake
      freetype-devel
      gdal-devel
      git
      harfbuzz-devel
      libicu-devel
      libjpeg-devel
      libpng-devel
      libtiff-devel
      libwebp-devel
      libxml2-devel
      postgresql-devel
      proj-devel
      sqlite-devel
      zlib-devel
  ubuntu-build-dependencies:
    default: >-
      apache2-dev
      libcairo2-dev
      libcurl4-gnutls-dev
      libglib2.0-dev
      libiniparser-dev
      libmemcached-dev
      librados-dev
  ubuntu-mapnik-latest-build-dependencies:
    default: >-
      cmake
      git
      libboost-program-options-dev
      libboost-regex-dev
      libfreetype6-dev
      libgdal-dev
      libharfbuzz-dev
      libicu-dev
      libjpeg-dev
      libpq-dev
      libproj-dev
      libsqlite3-dev
      libtiff-dev
      libwebp-dev
      libxml2-dev
      postgresql-server-dev-all
  ubuntu-test-dependencies:
    default: >-
      apache2
      jq
      lcov
      memcached
  mapnik-build-version-centos-stream:
    default: 4.0.0
  mapnik-build-version-opensuse:
    default: 4.0.0

runs:
  using: composite
  steps:
    - name: Install Dependencies (CentOS Stream)
      uses: ./.github/actions/dependencies/install/yum
      with:
        dependencies: epel-release
        packages: >-
          ${{ inputs.rhel-build-dependencies }}
          ${{ inputs.rhel-mapnik-build-dependencies }}
          ${{ inputs.rhel-test-dependencies }}
          ${{ matrix.build_system == 'CMake' && 'cmake' || 'autoconf automake redhat-rpm-config' }}
          ${{ matrix.compiler == 'LLVM' && 'clang' || 'gcc gcc-c++' }}
          rpm-build
      if: startsWith(matrix.image, 'quay.io/centos/centos:stream')

    - name: Install Dependencies (Debian)
      uses: ./.github/actions/dependencies/install/apt-get
      with:
        packages: >-
          ${{ inputs.debian-build-dependencies }}
          ${{ matrix.mapnik_latest && inputs.debian-mapnik-latest-build-dependencies || 'libmapnik-dev' }}
          ${{ inputs.debian-test-dependencies }}
          ${{ matrix.build_system == 'CMake' && 'cmake' || '' }}
          ${{ matrix.compiler == 'LLVM' && 'clang' || 'g++ gcc' }}
      if: startsWith(matrix.image, 'debian:')

    - name: Install Dependencies (Fedora)
      uses: ./.github/actions/dependencies/install/yum
      with:
        packages: >-
          ${{ inputs.fedora-build-dependencies }}
          ${{ inputs.fedora-test-dependencies }}
          ${{ matrix.build_system == 'CMake' && 'cmake' || 'autoconf automake redhat-rpm-config' }}
          ${{ matrix.compiler == 'LLVM' && 'clang' || 'gcc gcc-c++' }}
          rpm-build
      if: startsWith(matrix.image, 'fedora:')

    - name: Install Dependencies (FreeBSD)
      uses: ./.github/actions/dependencies/install/pkg
      with:
        packages: >-
          ${{ inputs.freebsd-build-dependencies }}
          ${{ inputs.freebsd-test-dependencies }}
          ${{ matrix.build_system == 'CMake' && 'cmake' || 'autoconf automake' }}
          ${{ matrix.compiler == 'GNU' && 'gcc' || 'llvm' }}
      if: github.job == 'FreeBSD'

    - name: Install Dependencies (macOS)
      uses: ./.github/actions/dependencies/install/brew
      with:
        packages: >-
          ${{ inputs.macos-build-dependencies }}
          ${{ inputs.macos-test-dependencies }}
          ${{ matrix.build_system == 'CMake' && 'cmake' || 'autoconf automake' }}
          ${{ matrix.compiler == 'GNU' && 'gcc' || '' }}
      if: github.job == 'macOS'

    - name: Install Dependencies (openSUSE)
      uses: ./.github/actions/dependencies/install/zypper
      with:
        packages: >-
          ${{ inputs.opensuse-build-dependencies }}
          ${{ inputs.opensuse-mapnik-build-dependencies }}
          ${{ inputs.opensuse-test-dependencies }}
          ${{ matrix.build_system == 'CMake' && 'cmake' || 'automake' }}
          ${{ matrix.compiler == 'LLVM' && 'clang' || 'gcc12 gcc12-c++' }}
          rpm-build
      if: startsWith(matrix.image, 'opensuse/')

    - name: Install Dependencies (Ubuntu)
      uses: ./.github/actions/dependencies/install/apt-get
      with:
        packages: >-
          ${{ inputs.ubuntu-build-dependencies }}
          ${{ matrix.mapnik_latest && inputs.ubuntu-mapnik-latest-build-dependencies || 'libmapnik-dev' }}
          ${{ inputs.ubuntu-test-dependencies }}
          ${{ matrix.build_system == 'CMake' && 'cmake' || '' }}
          ${{ matrix.compiler == 'LLVM' && 'clang' || 'g++ gcc' }}
      if: |
        startsWith(matrix.image, 'ubuntu:') ||
        (!matrix.image && github.job != 'FreeBSD' && runner.os == 'Linux')

    - name: Link `gcc`/`g++` (openSUSE)
      run: |
        update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 40
        update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 40
      shell: bash --noprofile --norc -euxo pipefail {0}
      if: startsWith(matrix.image, 'opensuse/') && matrix.compiler == 'GNU'

    - name: Add `nobody` user/group (openSUSE)
      run: |
        useradd --home-dir / --no-create-home --shell /usr/sbin/nologin --system --user-group nobody
      shell: bash --noprofile --norc -euxo pipefail {0}
      if: startsWith(matrix.image, 'opensuse/')

    - name: Build & Install `mapnik` (CentOS Stream)
      uses: ./.github/actions/dependencies/build-and-install/mapnik
      with:
        version: ${{ inputs.mapnik-build-version-centos-stream }}
      if: startsWith(matrix.image, 'quay.io/centos/centos:stream')

    - name: Build & Install `mapnik` (openSUSE)
      uses: ./.github/actions/dependencies/build-and-install/mapnik
      with:
        version: ${{ inputs.mapnik-build-version-opensuse }}
      if: (!matrix.mapnik_latest && startsWith(matrix.image, 'opensuse/'))

    - name: Build & Install latest `mapnik` (Debian/Ubuntu)
      uses: ./.github/actions/dependencies/build-and-install/mapnik
      with:
        version: latest
      if: |
        matrix.mapnik_latest &&
        (startsWith(matrix.image, 'debian:') || startsWith(matrix.image, 'ubuntu:') || runner.os == 'Linux')

    - name: Build & Install latest `mapnik` (openSUSE)
      uses: ./.github/actions/dependencies/build-and-install/mapnik
      with:
        version: latest
      if: (matrix.mapnik_latest && startsWith(matrix.image, 'opensuse/'))
