From bd1835f5a3398ef238724a5a4339d25d907496ea Mon Sep 17 00:00:00 2001 From: Helios Agent Date: Fri, 6 Mar 2026 15:20:26 +0100 Subject: [PATCH] feat: check version.json for latest available commit --- .github/workflows/ci.yml | 4 ++++ crates/cli/src/main.rs | 27 ++++++++++++++++++--------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5661813..bdcd514 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -124,6 +124,10 @@ jobs: scp -i ~/.ssh/deploy_key \ target/x86_64-unknown-linux-gnu/release/helios-remote-relay \ root@46.225.185.232:/var/www/helios-remote/helios-remote-relay-linux + # Write version.json so CLI knows what's available + echo "{\"commit\":\"$(git rev-parse --short HEAD)\"}" > version.json + scp -i ~/.ssh/deploy_key version.json \ + root@46.225.185.232:/var/www/helios-remote/version.json build-cli: runs-on: ubuntu-latest diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 5da1872..17ad146 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -722,7 +722,17 @@ fn main() { Commands::Update { device } => { validate_label(&device); - // Fetch all three commits + // Fetch latest available commit from version.json + let latest_commit = match reqwest::blocking::get("https://agent-helios.me/downloads/helios-remote/version.json") { + Ok(r) => r + .json::() + .ok() + .and_then(|v| v["commit"].as_str().map(String::from)) + .unwrap_or_else(|| "?".into()), + Err(e) => format!("error: {}", e), + }; + + // Fetch all three running commits let relay_commit = match reqwest::blocking::get(&format!("{}/version", cfg.base_url)) { Ok(r) => r .json::() @@ -739,13 +749,14 @@ fn main() { let cli_commit = GIT_COMMIT; + println!(" latest {}", latest_commit); println!(" relay {}", relay_commit); println!(" cli {}", cli_commit); println!(" client {}", client_commit); - let all_same = relay_commit == cli_commit && cli_commit == client_commit; - if all_same { - println!(" ✅ Already up to date (commit: {})", cli_commit); + let all_current = relay_commit == latest_commit && cli_commit == latest_commit && client_commit == latest_commit; + if all_current { + println!(" ✅ Already up to date (commit: {})", latest_commit); return; } @@ -753,7 +764,7 @@ fn main() { let mut updated_any = false; // Update relay if needed - if relay_commit != cli_commit { + if relay_commit != latest_commit { println!(" → Updating relay..."); let data = req(&cfg, "POST", "/relay/update", None, 15); println!(" {}", data["message"].as_str().unwrap_or("triggered")); @@ -761,7 +772,7 @@ fn main() { } // Update client if needed - if client_commit != cli_commit { + if client_commit != latest_commit { println!(" → Updating client on {}...", device); let data = req( &cfg, @@ -780,9 +791,7 @@ fn main() { } // Self-update CLI if needed - // (relay_commit is the "canonical" latest — if we differ from it, we're outdated) - // Skip on non-x86_64 Linux (e.g. ARM/Pi) — CI only builds x86_64 Linux binaries - if cli_commit != relay_commit { + if cli_commit != latest_commit { println!(" → Updating CLI..."); #[cfg(target_os = "windows")] let url = "https://agent-helios.me/downloads/helios-remote/helios-remote-cli-windows.exe";