blob: 809684825f3068f7cfe6e039d802c60908f7892a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#!/usr/bin/env bash
# post-receive hook for meru's homepage.git bare repo.
# Deploys jayrup.me on every push to main, using the pushed deploy-docker.sh.
#
# Install on meru (one-time):
# cp hooks/post-receive ~/projects/homepage.git/hooks/post-receive
# chmod +x ~/projects/homepage.git/hooks/post-receive
# Also authorize meru's SSH key on nandi (jayrup@jayrup.me ~/.ssh/authorized_keys).
#
# Log: /tmp/homepage-deploy.log — also echoed to the pusher (tee).
set -uo pipefail
# Serialize concurrent pushes (flock from util-linux)
exec 9>/tmp/homepage-deploy.lock
flock 9
LOG=/tmp/homepage-deploy.log
exec > >(tee -a "$LOG") 2>&1
echo "=== post-receive $(date -u +%Y-%m-%dT%H:%M:%SZ) ==="
BARE_DIR="$(cd "$(dirname "$0")/.." && pwd)"
# Private runtime dir — no fixed /tmp paths, cleaned up on exit
BUILD_DIR="$(mktemp -d /tmp/homepage-build.XXXXXX)"
trap 'rm -rf "$BUILD_DIR"' EXIT
DEPLOYED=0
while read oldrev newrev ref; do
case "$ref" in
refs/heads/main)
OLD_SHA="$(git --git-dir="$BARE_DIR" rev-parse --short "$oldrev")"
NEW_SHA="$(git --git-dir="$BARE_DIR" rev-parse --short "$newrev")"
echo ">> push to main: $OLD_SHA..$NEW_SHA"
# Snapshot the pushed tree (no .git, exact commit)
git --git-dir="$BARE_DIR" archive "$newrev" | tar -x -C "$BUILD_DIR"
bash "$BUILD_DIR/deploy-docker.sh" "$BUILD_DIR" "$NEW_SHA"
DEPLOYED=1
;;
*)
echo ">> skipped $ref (only refs/heads/main deploys)"
;;
esac
done
[ "$DEPLOYED" -eq 1 ] && echo "=== hook done OK ===" || echo "=== nothing deployed ==="
|