#!/usr/bin/env bash # Manual fallback. CI publishes every push to main (.tangled/workflows/ci.yml), # so normally you only push and then run tools/live.sh. # # This builds the tip of main and publishes it to the `pages` branch. It refuses # unless HEAD is exactly origin/main, so a stale checkout cannot roll the site # back, and tools/publish-pages.sh checks again right before pushing. set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" cd "$ROOT" [ -z "$(git status --porcelain --untracked-files=no)" ] || { echo "deploy: commit your changes first" >&2; exit 1; } git fetch -q origin main REV="$(git rev-parse HEAD)" MAIN="$(git rev-parse origin/main)" if [ "$REV" != "$MAIN" ]; then if git merge-base --is-ancestor "$REV" "$MAIN"; then echo "deploy: refusing. HEAD ${REV:0:12} is behind origin/main ${MAIN:0:12}; publishing it would roll the site back. Rebase first." >&2 else echo "deploy: refusing. HEAD ${REV:0:12} is not origin/main ${MAIN:0:12}; push it to main first (CI then deploys it)." >&2 fi exit 1 fi npm run ci # type-check, test, build bash tools/publish-pages.sh "$REV" dist || { s=$?; [ "$s" -eq 2 ] && echo "deploy: main moved on while building; not publishing an old build. Rebase and run again, or let CI publish the new tip" >&2; exit "$s" } exec bash tools/live.sh "$REV"