-
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 (#33)
Fixes #11 The version is checked against the latest release which we can get from this [endpoint](https://api.github.com/repos//sigma0-xyz/zkbitcoin/releases/latest). We compare this version to the crate's version. For this to work we would need: 1. Publish releases of new versions 2. The name of the tag should be prefixed with `v` e.g. `v0.1.0` 3. Bump crate version in Cargo.lock upon new release.
- Loading branch information
Showing
6 changed files
with
54 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,42 @@ | ||
use anyhow::Result; | ||
use log::warn; | ||
use reqwest::Client; | ||
use serde::Deserialize; | ||
use versions::Versioning; | ||
|
||
const RELEASES_URL: &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", "zkbitcoin 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(()) | ||
} |