flagon-io/g1t

public

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t/scripts/deploy.sh

60 lines1,636 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/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/docs
34)
35
36wanted() {
37 [ $# -eq 0 ] && return 0
38 local dir="$1"; shift
39 for name in "${PICK[@]}"; do
40 [ "$dir" = "$name" ] || [ "$(basename "$dir")" = "$name" ] && return 0
41 done
42 return 1
43}
44
45PICK=("$@")
46for dir in "${ORDER[@]}"; do
47 [ ${#PICK[@]} -eq 0 ] || wanted "$dir" || continue
48 echo "== $dir"
49 cd "$ROOT/$dir"
50 db=$(grep -o '"database_name": *"[^"]*"' wrangler.jsonc 2>/dev/null | head -1 | sed 's/.*"\([^"]*\)"$/\1/' || true)
51 if [ -n "$db" ] && [ -d migrations ]; then
52 npx wrangler d1 migrations apply "$db" --remote
53 fi
54 if grep -q '"deploy": "[^"]*build' package.json 2>/dev/null; then
55 npm run deploy
56 else
57 npx wrangler deploy
58 fi
59done
60echo "== Deployed."