#!/usr/bin/env bash # Build with orgo and deploy public/ to homelab on push to main. set -euo pipefail remote_host="homelab" remote_path="/var/www/krz.sh" # pre-push feeds " " per line. # Only deploy when main is being pushed (and not deleted). zero="0000000000000000000000000000000000000000" deploy=0 while read -r local_ref local_sha remote_ref remote_sha; do if [ "$remote_ref" = "refs/heads/main" ] && [ "$local_sha" != "$zero" ]; then deploy=1 fi done if [ "$deploy" -eq 0 ]; then exit 0 fi echo "pre-push: building site with orgo..." ./build.sh echo "pre-push: deploying to ${remote_host}:${remote_path}..." # Upload assets before HTML so a page never references a cachebust URL # whose file is still the old version; Cloudflare would cache it for a year. rsync -az --exclude '*.html' public/ "${remote_host}:${remote_path}/" rsync -az --delete public/ "${remote_host}:${remote_path}/" echo "pre-push: deploy complete."