-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement a check to the latest version of the CLI
- Loading branch information
Showing
6 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod version; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use anyhow::Result; | ||
use log::warn; | ||
use reqwest::Client; | ||
use serde::Deserialize; | ||
use versions::Versioning; | ||
|
||
const RELEASES_URL: &'static str = | ||
"https://api.github.com/repos//sigma0-xyz/zkbitcoin/releases/latest"; | ||
|
||
#[derive(Deserialize, Debug)] | ||
struct Release { | ||
url: String, | ||
tag_name: String, | ||
} | ||
|
||
async fn fetch_latest_version() -> Result<Release> { | ||
let client = Client::new(); | ||
|
||
let release = client | ||
.get(RELEASES_URL) | ||
.header("User-Agent", "Rust CLI") | ||
.send() | ||
.await? | ||
.json::<Release>() | ||
.await?; | ||
|
||
Ok(release) | ||
} | ||
|
||
pub async fn check_version() -> Result<()> { | ||
let current_version = Versioning::new(env!("CARGO_PKG_VERSION")); | ||
let latest_release = fetch_latest_version().await?; | ||
let latest_version = Versioning::new(&latest_release.tag_name.replace("v", "")); | ||
|
||
if current_version < latest_version { | ||
warn!( | ||
"You are using an old version. Please download the latest version: {}", | ||
latest_release.url | ||
) | ||
} | ||
|
||
Ok(()) | ||
} |