From 400b7200ba2087eeb96bf613d27920bb118040b3 Mon Sep 17 00:00:00 2001 From: twentyOne2x Date: Fri, 26 Jun 2026 01:19:16 +0200 Subject: [PATCH] Use GitHub remote for VPS auto deploy --- deploy/auto-deploy.sh | 23 ++++++++++++++++++----- tests/test_teleo_agent_systemd.py | 10 ++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/deploy/auto-deploy.sh b/deploy/auto-deploy.sh index 4f27f04..3f25fad 100755 --- a/deploy/auto-deploy.sh +++ b/deploy/auto-deploy.sh @@ -21,18 +21,31 @@ LOG_TAG="auto-deploy" log() { logger -t "$LOG_TAG" "$1"; echo "$(date '+%Y-%m-%d %H:%M:%S') $1"; } +DEPLOY_REMOTE="${TELEO_DEPLOY_REMOTE:-}" +if [ -z "$DEPLOY_REMOTE" ]; then + if git -C "$DEPLOY_CHECKOUT" remote get-url github >/dev/null 2>&1; then + DEPLOY_REMOTE="github" + else + DEPLOY_REMOTE="origin" + fi +fi + if [ ! -d "$DEPLOY_CHECKOUT/.git" ]; then log "ERROR: Deploy checkout not found at $DEPLOY_CHECKOUT. Run setup first." exit 1 fi cd "$DEPLOY_CHECKOUT" -if ! git fetch origin main --quiet 2>&1; then - log "ERROR: git fetch failed" +if ! git remote get-url "$DEPLOY_REMOTE" >/dev/null 2>&1; then + log "ERROR: deploy remote '$DEPLOY_REMOTE' is not configured" + exit 1 +fi +if ! git fetch "$DEPLOY_REMOTE" main --quiet 2>&1; then + log "ERROR: git fetch failed for $DEPLOY_REMOTE/main" exit 1 fi -NEW_SHA=$(git rev-parse origin/main) +NEW_SHA=$(git rev-parse "$DEPLOY_REMOTE/main") OLD_SHA=$(cat "$STAMP_FILE" 2>/dev/null || echo "none") if [ "$NEW_SHA" = "$OLD_SHA" ]; then @@ -45,8 +58,8 @@ if ! git checkout main --quiet 2>&1; then log "ERROR: git checkout main failed — dirty tree or corrupted index" exit 1 fi -if ! git pull --ff-only --quiet 2>&1; then - log "ERROR: git pull --ff-only failed. Manual intervention needed." +if ! git merge --ff-only "$DEPLOY_REMOTE/main" --quiet 2>&1; then + log "ERROR: git merge --ff-only $DEPLOY_REMOTE/main failed. Manual intervention needed." exit 1 fi diff --git a/tests/test_teleo_agent_systemd.py b/tests/test_teleo_agent_systemd.py index 11fe699..588c954 100644 --- a/tests/test_teleo_agent_systemd.py +++ b/tests/test_teleo_agent_systemd.py @@ -18,3 +18,13 @@ def test_deploy_scripts_restart_wallet_test_agent_when_present(): assert "add_restart_if_unit_exists teleo-agent@leo-wallet-test" in auto_deploy assert 'systemctl list-units --all --full "$1.service"' in auto_deploy assert "teleo-agent@leo-wallet-test" in manual_deploy + + +def test_auto_deploy_prefers_github_remote_when_present(): + auto_deploy = (REPO_ROOT / "deploy" / "auto-deploy.sh").read_text() + + assert 'DEPLOY_REMOTE="${TELEO_DEPLOY_REMOTE:-}"' in auto_deploy + assert 'remote get-url github' in auto_deploy + assert 'git fetch "$DEPLOY_REMOTE" main' in auto_deploy + assert 'git rev-parse "$DEPLOY_REMOTE/main"' in auto_deploy + assert 'git merge --ff-only "$DEPLOY_REMOTE/main"' in auto_deploy