#!/usr/bin/env bash # Publish a built static site to Codeberg Pages. # # One codebase, three real domains (atproto.nl/.be/.eu). SITE_SCOPE picks which one this run # builds and which Codeberg repo it pushes to; each domain is a standalone Codeberg Pages repo # with its own `pages` branch. Home base stays Tangled; Codeberg is only the delivery layer. # # The custom domain is claimed by dist/.domains, which astro.config.mjs writes from the scope at # build time -- so this script never has to know the hostname, only which remote to push. # # Usage: # SITE_SCOPE=nl bash scripts/deploy-codeberg.sh # -> remote `codeberg` (atproto.nl) # SITE_SCOPE=be bash scripts/deploy-codeberg.sh # -> remote `codeberg-be` (atproto.be) # SITE_SCOPE=eu bash scripts/deploy-codeberg.sh # -> remote `codeberg-eu` (atproto.eu) # Deploy all three: for s in nl be eu; do SITE_SCOPE=$s bash scripts/deploy-codeberg.sh; done # # Prereqs (per scope): a Codeberg remote over ssh (auth via ~/.ssh/id_ed25519_codeberg), e.g. # git remote add codeberg-be codeberg.org:gxjansen/atprotobe-website.git # git remote add codeberg-eu codeberg.org:gxjansen/atprotoeu-website.git # and rsync available. The `_git-pages-repository.` TXT record must point at the same repo. set -euo pipefail SCOPE="${SITE_SCOPE:-nl}" # Remote naming: nl uses `codeberg`, every other scope uses `codeberg-`. Derived (not a # hardcoded case) so a new scope in scopes.ts needs no edit here; if the remote is missing the check # below prints the exact `git remote add`. Validate against the source-of-truth scope list. if ! node "$(dirname "$0")/gen-scopes.mjs" --list | tr ' ' '\n' | grep -qx "$SCOPE"; then echo "Unknown SITE_SCOPE='$SCOPE' (not in src/config/scopes.ts). Valid: $(node "$(dirname "$0")/gen-scopes.mjs" --list)" >&2 exit 1 fi if [ "$SCOPE" = "nl" ]; then DEFAULT_REMOTE="codeberg"; else DEFAULT_REMOTE="codeberg-$SCOPE"; fi # CODEBERG_REMOTE still overrides for one-off targets (e.g. a preview repo). REMOTE="${CODEBERG_REMOTE:-$DEFAULT_REMOTE}" BRANCH="${CODEBERG_PAGES_BRANCH:-pages}" export SITE_SCOPE="$SCOPE" if ! git remote get-url "$REMOTE" >/dev/null 2>&1; then echo "Git remote '$REMOTE' not found. Add it, e.g.:" >&2 echo " git remote add $REMOTE codeberg.org:gxjansen/atproto${SCOPE}-website.git" >&2 exit 1 fi # Default base '/' — serve at the apex domain. For the codeberg.page// preview subpath: # SITE_BASE=/atproto${SCOPE}-website/ SITE_SCOPE=$SCOPE bash scripts/deploy-codeberg.sh export SITE_BASE="${SITE_BASE:-/}" echo "==> Building scope=$SCOPE (base=$SITE_BASE) -> remote $REMOTE" npm run build WT="$(mktemp -d)" cleanup() { git worktree remove --force "$WT" 2>/dev/null || true; } trap cleanup EXIT echo "==> Preparing $REMOTE/$BRANCH worktree" git fetch "$REMOTE" "$BRANCH" 2>/dev/null || true if git show-ref --verify --quiet "refs/remotes/$REMOTE/$BRANCH"; then git worktree add -B "$BRANCH" "$WT" "$REMOTE/$BRANCH" else git worktree add -B "$BRANCH" "$WT" fi echo "==> Syncing dist/ -> $REMOTE/$BRANCH" rsync -a --delete --exclude='.git' dist/ "$WT/" git -C "$WT" add -A if git -C "$WT" diff --cached --quiet; then echo "No changes to deploy." exit 0 fi git -C "$WT" commit -m "deploy $SCOPE $(git rev-parse --short HEAD)" git -C "$WT" push "$REMOTE" "$BRANCH" echo "==> Deployed scope=$SCOPE to Codeberg Pages ($REMOTE/$BRANCH)."