forked from WikiDeck/wikideck
41 lines
2.2 KiB
Bash
Executable File
41 lines
2.2 KiB
Bash
Executable File
#!/bin/sh
|
|
# sim-testnet: keep the wikideck-night testnet on the integration branch head.
|
|
# Run from the root of a *dedicated* checkout (e.g. a detached git worktree): it checks out
|
|
# each new head of $BRANCH and runs `deploy/night/testnet.sh rolling` (ledgers persist in the volumes):
|
|
# nodes restart one at a time, and deploys wait (up to FORCE_AFTER) while matches or lobbies are live,
|
|
# because lobbies are in memory and a restart ends games in progress.
|
|
# Head detection uses the public Gitea API, which also works where SSH auth isn't available.
|
|
set -u
|
|
BRANCH=${BRANCH:-night/2026-11-16}
|
|
API=${API:-https://gitea.eom.dev/api/v1/repos/claude/wikideck}
|
|
INTERVAL=${INTERVAL:-180}
|
|
LOG=${LOG:-/tmp/wikideck-night-autodeploy.log}
|
|
FORCE_AFTER=${FORCE_AFTER:-900} # defer while matches/lobbies are live, but at most this many seconds
|
|
deferred_since=
|
|
enc=$(printf %s "$BRANCH" | sed 's#/#%2F#g')
|
|
while :; do
|
|
new=$(node -e "fetch('$API/branches/$enc',{signal:AbortSignal.timeout(15000)}).then(r=>r.json()).then(b=>console.log(b.commit.id)).catch(()=>{})")
|
|
cur=$(git rev-parse HEAD)
|
|
if [ -z "$new" ]; then echo "WARN branch API failed"
|
|
elif [ "$new" != "$cur" ]; then
|
|
if ! git fetch -q origin "+refs/heads/$BRANCH:refs/remotes/origin/$BRANCH" 2>"$LOG"; then
|
|
echo "WARN fetch failed: $(tail -1 "$LOG")"
|
|
else
|
|
busy=$(deploy/night/testnet.sh busy 2>/dev/null || echo 0)
|
|
now=$(date +%s)
|
|
if [ "${busy:-0}" -gt 0 ] && { [ -z "$deferred_since" ] || [ $((now - deferred_since)) -lt "$FORCE_AFTER" ]; }; then
|
|
[ -z "$deferred_since" ] && { deferred_since=$now; echo "DEFER ${new%"${new#???????}"}: $busy live matches/lobbies"; }
|
|
sleep 60; continue
|
|
fi
|
|
[ -n "$deferred_since" ] && [ "${busy:-0}" -gt 0 ] && echo "FORCE deploy after ${FORCE_AFTER}s ($busy still live)"
|
|
deferred_since=
|
|
git checkout -q --detach "$new"
|
|
echo "DEPLOY start $(git log --oneline -1 | cut -c1-90)"
|
|
if deploy/night/testnet.sh rolling >"$LOG" 2>&1; then
|
|
sleep 20; echo "DEPLOY ok $(git rev-parse --short HEAD): $(deploy/night/testnet.sh status 2>&1 | tr '\n' ' ')"
|
|
else echo "DEPLOY FAILED $(git rev-parse --short HEAD): $(tail -3 "$LOG" | tr '\n' ' ')"; fi
|
|
fi
|
|
fi
|
|
sleep "$INTERVAL"
|
|
done
|