#!/bin/bash
set -e -u

while read oldrev newrev ref
do
  if [[ $ref =~ .*/main$ ]]; then
    echo "[deploy] main ref received"

    echo "[deploy] moving into temporary work tree"; {
      gitdir=$PWD
      cd ~/jonathan.is
    }

    echo "[deploy] checking out latest source"; {
      git --work-tree=$PWD --git-dir=$gitdir checkout --force
    }

    echo "[deploy] building and deploying site"; {
      podman-compose run --podman-run-args='--log-driver=none' deploy
    }
  fi
done
