git.lucas.co / gitsite
the static git browser that builds this site
git clone https://git.lucas.co/gitsite.git

autodeploy.sh (859B)

 1 #!/bin/sh
 2 # Publish git.lucas.co only if any listed repo has new commits.
 3 # Run by the gitsite.timer systemd user unit; log: ~/.cache/gitsite/autodeploy.log
 4 set -e
 5 
 6 BASE=$(dirname "$(readlink -f "$0")")
 7 STATE="$HOME/.cache/gitsite/last-publish-heads"
 8 
 9 current=$(grep -v '^#' "$BASE/repos.conf" | grep -v '^$' | \
10     while IFS='|' read -r name path desc mode; do
11         # path is a URL (GitHub); ls-remote is one round trip per repo. A
12         # repo with no commits yet answers nothing, hence "empty".
13         echo "$name $(git ls-remote "$path" HEAD 2>/dev/null | cut -f1 | grep . || echo empty)"
14     done | sha256sum | cut -d' ' -f1)
15 
16 if [ -f "$STATE" ] && [ "$(cat "$STATE")" = "$current" ]; then
17     echo "$(date -Is) no changes, skipping"
18     exit 0
19 fi
20 
21 "$BASE/build.sh"
22 "$BASE/deploy.sh"
23 printf '%s' "$current" > "$STATE"
24 echo "$(date -Is) published"