---
name: Build & Test (Ubuntu 20.04)

on:
  pull_request:
  push:
    branches:
      - master
      - develop
      - distros/ubuntu-20-04

env:
  build-dependencies: >-
    apache2-dev
    libcairo2-dev
    libcurl4-gnutls-dev
    libglib2.0-dev
    libiniparser-dev
    libmapnik-dev
    libmemcached-dev
    librados-dev

jobs:
  build-and-test:
    name: Build & Test
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Provision environment
        uses: ./.github/actions/apt/provision
        with:
          packages: >-
            ${{ env.build-dependencies }}
            apache2
            libjs-leaflet
      - 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: |
          sudo mkdir --parents /run/renderd /var/cache/renderd/tiles
          sudo ln --symbolic \
            "${PWD}/utils/example-map" \
            /var/www/
          sudo ln --symbolic \
            /usr/share/javascript/leaflet \
            /var/www/example-map/leaflet
          sudo ln --symbolic \
            "${PWD}/etc/renderd/renderd.conf.examples" \
            /etc/renderd.conf
          sudo ln --symbolic \
            "${PWD}/etc/apache2/renderd.conf" \
            /etc/apache2/conf-enabled/renderd.conf
          sudo ln --symbolic \
            "${PWD}/etc/apache2/renderd-example-map.conf" \
            /etc/apache2/conf-enabled/renderd-example-map.conf
          echo "LoadModule tile_module /usr/lib/apache2/modules/mod_tile.so" \
            | sudo tee --append /etc/apache2/mods-enabled/mod_tile.load
      - name: Run `sudo make install`
        run: sudo make install
      - name: Run `make install-mod_tile`
        run: sudo make install-mod_tile
      - name: Start `renderd`
        run: sudo renderd
      - name: Enable & start Apache HTTP Server
        run: sudo systemctl --now enable apache2
      - name: Test Apache HTTP Server `mod_tile` module
        run: |
          curl --silent http://localhost/renderd-example/tiles/9/297/191.png \
            | sha224sum - \
            | grep 9cd82e5af9d9002a1c75126ebdb7bf054ec0b7ed0db228dfb0a09bae
