site/tools/deploy.sh (1516B)
1 #!/usr/bin/env bash
2 # Build the landing page and publish it to the gh-pages branch.
3 #
4 # gh-pages holds only the built output and shares no history with main; the
5 # source is site/ on main. Requires sqzass on PATH (yay -S sqzass, or
6 # cargo install --git https://github.com/debuman/sqzass).
7 set -euo pipefail
8
9 REPO=$(git rev-parse --show-toplevel)
10 WORK=${WORK:-"${TMPDIR:-/tmp}/ommp-ghpages"}
11
12 command -v sqzass >/dev/null || { echo "sqzass not found on PATH" >&2; exit 1; }
13
14 sqzass build -i "$REPO/site"
15 sqzass doctor -i "$REPO/site"
16
17 git -C "$REPO" worktree remove "$WORK" --force 2>/dev/null || true
18 rm -rf "$WORK"
19 git -C "$REPO" fetch origin gh-pages
20 # Point the local branch at the remote before checking it out. GitHub writes its
21 # own commits to this branch whenever the Pages custom domain is changed, so a
22 # local ref that has not been moved forward will fork the history and the push
23 # will be rejected.
24 git -C "$REPO" branch -f gh-pages origin/gh-pages
25 git -C "$REPO" worktree add "$WORK" gh-pages
26
27 # Mirror rather than merge: files deleted from the site must disappear here too.
28 rsync -a --delete --exclude '.git' "$REPO/site/public/" "$WORK/"
29
30 git -C "$WORK" add -A
31 if git -C "$WORK" diff --cached --quiet; then
32 echo "nothing changed"
33 else
34 git -C "$WORK" commit -q -m "Deploy the landing page"
35 # No -q, and no success message unless the push actually returned 0.
36 git -C "$WORK" push origin gh-pages
37 echo "published → https://ommp.sqzer.com/"
38 fi
39 git -C "$REPO" worktree remove "$WORK" --force