Something went wrong. Try again.
A video game where you play as a misaligned AI, deceiving and building power. An experiment in spec-driven development. forked from cameron.stream/misaligned
Something went wrong. Try again.
3.6 kB · 100 lines
Shell
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101#!/usr/bin/env bash# Build the Starlight site and force-push an orphan `pages` branch whose# tree is exactly site/dist/ (index.html at root). Tangled Sites should be# configured: branch=pages, deploy directory=/.## CI auto-deploy is deferred until a write credential exists in Spindle# secrets. tools/task.sh finish calls this after every serialized main landing;# direct/manual landings must call it themselves.set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"SITE="$ROOT/site"DIST="$SITE/dist"BRANCH="${PAGES_BRANCH:-pages}"REMOTE="${PAGES_REMOTE:-origin}"TMP_REMOTE="pages-remote"SSH_CMD="$(git -C "$ROOT" config --get core.sshCommand || true)"HEAD_REVISION="$(git -C "$ROOT" rev-parse --verify 'HEAD^{commit}')"SOURCE_REVISION="$(git -C "$ROOT" rev-parse --verify "${SITE_SOURCE_REVISION:-HEAD}^{commit}")"export SITE_SOURCE_REVISION="$SOURCE_REVISION"
if [ "$SOURCE_REVISION" != "$HEAD_REVISION" ]; then echo "site-deploy: source revision $SOURCE_REVISION is not checked-out HEAD $HEAD_REVISION" >&2 exit 1fidirty=$(git -C "$ROOT" status --porcelain)if [ -n "$dirty" ]; then echo "site-deploy: refusing to publish a dirty source tree" >&2 printf '%s\n' "$dirty" >&2 exit 1fi
git_remote() { if [ -n "$SSH_CMD" ]; then GIT_SSH_COMMAND="$SSH_CMD" git "$@" else git "$@" fi}
"$ROOT/tools/site-build.sh"
if [ ! -f "$DIST/index.html" ]; then echo "site-deploy: missing $DIST/index.html after build" >&2 exit 1fiif ! grep -Fq "<meta name=\"misaligned-source-revision\" content=\"$SOURCE_REVISION\">" "$DIST/index.html"; then echo "site-deploy: homepage is missing source revision $SOURCE_REVISION" >&2 exit 1fi
TMP="$(mktemp -d "${TMPDIR:-/tmp}/misaligned-pages.XXXXXX")"cleanup() { rm -rf "$TMP"; }trap cleanup EXIT
# Orphan commit: only the built site, no history from main.git -C "$TMP" init -q -b "$BRANCH"# Copy dist contents (including hidden files like .nojekyll if present).cp -a "$DIST"/. "$TMP"/git -C "$TMP" add -ANEW_TREE="$(git -C "$TMP" write-tree)"
if ! REMOTE_URL="$(git -C "$ROOT" remote get-url "$REMOTE")"; then echo "site-deploy: missing remote url for '$REMOTE'" >&2 exit 1fi
if ls_remote_output="$(git_remote -C "$ROOT" ls-remote --exit-code --heads "$REMOTE_URL" "$BRANCH" 2>&1)"; then git -C "$TMP" remote add "$TMP_REMOTE" "$REMOTE_URL" git_remote -C "$TMP" fetch --depth=1 "$TMP_REMOTE" "$BRANCH" REMOTE_TREE="$(git -C "$TMP" rev-parse "refs/remotes/$TMP_REMOTE/$BRANCH^{tree}")"
if [ "$NEW_TREE" = "$REMOTE_TREE" ]; then echo "site-deploy: public-site content is current on $REMOTE/$BRANCH" echo "site-deploy: nothing to publish" exit 0 fielse ls_remote_status=$? if [ "$ls_remote_status" -eq 2 ]; then echo "site-deploy: missing remote pages branch $REMOTE/$BRANCH, initial publish" else printf '%s\n' "$ls_remote_output" >&2 echo "site-deploy: failed to inspect $REMOTE/$BRANCH" >&2 exit "$ls_remote_status" fifi
git -C "$TMP" \ -c user.name="$(git -C "$ROOT" config user.name || echo misaligned-site)" \ -c user.email="$(git -C "$ROOT" config user.email || echo site@misaligned.local)" \ commit -q -m "Publish Starlight wiki site from ${SOURCE_REVISION:0:12}"
# Reuse the repo's SSH command so Tangled auth matches main pushes and reads.echo "site-deploy: force-pushing orphan $BRANCH → $REMOTE ($REMOTE_URL)"git_remote -C "$TMP" push --force "$REMOTE_URL" "HEAD:refs/heads/$BRANCH"
echo "site-deploy: OK. Configure Tangled Settings → Sites:"echo " branch=$BRANCH deploy directory=/ (sub-path site)"echo " source=$SOURCE_REVISION"