krz/krz.sh

clone: git clone https://gitbay.org/krz/krz.sh.git

main: .githooks/pre-push · raw

 1#!/usr/bin/env bash
 2# Build with zola and deploy public/ to homelab on push to main.
 3set -euo pipefail
 4
 5remote_host="homelab"
 6remote_path="/var/www/krz.sh"
 7
 8# pre-push feeds "<local ref> <local sha> <remote ref> <remote sha>" per line.
 9# Only deploy when main is being pushed (and not deleted).
10zero="0000000000000000000000000000000000000000"
11deploy=0
12while read -r local_ref local_sha remote_ref remote_sha; do
13  if [ "$remote_ref" = "refs/heads/main" ] && [ "$local_sha" != "$zero" ]; then
14    deploy=1
15  fi
16done
17
18if [ "$deploy" -eq 0 ]; then
19  exit 0
20fi
21
22echo "pre-push: building site with zola..."
23zola build
24
25echo "pre-push: deploying to ${remote_host}:${remote_path}..."
26rsync -az --delete public/ "${remote_host}:${remote_path}/"
27
28echo "pre-push: deploy complete."