mirror of
https://github.com/clockworklabs/SpacetimeDB.git
synced 2026-06-28 16:58:39 -04:00
5404126aba
## Summary Adds a version update check to the `spacetimedb-update` proxy, so users are notified when a newer version of SpacetimeDB is available. ## Changes Adds `crates/update/src/update_notice.rs` — a lightweight update check that runs in the proxy path before exec'ing the CLI: - **Cache-based**: Stores the last check result in `~/.spacetime/.update_check_cache`. Only hits the network once every 24 hours. - **Non-blocking on cache hit**: If the cache is fresh, it's a single file read — no network, no delay. - **Short timeout**: When the cache is stale, makes a single HTTP request to GitHub releases API with a 5-second timeout. Uses the same `SPACETIME_UPDATE_RELEASES_URL` env var as `spacetime version upgrade`. - **Best-effort**: Any failure (network, parse, file I/O) is silently ignored. The update check never interferes with the user's command. - **Uses semver**: Proper version comparison via the `semver` crate (already a dependency). ## Output When a newer version is available: ``` A new version of SpacetimeDB is available: v2.1.0 (current: v2.0.0) Run `spacetime version upgrade` to update. ``` # Testing - [x] I get a warning if my local version is less than 2.0.2 - [x] If I have a cached update check, I get the same error even if I have no network connection - [x] if the cache is old, the next command checks again - [x] if I'm not connected and the cache is stale, I'm still able to use the CLI --------- Co-authored-by: clockwork-labs-bot <clockwork-labs-bot@users.noreply.github.com> Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com> Co-authored-by: clockwork-labs-bot <bot@clockworklabs.com> Co-authored-by: Zeke Foppa <196249+bfops@users.noreply.github.com>
44 lines
1.3 KiB
Rust
44 lines
1.3 KiB
Rust
use std::path::{Path, PathBuf};
|
|
use std::process::ExitCode;
|
|
|
|
use anyhow::Context;
|
|
use clap::Parser;
|
|
|
|
mod cli;
|
|
mod proxy;
|
|
mod update_notice;
|
|
|
|
fn main() -> anyhow::Result<ExitCode> {
|
|
let mut args = std::env::args_os();
|
|
let argv0: PathBuf = args.next().unwrap().into();
|
|
let env_cmd = std::env::var_os("SPACETIMEDB_UPDATE_MULTICALL_APPLET");
|
|
let cmd = if let Some(cmd) = &env_cmd {
|
|
cmd
|
|
} else {
|
|
argv0.file_stem().context("argv0 must have a filename")?
|
|
};
|
|
if cmd == "spacetimedb-update" {
|
|
spacetimedb_update_main()
|
|
} else if cmd == "spacetime" {
|
|
let args = args.collect::<Vec<_>>();
|
|
if args.first().is_some_and(|s| s == "version") {
|
|
// if the first arg is unambiguously `version`, go straight to `spacetime version`
|
|
spacetimedb_update_main()
|
|
} else {
|
|
proxy::run_cli(None, Some(argv0.as_os_str()), args)
|
|
}
|
|
} else if cmd == "spacetime-install" {
|
|
cli::SelfInstall::parse().exec()
|
|
} else {
|
|
anyhow::bail!(
|
|
"unknown command name for spacetimedb-update multicall binary: {}",
|
|
Path::new(cmd).display()
|
|
)
|
|
}
|
|
}
|
|
|
|
fn spacetimedb_update_main() -> anyhow::Result<ExitCode> {
|
|
let args = cli::Args::parse();
|
|
args.exec()
|
|
}
|