@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
sh 40 lines 1.32 KB
Raw
1 #!/usr/bin/env bash
2 # Times one preview lifecycle: deploy -> URL live -> test -> destroy.
3 # Usage: ALCHEMY_PROFILE=<name> STAGE=<stage> bun run bench
4 # (STAGE defaults to pr-147; the CLI and the test harness both read ALCHEMY_PROFILE)
5 set -euo pipefail
6 cd "$(dirname "$0")/.."
7
8 export STAGE="${STAGE:-pr-147}"
9 unset CI # the test file only destroys on CI; this script destroys explicitly
10 mkdir -p .alchemy/bench
11 log=".alchemy/bench/$(date +%Y%m%d-%H%M%S)"
12
13 now() { date +%s.%N; }
14 elapsed() { awk -v s="$1" -v e="$2" 'BEGIN { printf "%.2fs", e - s }'; }
15
16 t0=$(now)
17 bunx alchemy deploy --stage "$STAGE" --yes >"$log-deploy.log" 2>&1 ||
18 { cat "$log-deploy.log"; exit 1; }
19 t1=$(now)
20 echo "deploy $(elapsed "$t0" "$t1")"
21
22 url=$(grep -oE 'https://[a-z0-9.-]+\.workers\.dev' "$log-deploy.log" | tail -1)
23 for _ in $(seq 1 100); do # at most ~10s
24 [ "$(curl -s -o /dev/null -w '%{http_code}' "$url/photos")" = 200 ] && break
25 sleep 0.1
26 done
27 t2=$(now)
28 echo "url live $(elapsed "$t1" "$t2") $url"
29
30 status=0
31 bun test >"$log-test.log" 2>&1 || { status=$?; cat "$log-test.log"; }
32 t3=$(now)
33 echo "test $(elapsed "$t2" "$t3")"
34
35 bunx alchemy destroy --stage "$STAGE" --yes >"$log-destroy.log" 2>&1 ||
36 { cat "$log-destroy.log"; exit 1; }
37 t4=$(now)
38 echo "destroy $(elapsed "$t3" "$t4")"
39 echo "total $(elapsed "$t0" "$t4") (logs: $log-*.log)"
40 exit "$status"