mirror of
https://github.com/pesde-pkg/pesde.git
synced 2025-01-10 01:39:10 +00:00
fix: ignore build metadata when comparing cli versions
This commit is contained in:
parent
a6846597ca
commit
d387c27f16
3 changed files with 75 additions and 72 deletions
|
@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
|
|||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
### Fixed
|
||||
- Ignore build metadata when comparing CLI versions by @daimond113
|
||||
|
||||
## [0.5.0] - 2024-12-14
|
||||
### Added
|
||||
- Add support for multiple targets under the same package name in workspace members by @daimond113
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
use crate::cli::{
|
||||
config::read_config,
|
||||
version::{
|
||||
current_version, get_latest_remote_version, get_or_download_version, update_bin_exe,
|
||||
current_version, get_latest_remote_version, get_or_download_version, no_build_metadata,
|
||||
update_bin_exe,
|
||||
},
|
||||
};
|
||||
use anyhow::Context;
|
||||
use clap::Args;
|
||||
use colored::Colorize;
|
||||
use semver::BuildMetadata;
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
pub struct SelfUpgradeCommand {
|
||||
|
@ -28,17 +28,14 @@ impl SelfUpgradeCommand {
|
|||
get_latest_remote_version(&reqwest).await?
|
||||
};
|
||||
|
||||
if latest_version <= current_version() {
|
||||
let latest_version_no_metadata = no_build_metadata(&latest_version);
|
||||
|
||||
if latest_version_no_metadata <= current_version() {
|
||||
println!("already up to date");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let display_latest_version = {
|
||||
let mut ver = latest_version.clone();
|
||||
// remove build metadata to make it more readable
|
||||
ver.build = BuildMetadata::EMPTY;
|
||||
ver.to_string().yellow().bold()
|
||||
};
|
||||
let display_latest_version = latest_version_no_metadata.to_string().yellow().bold();
|
||||
|
||||
if !inquire::prompt_confirmation(format!(
|
||||
"are you sure you want to upgrade {} from {} to {display_latest_version}?",
|
||||
|
|
|
@ -64,6 +64,12 @@ pub async fn get_latest_remote_version(reqwest: &reqwest::Client) -> anyhow::Res
|
|||
.context("failed to find latest version")
|
||||
}
|
||||
|
||||
pub fn no_build_metadata(version: &Version) -> Version {
|
||||
let mut version = version.clone();
|
||||
version.build = semver::BuildMetadata::EMPTY;
|
||||
version
|
||||
}
|
||||
|
||||
const CHECK_INTERVAL: chrono::Duration = chrono::Duration::hours(6);
|
||||
|
||||
pub async fn check_for_updates(reqwest: &reqwest::Client) -> anyhow::Result<()> {
|
||||
|
@ -86,21 +92,18 @@ pub async fn check_for_updates(reqwest: &reqwest::Client) -> anyhow::Result<()>
|
|||
version
|
||||
};
|
||||
let current_version = current_version();
|
||||
let version_no_metadata = no_build_metadata(&version);
|
||||
|
||||
if version_no_metadata <= current_version {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if version > current_version {
|
||||
let name = env!("CARGO_BIN_NAME");
|
||||
let changelog = format!("{}/releases/tag/v{version}", env!("CARGO_PKG_REPOSITORY"));
|
||||
|
||||
let display_version = {
|
||||
let mut ver = version.clone();
|
||||
// remove build metadata to make it more readable
|
||||
ver.build = semver::BuildMetadata::EMPTY;
|
||||
ver.to_string()
|
||||
};
|
||||
|
||||
let unformatted_messages = [
|
||||
"".to_string(),
|
||||
format!("update available! {current_version} → {display_version}"),
|
||||
format!("update available! {current_version} → {version_no_metadata}"),
|
||||
format!("changelog: {changelog}"),
|
||||
format!("run `{name} self-upgrade` to upgrade"),
|
||||
"".to_string(),
|
||||
|
@ -120,7 +123,7 @@ pub async fn check_for_updates(reqwest: &reqwest::Client) -> anyhow::Result<()>
|
|||
format!(
|
||||
"update available! {} → {}",
|
||||
current_version.to_string().red(),
|
||||
display_version.green()
|
||||
version_no_metadata.to_string().green()
|
||||
),
|
||||
format!("changelog: {}", changelog.blue()),
|
||||
format!(
|
||||
|
@ -150,7 +153,6 @@ pub async fn check_for_updates(reqwest: &reqwest::Client) -> anyhow::Result<()>
|
|||
let br = "╯".bright_magenta();
|
||||
|
||||
println!("\n{tl}{lines}{tr}\n{message}\n{bl}{lines}{br}\n");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue