#!/usr/bin/env bash # Put dist/ on the `site` branch, which holds build output and nothing else. # git-sync follows that branch; there is no image and no rollout. # # The orphan branch is named per-run and deleted in the trap. A fixed name # survives the worktree and collides on the second run, which it did twice. set -euo pipefail cd "$(dirname "$0")/.." [ -d dist ] || { echo "no dist/ — run npm run build first" >&2; exit 1; } ROOT=$PWD SHA=$(git rev-parse --short HEAD) TMP="publish-$$" WORK=$(mktemp -d) cleanup() { git -C "$ROOT" worktree remove --force "$WORK" 2>/dev/null || true rm -rf "$WORK" git -C "$ROOT" branch -qD "$TMP" 2>/dev/null || true } trap cleanup EXIT git worktree add -q --detach "$WORK" cd "$WORK" git checkout -q --orphan "$TMP" git rm -rq --cached . 2>/dev/null || true find . -mindepth 1 -maxdepth 1 ! -name .git -exec rm -rf {} + mkdir dist && cp -R "$ROOT/dist/." dist/ git add -A git commit -q -m "site: built from $SHA" git push -qf origin HEAD:site cd "$ROOT" echo "published site branch from $SHA"