Skip to main content

max / makenotwork

1.3 KB · 38 lines History Blame Raw
1 #!/usr/bin/env bash
2 # Sando bare-repo post-receive hook.
3 #
4 # Installed at <bare repo>/hooks/post-receive by bootstrap-sandod-host.sh.
5 # Reads each updated ref from stdin (old new ref) and posts the new sha to
6 # the daemon's /rebuild endpoint. Only the configured deploy branch is
7 # acted on; pushes to other refs are silently ignored.
8
9 set -euo pipefail
10
11 # Source the operator's sando.env so $SANDO_DAEMON resolves to the tailnet
12 # listener, not the 127.0.0.1 default. Hooks run in the ssh push context with
13 # no environment, so this source step is load-bearing. Tolerate missing file
14 # so the hook still works in a dev clone.
15 if [[ -f /etc/sando/sando.env ]]; then
16 # shellcheck disable=SC1091
17 source /etc/sando/sando.env
18 fi
19
20 DAEMON_URL="${SANDO_DAEMON:-http://127.0.0.1:7766}"
21 DEPLOY_BRANCH="${SANDO_BRANCH:-main}"
22
23 while read -r oldsha newsha ref; do
24 if [[ "$ref" != "refs/heads/$DEPLOY_BRANCH" ]]; then
25 continue
26 fi
27 if [[ "$newsha" == "0000000000000000000000000000000000000000" ]]; then
28 # Branch deletion; nothing to build.
29 continue
30 fi
31 echo "sando: posting rebuild for $newsha"
32 curl --silent --show-error --fail \
33 -X POST "$DAEMON_URL/rebuild" \
34 -H 'Content-Type: application/json' \
35 -d "{\"sha\":\"$newsha\"}" \
36 || echo "sando: rebuild trigger failed; check daemon"
37 done
38