clone

an rts arena for scripts: submit tribe strategies over the web or mcp, run deterministic matches, watch them

main
tribes / scripts / release.sh
release.sh 2.4K executable
1#!/usr/bin/env bash2# Release a prod version: scripts/release.sh v1.2.33#4# Deploys the current tree to:5# 1. v1-2-3.tribes.pub — immutable versioned host (worker "tribes-v1-2-3")6# 2. tribes.pub — apex, always the latest release (worker "tribes-prod")7# Both bind the SHARED tribes-prod D1 and the same session cookie domain, so8# accounts and sims carry across versions. Versioned hosts use dashes because9# the universal wildcard cert only covers one subdomain label.10#11# First-time setup per new versioned worker: SESSION_SECRET must exist. Export12# TRIBES_SESSION_SECRET (same value as tribes-prod's secret) and this script13# pushes it; otherwise set it manually with:14# npx wrangler secret put SESSION_SECRET --name tribes-v1-2-315set -euo pipefail16cd "$(dirname "$0")/.."1718VERSION="${1:?usage: scripts/release.sh vX.Y.Z}"19[[ "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "version must look like v1.2.3" >&2; exit 1; }20SLUG="${VERSION//./-}" # v1.2.3 -> v1-2-321HOST="${SLUG}.tribes.pub"22WORKER="tribes-${SLUG}"2324echo "==> building"25npm run build2627echo "==> migrating tribes-prod D1"28npx wrangler d1 migrations apply tribes-prod --env prod --remote2930echo "==> generating release config for ${WORKER} (${HOST})"31node - "$WORKER" "$HOST" <<'EOF'32const fs = require('fs');33const [worker, host] = process.argv.slice(2);34// Strip // comments (JSONC) conservatively, then rewrite the prod env.35const raw = fs.readFileSync('wrangler.jsonc', 'utf8').replace(/^\s*\/\/.*$/gm, '');36const cfg = JSON.parse(raw);37const prod = cfg.env.prod;38const release = {39 ...cfg,40 name: worker,41 routes: [{ pattern: host, custom_domain: true }],42 d1_databases: prod.d1_databases,43 r2_buckets: prod.r2_buckets, // NEVER inherit the top-level (dev) bucket44 limits: prod.limits,45 triggers: prod.triggers,46 vars: prod.vars,47 env: undefined,48};49fs.writeFileSync('.wrangler-release.json', JSON.stringify(release, null, 2));50EOF5152echo "==> deploying ${WORKER} -> https://${HOST}"53npx wrangler deploy -c .wrangler-release.json54if [[ -n "${TRIBES_SESSION_SECRET:-}" ]]; then55 printf '%s' "$TRIBES_SESSION_SECRET" | npx wrangler secret put SESSION_SECRET --name "$WORKER"56fi57rm -f .wrangler-release.json5859echo "==> deploying apex tribes-prod -> https://tribes.pub"60npx wrangler deploy --env prod6162echo "==> tagging ${VERSION}"63git tag -f "$VERSION"64echo "done: https://${HOST} and https://tribes.pub are live. Push the tag with: git push origin ${VERSION}"