-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·114 lines (97 loc) · 4.3 KB
/
deploy.sh
File metadata and controls
executable file
·114 lines (97 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env bash
# deploy.sh — Build & deploy NoticeForge - Road Reporter to Netlify
#
# Usage:
# ./deploy.sh → draft deploy (unique URL per deploy, permanent)
# ./deploy.sh --prod → also update the stable production URL
# ./deploy.sh --skip-data → skip NYSDOT RIS fetch (use cached data)
# ./deploy.sh --smoke → run post-deploy smoke tests after deploying
#
# Uses the locally-installed netlify-cli (frontend/node_modules/.bin/netlify)
# so no interactive "Ok to proceed?" prompts from npx.
#
# First run: netlify login is required once — run:
# frontend/node_modules/.bin/netlify login
#
# The site ID is stored in .netlify/state.json (gitignored).
set -euo pipefail
PROD_FLAG=""
SKIP_DATA=false
RUN_SMOKE=false
for arg in "$@"; do
[[ "$arg" == "--prod" ]] && PROD_FLAG="--prod"
[[ "$arg" == "--skip-data" ]] && SKIP_DATA=true
[[ "$arg" == "--smoke" ]] && RUN_SMOKE=true
done
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
NETLIFY="$ROOT/frontend/node_modules/.bin/netlify"
if [[ ! -x "$NETLIFY" ]]; then
echo "ERROR: netlify-cli not found at $NETLIFY"
echo "Run: cd frontend && npm install"
exit 1
fi
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " NoticeForge — Road Reporter — deploy to Netlify"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# ── Step 0: Unit tests ────────────────────────────────────────────────────────
echo ""
echo "▶ 0/4 Running unit tests…"
cd "$ROOT/frontend"
node_modules/.bin/vitest run --reporter=verbose
cd "$ROOT"
# ── Step 1: Fetch fresh road data from NYSDOT RIS ────────────────────────────
if [[ "$SKIP_DATA" == false ]]; then
echo ""
echo "▶ 1/4 Fetching road data from NYSDOT RIS…"
node "$ROOT/demo/build_demo_geojson.js"
else
echo ""
echo "▶ 1/4 Skipping data fetch (--skip-data)."
fi
# ── Step 2: Vite production build ────────────────────────────────────────────
echo ""
echo "▶ 2/4 Building frontend…"
cd "$ROOT/frontend"
VITE_DEMO_MODE=true node_modules/.bin/vite build
cd "$ROOT"
# ── Step 3: Deploy to Netlify ────────────────────────────────────────────────
echo ""
echo "▶ 3/4 Deploying to Netlify…"
cd "$ROOT"
DEPLOY_OUTPUT=$("$NETLIFY" deploy \
--dir=frontend/dist \
--message="NoticeForge $(date +%Y-%m-%d)" \
$PROD_FLAG 2>&1)
echo "$DEPLOY_OUTPUT"
# Extract the deploy URL for smoke tests
# Netlify output varies: "Website URL:", "Website Draft URL:", "Deployed to production URL:", etc.
DEPLOY_URL=$(echo "$DEPLOY_OUTPUT" | grep -oE 'https://[a-zA-Z0-9-]+\.netlify\.app' | tail -1)
# ── Step 4: Post-deploy smoke tests ──────────────────────────────────────────
if [[ "$RUN_SMOKE" == true && -n "$DEPLOY_URL" ]]; then
echo ""
echo "▶ 4/4 Running smoke tests against $DEPLOY_URL …"
cd "$ROOT/frontend"
SMOKE_URL="$DEPLOY_URL" node_modules/.bin/vitest run tests/smoke.test.ts --reporter=verbose
cd "$ROOT"
else
echo ""
echo "▶ 4/4 Smoke tests skipped. Pass --smoke to run them after deploy."
fi
echo ""
echo "✅ Done."
# Print build manifest summary if available
META_FILE="$ROOT/frontend/public/data/build_meta.json"
if [[ -f "$META_FILE" ]]; then
echo ""
echo "Build manifest:"
node -e '
const m = require(process.argv[1]);
console.log(" Region: " + (m.region || "unknown"));
console.log(" Counties: " + (m.counties || []).map(c => c.name + " (" + c.segments + ")").join(", "));
console.log(" Total roads: " + (m.counts?.roads || "?"));
console.log(" Markers: " + (m.counts?.markers || "?"));
console.log(" Municipalities: " + (m.counts?.municipalities || "?"));
console.log(" Generated at: " + (m.generated_at || "?"));
' "$META_FILE"
fi