---
name: Build & Test (Fedora 34)

on:
  pull_request:
  push:
    branches:
      - master
      - develop
      - distros/fedora-34

env:
  build-group-dependencies: >-
    "C Development Tools and Libraries"
    "Development Libraries"
    "Development Tools"
  build-dependencies: >-
    cairo-devel
    glib2-devel
    httpd-devel
    iniparser-devel
    libcurl-devel
    libmemcached-devel
    librados-devel
    mapnik-devel

jobs:
  build-and-test:
    name: Build & Test
    runs-on: ubuntu-latest
    container:
      image: fedora:34
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Provision environment
        uses: ./.github/actions/yum/provision
        with:
          groups: ${{ env.build-group-dependencies }}
          packages: ${{ env.build-dependencies }} httpd
      - name: Run `./autogen.sh`
        run: ./autogen.sh
      - name: Run `./configure`
        run: ./configure
      - name: Run `make`
        run: make
      - name: Run `make test`
        run: make test
      - name: Configure Apache HTTP Server
        run: |
          mkdir --parents /usr/share/javascript/leaflet
          curl --silent \
            "https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/leaflet.js" \
            > /usr/share/javascript/leaflet/leaflet.min.js
          curl --silent \
            "https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/leaflet.css" \
            > /usr/share/javascript/leaflet/leaflet.css
          mkdir --parents /run/renderd /var/cache/renderd/tiles
          ln --symbolic \
            "${PWD}/utils/example-map" \
            /var/www/
          ln --symbolic \
            /usr/share/javascript/leaflet \
            /var/www/example-map/leaflet
          ln --symbolic \
            "${PWD}/etc/renderd/renderd.conf.examples" \
            /etc/renderd.conf
          ln --symbolic \
            "${PWD}/etc/apache2/renderd.conf" \
            /etc/httpd/conf.d/renderd.conf
          ln --symbolic \
            "${PWD}/etc/apache2/renderd-example-map.conf" \
            /etc/httpd/conf.d/renderd-example-map.conf
          echo "LoadModule tile_module /usr/lib64/httpd/modules/mod_tile.so" \
            | tee --append /etc/httpd/conf.modules.d/11-mod_tile.conf
          sed --in-place \
            "s#/usr/lib/mapnik/3.0/input#/usr/lib64/mapnik/input#g" \
            /etc/renderd.conf
          sed --in-place \
            "s#/usr/share/fonts/truetype#/usr/share/fonts#g" \
            /etc/renderd.conf
          rm --force /etc/httpd/conf.d/welcome.conf
      - name: Run `make install`
        run: make install
      - name: Run `make install-mod_tile`
        run: make install-mod_tile
      - name: Start `renderd`
        run: renderd
      - name: Start Apache HTTP Server
        run: httpd
      - name: Test Apache HTTP Server `mod_tile` module
        run: |
          curl --silent http://localhost/renderd-example/tiles/9/297/191.png \
            | sha224sum - \
            | grep 9cd82e5af9d9002a1c75126ebdb7bf054ec0b7ed0db228dfb0a09bae
