Read-only mirror of github.com/ondeinference/ed.
Mirrored from https://github.com/ondeinference/ed.git
Synced Nov 23, 01:00 UTC
| 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" "$stage/badges" |
| 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/badges/app-store.svg www/badges/google-play.png "$stage/badges/" |
| 37 | cp www/pkg/web_chat.js www/pkg/web_chat_bg.wasm "$stage/pkg/" |
| 38 | printf '%s\n' "$version" > "$stage/version.txt" |
| 39 | # Config only: the CLI reads it and leaves it out of the upload. |
| 40 | cp -R .smb "$stage/.smb" |
| 41 | |
| 42 | echo "version: $version" |
| 43 | echo "app: $app_id" |
| 44 | echo "cli: $(smb --version 2>&1)" |
| 45 | |
| 46 | if [ "${1:-}" = "--dry-run" ]; then |
| 47 | (cd "$stage" && smb --ci deploy --prebuilt --dry-run) |
| 48 | exit 0 |
| 49 | fi |
| 50 | |
| 51 | (cd "$stage" && smb --ci deploy --prebuilt) |
| 52 | |
| 53 | echo "waiting for $URL/version.txt to report $version" |
| 54 | for _ in $(seq 15); do |
| 55 | live="$(curl -fsS --max-time 5 -H 'Cache-Control: no-cache' "$URL/version.txt" 2>/dev/null | tr -d '[:space:]' || true)" |
| 56 | if [ "$live" = "$version" ]; then |
| 57 | echo "live: $URL serves $version" |
| 58 | exit 0 |
| 59 | fi |
| 60 | sleep 2 |
| 61 | done |
| 62 | echo "$URL did not report $version within 30s (last saw: ${live:-nothing})" >&2 |
| 63 | exit 1 |