@ondeinference / ed Mirror · read-only
Fork 0

Read-only mirror of github.com/ondeinference/ed.

Mirrored from https://github.com/ondeinference/ed.git

Synced Nov 23, 01:00 UTC

main
sh 62 lines 2.26 KB
Raw
1 #!/usr/bin/env bash
2 # Publish www/ to https://ondewebdemo.5mb.app with the smbCloud CLI (smb >= 1.1.0).
3 #
4 # ./deploy.sh --dry-run stage and list the files; uploads nothing
5 # ./deploy.sh stage, deploy, then check /version.txt
6 #
7 # Run ./build.sh first: this ships whatever is in www/pkg. Auth is the token
8 # from `smb login`, or SMB_TOKEN in CI.
9 set -euo pipefail
10 cd "$(dirname "$0")"
11
12 # The App .smb/config.toml must name. A stale config once sent a deploy into
13 # another app's directory, so a mismatch stops here before anything is written.
14 EXPECTED_APP_ID="c0277812-c891-4f4b-a3ee-c8cb371bb629"
15 URL="https://ondewebdemo.5mb.app"
16
17 app_id="$(sed -n 's/^frontend_app_id *= *"\([^"]*\)".*/\1/p' .smb/config.toml | head -n 1)"
18 if [ "$app_id" != "$EXPECTED_APP_ID" ]; then
19 echo "refusing to deploy: .smb/config.toml says frontend_app_id ${app_id:-?}, expected $EXPECTED_APP_ID" >&2
20 exit 1
21 fi
22
23 for f in www/pkg/web_chat.js www/pkg/web_chat_bg.wasm; do
24 [ -f "$f" ] || { echo "missing $f; run ./build.sh first" >&2; exit 1; }
25 done
26
27 version="$(git rev-parse --short HEAD)"
28 git diff --quiet HEAD -- . || version="$version-dirty"
29
30 # Only the servable files. www/pkg also holds a README, package.json and
31 # .gitignore from wasm-pack that have no place on the site.
32 stage="$(mktemp -d)"
33 trap 'rm -rf "$stage"' EXIT
34 mkdir "$stage/pkg"
35 cp www/index.html www/main.js www/worker.js www/style.css www/favicon.svg www/apple-touch-icon.png "$stage/"
36 cp www/pkg/web_chat.js www/pkg/web_chat_bg.wasm "$stage/pkg/"
37 printf '%s\n' "$version" > "$stage/version.txt"
38 # Config only: the CLI reads it and leaves it out of the upload.
39 cp -R .smb "$stage/.smb"
40
41 echo "version: $version"
42 echo "app: $app_id"
43 echo "cli: $(smb --version 2>&1)"
44
45 if [ "${1:-}" = "--dry-run" ]; then
46 (cd "$stage" && smb --ci deploy --prebuilt --dry-run)
47 exit 0
48 fi
49
50 (cd "$stage" && smb --ci deploy --prebuilt)
51
52 echo "waiting for $URL/version.txt to report $version"
53 for _ in $(seq 15); do
54 live="$(curl -fsS --max-time 5 -H 'Cache-Control: no-cache' "$URL/version.txt" 2>/dev/null | tr -d '[:space:]' || true)"
55 if [ "$live" = "$version" ]; then
56 echo "live: $URL serves $version"
57 exit 0
58 fi
59 sleep 2
60 done
61 echo "$URL did not report $version within 30s (last saw: ${live:-nothing})" >&2
62 exit 1