pr_01m47d24b0e6n91zwymwxg0vpx/scripts/deploy.sh
| 1 | #!/usr/bin/env bash |
| 2 | # Deploys g1t: every part, or the ones named, in the order they depend on |
| 3 | # each other. Each part's D1 migrations are applied before its code goes |
| 4 | # out, so new code never meets an old database. |
| 5 | # |
| 6 | # scripts/deploy.sh # everything |
| 7 | # scripts/deploy.sh billing web # just these, still in order |
| 8 | # |
| 9 | # Uses your `wrangler login`. The repository's .env may hold a token for |
| 10 | # other tools; it is ignored here unless you set CLOUDFLARE_DEPLOY_TOKEN. |
| 11 | set -euo pipefail |
| 12 | |
| 13 | ROOT="$(cd "$(dirname "$0")/.." && pwd)" |
| 14 | export CLOUDFLARE_API_TOKEN="${CLOUDFLARE_DEPLOY_TOKEN:-}" |
| 15 | |
| 16 | # Dependency order: what others bind to goes first. |
| 17 | ORDER=( |
| 18 | services/events |
| 19 | services/identity |
| 20 | services/repos |
| 21 | services/work |
| 22 | services/projects |
| 23 | services/billing |
| 24 | services/integrations |
| 25 | services/webhooks |
| 26 | services/actions |
| 27 | services/models |
| 28 | services/deployments |
| 29 | services/runner |
| 30 | apps/api |
| 31 | services/pages |
| 32 | apps/web |
| 33 | apps/sudo |
| 34 | apps/docs |
| 35 | ) |
| 36 | |
| 37 | wanted() { |
| 38 | [ $# -eq 0 ] && return 0 |
| 39 | local dir="$1"; shift |
| 40 | for name in "${PICK[@]}"; do |
| 41 | [ "$dir" = "$name" ] || [ "$(basename "$dir")" = "$name" ] && return 0 |
| 42 | done |
| 43 | return 1 |
| 44 | } |
| 45 | |
| 46 | PICK=("$@") |
| 47 | for dir in "${ORDER[@]}"; do |
| 48 | [ ${#PICK[@]} -eq 0 ] || wanted "$dir" || continue |
| 49 | echo "== $dir" |
| 50 | cd "$ROOT/$dir" |
| 51 | db=$(grep -o '"database_name": *"[^"]*"' wrangler.jsonc 2>/dev/null | head -1 | sed 's/.*"\([^"]*\)"$/\1/' || true) |
| 52 | if [ -n "$db" ] && [ -d migrations ]; then |
| 53 | npx wrangler d1 migrations apply "$db" --remote |
| 54 | fi |
| 55 | if grep -q '"deploy": "[^"]*build' package.json 2>/dev/null; then |
| 56 | npm run deploy |
| 57 | else |
| 58 | npx wrangler deploy |
| 59 | fi |
| 60 | done |
| 61 | echo "== Deployed." |