Skip to main content

max / makenotwork

1.3 KB · 39 lines History Blame Raw
1 #!/usr/bin/env bash
2 # Sando bare-repo post-receive hook.
3 #
4 # Install: copy into <bare repo>/hooks/post-receive and chmod +x.
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 # Pick up SANDO_DAEMON / SANDO_BRANCH from the daemon's env file when present
12 # (the same file systemd's EnvironmentFile= points at). Lets the deployed hook
13 # reach a non-loopback listen address without changing the hook source.
14 if [[ -r /etc/sando/sando.env ]]; then
15 set -a
16 # shellcheck disable=SC1091
17 source /etc/sando/sando.env
18 set +a
19 fi
20
21 DAEMON_URL="${SANDO_DAEMON:-http://127.0.0.1:7766}"
22 DEPLOY_BRANCH="${SANDO_BRANCH:-main}"
23
24 while read -r oldsha newsha ref; do
25 if [[ "$ref" != "refs/heads/$DEPLOY_BRANCH" ]]; then
26 continue
27 fi
28 if [[ "$newsha" == "0000000000000000000000000000000000000000" ]]; then
29 # Branch deletion; nothing to build.
30 continue
31 fi
32 echo "sando: posting rebuild for $newsha"
33 curl --silent --show-error --fail \
34 -X POST "$DAEMON_URL/rebuild" \
35 -H 'Content-Type: application/json' \
36 -d "{\"sha\":\"$newsha\"}" \
37 || echo "sando: rebuild trigger failed; check daemon"
38 done
39