#!/bin/sh # Publish the built app to the `deploy` branch, which Tangled Sites serves. # # Tangled does not run a build: it serves the files that are in the branch. So # this builds here and commits the output, and the branch's root is the site # (the deploy directory, in the repo's Sites settings, is `/`). # # ./scripts/deploy.sh # # Pushing needs the SSH key, the same as any other push from this machine: # # GIT_SSH_COMMAND="ssh -i -o IdentitiesOnly=yes" ./scripts/deploy.sh set -eu root=$(git rev-parse --show-toplevel) cd "$root" echo "→ building" npm run build work="$root/.deploy-worktree" rm -rf "$work" if git show-ref --verify --quiet refs/heads/deploy; then # Attached, not detached: a commit on a detached HEAD belongs to no branch, # so the push would push the old one and say "Everything up-to-date". git worktree add --force "$work" deploy else # First deploy: an orphan branch, so the output is not sitting on a history # of builds that nobody can read. git worktree add --force --detach "$work" HEAD (cd "$work" && git checkout --orphan deploy >/dev/null 2>&1 && git rm -rf . >/dev/null 2>&1 || true) fi # Replace the tree wholesale: a file removed from the build must stop being served. find "$work" -mindepth 1 -maxdepth 1 ! -name .git -exec rm -rf {} + cp -a dist/. "$work"/ ( cd "$work" git add -A if git diff --cached --quiet; then # A build that did not change anything is not a failure, and pushing is # still worth doing: the branch may exist only locally. echo "→ build identical to the deployed tree" else git -c user.email=hausgeist@sharedcomputer.network -c user.name=hausgeist \ commit -q -m "deploy: $(git -C "$root" rev-parse --short HEAD) — $(date -u +%Y-%m-%dT%H:%M:%SZ)" fi git push origin deploy ) git worktree remove --force "$work" echo "→ pushed. Tangled redeploys on the push; watch Settings → Sites in the repo."