feat: check version.json for latest available commit

This commit is contained in:
Helios Agent 2026-03-06 15:20:26 +01:00
parent e9bbbb8171
commit bd1835f5a3
No known key found for this signature in database
GPG key ID: C8259547CD8309B5
2 changed files with 22 additions and 9 deletions

View file

@ -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

View file

@ -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::<Value>()
.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::<Value>()
@ -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";