115 lines
4.2 KiB
Bash
Executable file
115 lines
4.2 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# Read-only readiness check for the disposable Leo Telegram transport.
|
|
# Run on the VPS before resetting auto-deploy or booting teleo-agent@leo-test.
|
|
set -euo pipefail
|
|
|
|
DEPLOY_CHECKOUT="${DEPLOY_CHECKOUT:-/opt/teleo-eval/workspaces/deploy}"
|
|
DEPLOY_INFRA_CHECKOUT="${DEPLOY_INFRA_CHECKOUT:-/opt/teleo-eval/workspaces/deploy-infra}"
|
|
RUNTIME_TELEGRAM_DIR="${RUNTIME_TELEGRAM_DIR:-/opt/teleo-eval/telegram}"
|
|
PIPELINE_TELEGRAM_DIR="${PIPELINE_TELEGRAM_DIR:-/opt/teleo-eval/pipeline/telegram}"
|
|
LEO_TEST_TOKEN_FILE="${LEO_TEST_TOKEN_FILE:-/opt/teleo-eval/secrets/leo-test-telegram-bot-token}"
|
|
EXPECTED_GITHUB_MAIN="${EXPECTED_GITHUB_MAIN:-4cc6a5d06e053d95b3bc64eb359c9d07e2611b0c}"
|
|
EXPECTED_AUTO_DEPLOY_EXEC="${EXPECTED_AUTO_DEPLOY_EXEC:-/opt/teleo-eval/workspaces/deploy-infra/deploy/auto-deploy.sh}"
|
|
FETCH_GITHUB_MAIN="${FETCH_GITHUB_MAIN:-0}"
|
|
|
|
failures=0
|
|
|
|
emit() {
|
|
printf '%s=%s\n' "$1" "$2"
|
|
}
|
|
|
|
pass() {
|
|
emit "$1" "ok"
|
|
}
|
|
|
|
fail() {
|
|
emit "$1" "missing_or_mismatch"
|
|
emit "$1.reason" "$2"
|
|
failures=$((failures + 1))
|
|
}
|
|
|
|
check_file_present() {
|
|
local key="$1"
|
|
local path="$2"
|
|
if [ -f "$path" ]; then
|
|
pass "$key"
|
|
else
|
|
fail "$key" "$path not found"
|
|
fi
|
|
}
|
|
|
|
emit schema livingip.teleo.leoTestDeployReadiness.v1
|
|
emit secret_values_included false
|
|
emit live_service_reset_run false
|
|
emit telegram_or_slack_message_sent false
|
|
emit paid_spend_run false
|
|
|
|
if [ ! -d "$DEPLOY_CHECKOUT/.git" ]; then
|
|
fail deploy_checkout_git "$DEPLOY_CHECKOUT/.git not found"
|
|
else
|
|
pass deploy_checkout_git
|
|
emit deploy_checkout_path "$DEPLOY_CHECKOUT"
|
|
emit deploy_checkout_branch "$(git -C "$DEPLOY_CHECKOUT" rev-parse --abbrev-ref HEAD 2>/dev/null || true)"
|
|
emit deploy_checkout_head "$(git -C "$DEPLOY_CHECKOUT" rev-parse --short HEAD 2>/dev/null || true)"
|
|
emit deploy_checkout_status "$(git -C "$DEPLOY_CHECKOUT" status --short | tr '\n' ';' || true)"
|
|
fi
|
|
|
|
if [ ! -d "$DEPLOY_INFRA_CHECKOUT/.git" ]; then
|
|
fail deploy_infra_git "$DEPLOY_INFRA_CHECKOUT/.git not found"
|
|
else
|
|
pass deploy_infra_git
|
|
emit deploy_infra_path "$DEPLOY_INFRA_CHECKOUT"
|
|
if [ "$FETCH_GITHUB_MAIN" = "1" ]; then
|
|
git -C "$DEPLOY_INFRA_CHECKOUT" fetch github main --quiet 2>/dev/null || true
|
|
emit deploy_infra_fetch_github_main attempted
|
|
else
|
|
emit deploy_infra_fetch_github_main skipped
|
|
fi
|
|
github_main="$(git -C "$DEPLOY_INFRA_CHECKOUT" rev-parse github/main 2>/dev/null || true)"
|
|
emit deploy_infra_github_main "$github_main"
|
|
emit deploy_infra_github_main_required_ancestor "$EXPECTED_GITHUB_MAIN"
|
|
if [ "$github_main" = "$EXPECTED_GITHUB_MAIN" ] || git -C "$DEPLOY_INFRA_CHECKOUT" merge-base --is-ancestor "$EXPECTED_GITHUB_MAIN" github/main 2>/dev/null; then
|
|
pass deploy_infra_github_main_expected
|
|
else
|
|
fail deploy_infra_github_main_expected "expected github/main to equal or descend from $EXPECTED_GITHUB_MAIN, got ${github_main:-none}"
|
|
fi
|
|
|
|
if git -C "$DEPLOY_INFRA_CHECKOUT" cat-file -e github/main:telegram/agents/leo-test.yaml 2>/dev/null; then
|
|
pass deploy_infra_github_main_leo_test_config
|
|
else
|
|
fail deploy_infra_github_main_leo_test_config "github/main lacks telegram/agents/leo-test.yaml"
|
|
fi
|
|
|
|
if git -C "$DEPLOY_INFRA_CHECKOUT" cat-file -e github/main:deploy/auto-deploy.sh 2>/dev/null; then
|
|
pass deploy_infra_github_main_auto_deploy
|
|
else
|
|
fail deploy_infra_github_main_auto_deploy "github/main lacks deploy/auto-deploy.sh"
|
|
fi
|
|
fi
|
|
|
|
actual_exec="$(systemctl cat teleo-auto-deploy.service 2>/dev/null | awk -F= '/^ExecStart=/{print $2; exit}' || true)"
|
|
emit teleo_auto_deploy_exec_start "$actual_exec"
|
|
if [ "$actual_exec" = "$EXPECTED_AUTO_DEPLOY_EXEC" ]; then
|
|
pass teleo_auto_deploy_exec_start_expected
|
|
else
|
|
fail teleo_auto_deploy_exec_start_expected "expected $EXPECTED_AUTO_DEPLOY_EXEC, got ${actual_exec:-none}"
|
|
fi
|
|
|
|
check_file_present runtime_leo_config "$RUNTIME_TELEGRAM_DIR/agents/leo.yaml"
|
|
check_file_present runtime_leo_test_config "$RUNTIME_TELEGRAM_DIR/agents/leo-test.yaml"
|
|
check_file_present pipeline_leo_test_config "$PIPELINE_TELEGRAM_DIR/agents/leo-test.yaml"
|
|
|
|
if [ -f "$LEO_TEST_TOKEN_FILE" ]; then
|
|
pass leo_test_token_file
|
|
else
|
|
fail leo_test_token_file "$LEO_TEST_TOKEN_FILE not found"
|
|
fi
|
|
|
|
if [ "$failures" -eq 0 ]; then
|
|
emit status ready_for_leo_test_validate_and_boot
|
|
else
|
|
emit status blocked
|
|
emit failure_count "$failures"
|
|
fi
|
|
|
|
exit "$failures"
|