ci: keep Windows Blacksmith testbox ready

This commit is contained in:
Vincent Koc
2026-05-03 22:13:00 -07:00
parent 20ade148be
commit 18db16471b

View File

@@ -123,5 +123,78 @@ jobs:
git --version
- name: Run Testbox
shell: bash
run: |
set -euo pipefail
state=/tmp/.testbox
test -d "$state"
testbox_id="$(cat "$state/testbox_id")"
installation_model_id="$(cat "$state/installation_model_id")"
auth_token="$(cat "$state/auth_token")"
idle_timeout="$(cat "$state/idle_timeout" 2>/dev/null || true)"
idle_timeout="${idle_timeout:-10}"
api_url="$(cat "$state/api_url")"
runner_host="$(cat "$state/runner_host")"
runner_ssh_port="$(cat "$state/runner_ssh_port")"
working_directory="$(cat "$state/working_directory")"
adopted_run_id="$(cat "$state/adopted_run_id")"
ready_body="$RUNNER_TEMP/testbox-ready.json"
cat > "$ready_body" <<JSON
{
"testbox_id": "${testbox_id}",
"installation_model_id": ${installation_model_id},
"status": "ready",
"ip_address": "${runner_host}",
"ssh_port": "${runner_ssh_port}",
"working_directory": "${working_directory}",
"adopted_run_id": "${adopted_run_id}",
"metadata": {}
}
JSON
http_code="$(curl -sS -o "$RUNNER_TEMP/testbox-ready.response" -w '%{http_code}' \
-X POST "${api_url}/api/testbox/phone-home" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${auth_token}" \
--data-binary @"$ready_body" || true)"
echo "phone_home_ready_http=${http_code}"
echo "============================================"
echo "Testbox ready!"
echo " Testbox ID: ${testbox_id}"
echo " Runner host: ${runner_host}"
echo " SSH port: ${runner_ssh_port}"
echo " Working directory: ${working_directory}"
echo " Run ID: ${adopted_run_id}"
echo " SSH: ssh -p ${runner_ssh_port} runner@${runner_host}"
echo "============================================"
last_activity="$(date +%s)"
idle_timeout_seconds=$(( idle_timeout * 60 ))
while true; do
sleep 30
now="$(date +%s)"
if netstat -na 2>/dev/null | grep -q ":${runner_ssh_port}"; then
last_activity="$now"
elif [ -f ~/.testbox-last-activity ]; then
file_mtime="$(stat -c %Y ~/.testbox-last-activity 2>/dev/null || stat -f %m ~/.testbox-last-activity)"
if [ "$file_mtime" -gt "$last_activity" ]; then
last_activity="$file_mtime"
fi
fi
idle_seconds=$(( now - last_activity ))
if [ "$idle_seconds" -ge "$idle_timeout_seconds" ]; then
echo "Idle timeout reached (${idle_timeout} minutes). Shutting down."
exit 0
fi
done
- name: Testbox action marker
if: ${{ false }}
uses: useblacksmith/run-testbox@5ca05834db1d3813554d1dd109e5f2087a8d7cbc
if: always()