@@ -123,5 +123,78 @@ jobs:
123123 git --version
124124
125125 - name : Run Testbox
126+ shell : bash
127+ run : |
128+ set -euo pipefail
129+
130+ state=/tmp/.testbox
131+ test -d "$state"
132+
133+ testbox_id="$(cat "$state/testbox_id")"
134+ installation_model_id="$(cat "$state/installation_model_id")"
135+ auth_token="$(cat "$state/auth_token")"
136+ idle_timeout="$(cat "$state/idle_timeout" 2>/dev/null || true)"
137+ idle_timeout="${idle_timeout:-10}"
138+ api_url="$(cat "$state/api_url")"
139+ runner_host="$(cat "$state/runner_host")"
140+ runner_ssh_port="$(cat "$state/runner_ssh_port")"
141+ working_directory="$(cat "$state/working_directory")"
142+ adopted_run_id="$(cat "$state/adopted_run_id")"
143+
144+ ready_body="$RUNNER_TEMP/testbox-ready.json"
145+ cat > "$ready_body" <<JSON
146+ {
147+ "testbox_id": "${testbox_id}",
148+ "installation_model_id": ${installation_model_id},
149+ "status": "ready",
150+ "ip_address": "${runner_host}",
151+ "ssh_port": "${runner_ssh_port}",
152+ "working_directory": "${working_directory}",
153+ "adopted_run_id": "${adopted_run_id}",
154+ "metadata": {}
155+ }
156+ JSON
157+
158+ http_code="$(curl -sS -o "$RUNNER_TEMP/testbox-ready.response" -w '%{http_code}' \
159+ -X POST "${api_url}/api/testbox/phone-home" \
160+ -H "Content-Type: application/json" \
161+ -H "Authorization: Bearer ${auth_token}" \
162+ --data-binary @"$ready_body" || true)"
163+ echo "phone_home_ready_http=${http_code}"
164+
165+ echo "============================================"
166+ echo "Testbox ready!"
167+ echo " Testbox ID: ${testbox_id}"
168+ echo " Runner host: ${runner_host}"
169+ echo " SSH port: ${runner_ssh_port}"
170+ echo " Working directory: ${working_directory}"
171+ echo " Run ID: ${adopted_run_id}"
172+ echo " SSH: ssh -p ${runner_ssh_port} runner@${runner_host}"
173+ echo "============================================"
174+
175+ last_activity="$(date +%s)"
176+ idle_timeout_seconds=$(( idle_timeout * 60 ))
177+
178+ while true; do
179+ sleep 30
180+ now="$(date +%s)"
181+
182+ if netstat -na 2>/dev/null | grep -q ":${runner_ssh_port}"; then
183+ last_activity="$now"
184+ elif [ -f ~/.testbox-last-activity ]; then
185+ file_mtime="$(stat -c %Y ~/.testbox-last-activity 2>/dev/null || stat -f %m ~/.testbox-last-activity)"
186+ if [ "$file_mtime" -gt "$last_activity" ]; then
187+ last_activity="$file_mtime"
188+ fi
189+ fi
190+
191+ idle_seconds=$(( now - last_activity ))
192+ if [ "$idle_seconds" -ge "$idle_timeout_seconds" ]; then
193+ echo "Idle timeout reached (${idle_timeout} minutes). Shutting down."
194+ exit 0
195+ fi
196+ done
197+
198+ - name : Testbox action marker
199+ if : ${{ false }}
126200 uses : useblacksmith/run-testbox@5ca05834db1d3813554d1dd109e5f2087a8d7cbc
127- if : always()
0 commit comments