experiments in a post-browser web
at main 94 lines 3.0 kB view raw
1#!/bin/bash 2# Deploy server to Railway by updating the deploy/server branch 3# with backend/server/ contents at the root. 4# 5# Railway uses npm (not yarn). The deploy branch must not contain 6# yarn.lock, otherwise Nixpacks will use yarn and fail. 7set -e 8 9# Find the jj repo root (where .git lives) 10REPO_ROOT="$(jj workspace root)" 11DIR="$REPO_ROOT" 12while [ ! -d "$DIR/.git" ] && [ "$DIR" != "/" ]; do 13 DIR="$(dirname "$DIR")" 14done 15 16if [ ! -d "$DIR/.git" ]; then 17 echo "Error: could not find .git directory" >&2 18 exit 1 19fi 20 21cd "$DIR" 22 23echo "=== Server Deploy ===" 24echo "" 25 26# Auto-commit any pending jj changes 27if [ -n "$(jj diff --stat 2>/dev/null)" ]; then 28 echo ">>> Auto-committing pending changes..." 29 jj commit -m "chore: auto-commit for deploy" 30fi 31 32# Sync jj state to git and ensure git main matches jj main 33echo ">>> Syncing jj → git..." 34jj git export 35MAIN_COMMIT=$(jj log -r main --no-graph -T 'commit_id' 2>/dev/null) 36git branch -f main "$MAIN_COMMIT" 2>/dev/null || true 37 38# Show what we're deploying 39echo "" 40echo ">>> Deploying from main:" 41jj log -r main --no-graph -T 'commit_id.short(12) ++ " " ++ description.first_line()' 2>/dev/null 42echo "" 43 44# Show recent commits that touched server 45echo ">>> Recent commits touching backend/server/:" 46jj log -r 'ancestors(main, 10)' --no-graph -T 'change_id.short(8) ++ " " ++ description.first_line() ++ "\n"' -- backend/server/ 2>/dev/null | head -5 47echo "" 48 49# Ensure deploy/server branch exists 50if ! git rev-parse --verify deploy/server &>/dev/null; then 51 echo "Creating deploy/server branch..." 52 git checkout --orphan deploy/server 53 git rm -rf . 2>/dev/null || true 54 git commit --allow-empty -m "Initial deploy/server branch" 55 git checkout main 56fi 57 58# Create temp worktree for deploy branch 59DEPLOY_DIR=$(mktemp -d) 60trap "rm -rf $DEPLOY_DIR; git worktree remove $DEPLOY_DIR --force 2>/dev/null || true; git worktree prune 2>/dev/null || true" EXIT 61 62# Clean any stale worktrees first 63git worktree prune 2>/dev/null || true 64 65git worktree add "$DEPLOY_DIR" deploy/server 66 67# Use jj to get the actual files (avoids git working tree sync issues) 68echo "Syncing backend/server/ to deploy branch..." 69rm -rf "$DEPLOY_DIR"/* 2>/dev/null || true 70jj file list -r main -- backend/server/ | while read f; do 71 REL="${f#backend/server/}" 72 [ "$REL" = "yarn.lock" ] && continue 73 mkdir -p "$DEPLOY_DIR/$(dirname "$REL")" 74 jj file show "$f" -r main > "$DEPLOY_DIR/$REL" 75done 76 77# Commit and push if there are changes 78cd "$DEPLOY_DIR" 79if [ -n "$(git status --porcelain)" ]; then 80 git add -A 81 git commit -m "deploy: $(date -u +%Y-%m-%dT%H:%M:%SZ)" 82 echo "" 83 echo ">>> Deployed changes:" 84 git log -1 --stat --oneline 85 echo "" 86else 87 echo ">>> No changes to deploy" 88fi 89 90# Push to GitHub 91git push github deploy/server --force-with-lease 2>/dev/null || git push github deploy/server -f 92echo "" 93echo ">>> Pushed deploy/server branch to GitHub" 94echo ">>> Railway will auto-deploy from: https://github.com/autonome/peek/tree/deploy/server"