pr_01m47d24b0e6n91zwymwxg0vpx/scripts/deploy.sh

59 lines1,616 bytesCodeBlame
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.
11set -euo pipefail
12
13ROOT="$(cd "$(dirname "$0")/.." && pwd)"
14export CLOUDFLARE_API_TOKEN="${CLOUDFLARE_DEPLOY_TOKEN:-}"
15
16# Dependency order: what others bind to goes first.
17ORDER=(
18 services/events
19 services/identity
20 services/repos
21 services/work
22 services/billing
23 services/integrations
24 services/webhooks
25 services/actions
26 services/models
27 services/deployments
28 services/runner
29 apps/api
30 services/pages
31 apps/web
32 apps/docs
33)
34
35wanted() {
36 [ $# -eq 0 ] && return 0
37 local dir="$1"; shift
38 for name in "${PICK[@]}"; do
39 [ "$dir" = "$name" ] || [ "$(basename "$dir")" = "$name" ] && return 0
40 done
41 return 1
42}
43
44PICK=("$@")
45for dir in "${ORDER[@]}"; do
46 [ ${#PICK[@]} -eq 0 ] || wanted "$dir" || continue
47 echo "== $dir"
48 cd "$ROOT/$dir"
49 db=$(grep -o '"database_name": *"[^"]*"' wrangler.jsonc 2>/dev/null | head -1 | sed 's/.*"\([^"]*\)"$/\1/' || true)
50 if [ -n "$db" ] && [ -d migrations ]; then
51 npx wrangler d1 migrations apply "$db" --remote
52 fi
53 if grep -q '"deploy": "[^"]*build' package.json 2>/dev/null; then
54 npm run deploy
55 else
56 npx wrangler deploy
57 fi
58done
59echo "== Deployed."