From 6f9e4b893d9224291e65a0ea518dc93d74252c87 Mon Sep 17 00:00:00 2001 From: Finomnis Date: Thu, 9 Feb 2023 20:08:41 +0100 Subject: [PATCH 1/7] Add --assume-semver flag --- src/check_release.rs | 15 +++++++++++---- src/main.rs | 24 ++++++++++++++++++++++-- src/query.rs | 2 +- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/check_release.rs b/src/check_release.rs index 6f4e126c..21ba6373 100644 --- a/src/check_release.rs +++ b/src/check_release.rs @@ -83,25 +83,31 @@ pub(super) fn run_check_release( crate_name: &str, current_crate: VersionedCrate, baseline_crate: VersionedCrate, + assume_semver: Option, ) -> anyhow::Result { let current_version = current_crate.crate_version(); let baseline_version = baseline_crate.crate_version(); - let version_change = classify_semver_version_change(current_version, baseline_version) - .unwrap_or_else(|| { + let version_change = assume_semver.unwrap_or_else(|| { + classify_semver_version_change(current_version, baseline_version).unwrap_or_else(|| { config .shell_warn( "Could not determine whether crate version changed. Assuming no change.", ) .expect("print failed"); ActualSemverUpdate::NotChanged - }); + }) + }); let change = match version_change { ActualSemverUpdate::Major => "major", ActualSemverUpdate::Minor => "minor", ActualSemverUpdate::Patch => "patch", ActualSemverUpdate::NotChanged => "no", }; + let assume = match assume_semver { + Some(_) => "assume ", + None => "", + }; let queries = SemverQuery::all_queries(); @@ -119,9 +125,10 @@ pub(super) fn run_check_release( config.shell_status( "Checking", format_args!( - "{crate_name} v{} -> v{} ({} change)", + "{crate_name} v{} -> v{} ({}{} change)", baseline_version.unwrap_or("unknown"), current_version.unwrap_or("unknown"), + assume, change ), )?; diff --git a/src/main.rs b/src/main.rs index fef1989c..058f6ad6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,10 @@ use std::path::PathBuf; use clap::{Args, Parser, Subcommand}; use trustfall_rustdoc::{load_rustdoc, VersionedCrate}; -use crate::{check_release::run_check_release, config::GlobalConfig, util::slugify}; +use crate::{ + check_release::run_check_release, config::GlobalConfig, query::ActualSemverUpdate, + util::slugify, +}; fn main() -> anyhow::Result<()> { human_panic::setup_panic!(); @@ -143,7 +146,13 @@ fn main() -> anyhow::Result<()> { baseline_highest_allowed_version, )?; - let success = run_check_release(&mut config, name, current_crate, baseline_crate)?; + let success = run_check_release( + &mut config, + name, + current_crate, + baseline_crate, + args.assume_semver, + )?; vec![Ok(success)] } else { let metadata = args.manifest.metadata().exec()?; @@ -184,6 +193,7 @@ fn main() -> anyhow::Result<()> { crate_name, current_crate, baseline_crate, + args.assume_semver, )?) } }) @@ -334,6 +344,16 @@ struct CheckRelease { )] baseline_rustdoc: Option, + /// Assume given semver type and ignore the actual version difference. + #[arg( + value_enum, + long, + value_name = "SEMVER_TYPE", + help_heading = "Overrides", + group = "overrides" + )] + assume_semver: Option, + #[command(flatten)] verbosity: clap_verbosity_flag::Verbosity, } diff --git a/src/query.rs b/src/query.rs index f7aa5b70..fc5793ce 100644 --- a/src/query.rs +++ b/src/query.rs @@ -18,7 +18,7 @@ impl RequiredSemverUpdate { } } -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)] pub(crate) enum ActualSemverUpdate { Major, Minor, From c002ffbd9b197d397876f0744b06fab210cc4f06 Mon Sep 17 00:00:00 2001 From: Finomnis Date: Thu, 9 Feb 2023 20:15:51 +0100 Subject: [PATCH 2/7] Rename SEMVER_TYPE to TYPE in help message --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 058f6ad6..58db0ccb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -348,7 +348,7 @@ struct CheckRelease { #[arg( value_enum, long, - value_name = "SEMVER_TYPE", + value_name = "TYPE", help_heading = "Overrides", group = "overrides" )] From f5606585a10201f2034f195d65fc5894b92ffa09 Mon Sep 17 00:00:00 2001 From: Finomnis Date: Thu, 9 Feb 2023 21:07:18 +0100 Subject: [PATCH 3/7] Update src/main.rs Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com> --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 58db0ccb..8b5944d9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -344,7 +344,7 @@ struct CheckRelease { )] baseline_rustdoc: Option, - /// Assume given semver type and ignore the actual version difference. + /// Assume the version change is of the given semver type, overriding the actual change kind. #[arg( value_enum, long, From ecd5505b8d69469945d2077c7f2b687e5b6725d7 Mon Sep 17 00:00:00 2001 From: Finomnis Date: Sat, 11 Feb 2023 13:51:17 +0100 Subject: [PATCH 4/7] Rename assume_semver to release_type --- src/check_release.rs | 6 +++--- src/main.rs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/check_release.rs b/src/check_release.rs index 21ba6373..1fecd082 100644 --- a/src/check_release.rs +++ b/src/check_release.rs @@ -83,12 +83,12 @@ pub(super) fn run_check_release( crate_name: &str, current_crate: VersionedCrate, baseline_crate: VersionedCrate, - assume_semver: Option, + release_type: Option, ) -> anyhow::Result { let current_version = current_crate.crate_version(); let baseline_version = baseline_crate.crate_version(); - let version_change = assume_semver.unwrap_or_else(|| { + let version_change = release_type.unwrap_or_else(|| { classify_semver_version_change(current_version, baseline_version).unwrap_or_else(|| { config .shell_warn( @@ -104,7 +104,7 @@ pub(super) fn run_check_release( ActualSemverUpdate::Patch => "patch", ActualSemverUpdate::NotChanged => "no", }; - let assume = match assume_semver { + let assume = match release_type { Some(_) => "assume ", None => "", }; diff --git a/src/main.rs b/src/main.rs index 8b5944d9..47faae95 100644 --- a/src/main.rs +++ b/src/main.rs @@ -151,7 +151,7 @@ fn main() -> anyhow::Result<()> { name, current_crate, baseline_crate, - args.assume_semver, + args.release_type, )?; vec![Ok(success)] } else { @@ -193,7 +193,7 @@ fn main() -> anyhow::Result<()> { crate_name, current_crate, baseline_crate, - args.assume_semver, + args.release_type, )?) } }) @@ -344,7 +344,7 @@ struct CheckRelease { )] baseline_rustdoc: Option, - /// Assume the version change is of the given semver type, overriding the actual change kind. + /// Set the desired release type instead of deriving it from the version number. #[arg( value_enum, long, @@ -352,7 +352,7 @@ struct CheckRelease { help_heading = "Overrides", group = "overrides" )] - assume_semver: Option, + release_type: Option, #[command(flatten)] verbosity: clap_verbosity_flag::Verbosity, From 4ba666a936c09c79c842206b81d1cc78c5d53fa5 Mon Sep 17 00:00:00 2001 From: Finomnis Date: Sat, 11 Feb 2023 14:03:44 +0100 Subject: [PATCH 5/7] Add ReleaseType enum --- src/check_release.rs | 26 ++++++++++++++------------ src/main.rs | 18 +++++++++++------- src/query.rs | 14 +++++++++++++- 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/check_release.rs b/src/check_release.rs index 1fecd082..075556ed 100644 --- a/src/check_release.rs +++ b/src/check_release.rs @@ -10,7 +10,7 @@ use trustfall_rustdoc::{VersionedCrate, VersionedIndexedCrate, VersionedRustdocA use crate::{ query::{ActualSemverUpdate, RequiredSemverUpdate, SemverQuery}, - GlobalConfig, + GlobalConfig, ReleaseType, }; type QueryResultItem = BTreeMap, FieldValue>; @@ -83,21 +83,23 @@ pub(super) fn run_check_release( crate_name: &str, current_crate: VersionedCrate, baseline_crate: VersionedCrate, - release_type: Option, + release_type: Option, ) -> anyhow::Result { let current_version = current_crate.crate_version(); let baseline_version = baseline_crate.crate_version(); - let version_change = release_type.unwrap_or_else(|| { - classify_semver_version_change(current_version, baseline_version).unwrap_or_else(|| { - config - .shell_warn( - "Could not determine whether crate version changed. Assuming no change.", - ) - .expect("print failed"); - ActualSemverUpdate::NotChanged - }) - }); + let version_change = release_type + .map(ActualSemverUpdate::from) + .unwrap_or_else(|| { + classify_semver_version_change(current_version, baseline_version).unwrap_or_else(|| { + config + .shell_warn( + "Could not determine whether crate version changed. Assuming no change.", + ) + .expect("print failed"); + ActualSemverUpdate::NotChanged + }) + }); let change = match version_change { ActualSemverUpdate::Major => "major", ActualSemverUpdate::Minor => "minor", diff --git a/src/main.rs b/src/main.rs index 47faae95..2b53ed18 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,13 +14,10 @@ use rustdoc_cmd::RustdocCommand; use semver::Version; use std::path::PathBuf; -use clap::{Args, Parser, Subcommand}; +use clap::{Args, Parser, Subcommand, ValueEnum}; use trustfall_rustdoc::{load_rustdoc, VersionedCrate}; -use crate::{ - check_release::run_check_release, config::GlobalConfig, query::ActualSemverUpdate, - util::slugify, -}; +use crate::{check_release::run_check_release, config::GlobalConfig, util::slugify}; fn main() -> anyhow::Result<()> { human_panic::setup_panic!(); @@ -253,6 +250,13 @@ fn generate_versioned_crates( Ok((current_crate, baseline_crate)) } +#[derive(ValueEnum, Debug, Clone, Copy, PartialEq, Eq)] +enum ReleaseType { + Major, + Minor, + Patch, +} + #[derive(Parser)] #[command(name = "cargo")] #[command(bin_name = "cargo")] @@ -344,7 +348,7 @@ struct CheckRelease { )] baseline_rustdoc: Option, - /// Set the desired release type instead of deriving it from the version number. + /// Sets the release type instead of deriving it from the version number. #[arg( value_enum, long, @@ -352,7 +356,7 @@ struct CheckRelease { help_heading = "Overrides", group = "overrides" )] - release_type: Option, + release_type: Option, #[command(flatten)] verbosity: clap_verbosity_flag::Verbosity, diff --git a/src/query.rs b/src/query.rs index fc5793ce..e8c87ff3 100644 --- a/src/query.rs +++ b/src/query.rs @@ -3,6 +3,8 @@ use std::collections::BTreeMap; use serde::{Deserialize, Serialize}; use trustfall_core::ir::TransparentValue; +use crate::ReleaseType; + #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] pub(crate) enum RequiredSemverUpdate { Major, @@ -18,7 +20,7 @@ impl RequiredSemverUpdate { } } -#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub(crate) enum ActualSemverUpdate { Major, Minor, @@ -37,6 +39,16 @@ impl ActualSemverUpdate { } } +impl From for ActualSemverUpdate { + fn from(value: ReleaseType) -> Self { + match value { + ReleaseType::Major => Self::Major, + ReleaseType::Minor => Self::Minor, + ReleaseType::Patch => Self::Patch, + } + } +} + /// A query that can be executed on a pair of rustdoc output files, /// returning instances of a particular kind of semver violation. #[derive(Debug, Clone, Serialize, Deserialize)] From 809636b7e002244e09852cf2f032279cc199c1d5 Mon Sep 17 00:00:00 2001 From: Finomnis Date: Sat, 11 Feb 2023 14:15:54 +0100 Subject: [PATCH 6/7] Beautify code --- src/check_release.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/check_release.rs b/src/check_release.rs index 075556ed..5c7db9fb 100644 --- a/src/check_release.rs +++ b/src/check_release.rs @@ -88,9 +88,9 @@ pub(super) fn run_check_release( let current_version = current_crate.crate_version(); let baseline_version = baseline_crate.crate_version(); - let version_change = release_type - .map(ActualSemverUpdate::from) - .unwrap_or_else(|| { + let version_change = match release_type { + Some(release_type) => release_type.into(), + None => { classify_semver_version_change(current_version, baseline_version).unwrap_or_else(|| { config .shell_warn( @@ -99,7 +99,8 @@ pub(super) fn run_check_release( .expect("print failed"); ActualSemverUpdate::NotChanged }) - }); + } + }; let change = match version_change { ActualSemverUpdate::Major => "major", ActualSemverUpdate::Minor => "minor", From 67e0bb47b43b4248ae4b41a2acdc380f471402fc Mon Sep 17 00:00:00 2001 From: Finomnis Date: Sat, 11 Feb 2023 14:20:38 +0100 Subject: [PATCH 7/7] Beautification --- src/check_release.rs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/check_release.rs b/src/check_release.rs index 5c7db9fb..c6d456b2 100644 --- a/src/check_release.rs +++ b/src/check_release.rs @@ -88,19 +88,17 @@ pub(super) fn run_check_release( let current_version = current_crate.crate_version(); let baseline_version = baseline_crate.crate_version(); - let version_change = match release_type { - Some(release_type) => release_type.into(), - None => { - classify_semver_version_change(current_version, baseline_version).unwrap_or_else(|| { - config - .shell_warn( - "Could not determine whether crate version changed. Assuming no change.", - ) - .expect("print failed"); - ActualSemverUpdate::NotChanged - }) - } - }; + let version_change = release_type + .map(Into::into) + .or_else(|| classify_semver_version_change(current_version, baseline_version)) + .unwrap_or_else(|| { + config + .shell_warn( + "Could not determine whether crate version changed. Assuming no change.", + ) + .expect("print failed"); + ActualSemverUpdate::NotChanged + }); let change = match version_change { ActualSemverUpdate::Major => "major", ActualSemverUpdate::Minor => "minor",