diff --git a/src/check_release.rs b/src/check_release.rs index 6f4e126c..c6d456b2 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,11 +83,14 @@ pub(super) fn run_check_release( crate_name: &str, current_crate: VersionedCrate, baseline_crate: VersionedCrate, + release_type: 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) + let version_change = release_type + .map(Into::into) + .or_else(|| classify_semver_version_change(current_version, baseline_version)) .unwrap_or_else(|| { config .shell_warn( @@ -102,6 +105,10 @@ pub(super) fn run_check_release( ActualSemverUpdate::Patch => "patch", ActualSemverUpdate::NotChanged => "no", }; + let assume = match release_type { + Some(_) => "assume ", + None => "", + }; let queries = SemverQuery::all_queries(); @@ -119,9 +126,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..2b53ed18 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,7 @@ 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, util::slugify}; @@ -143,7 +143,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.release_type, + )?; vec![Ok(success)] } else { let metadata = args.manifest.metadata().exec()?; @@ -184,6 +190,7 @@ fn main() -> anyhow::Result<()> { crate_name, current_crate, baseline_crate, + args.release_type, )?) } }) @@ -243,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")] @@ -334,6 +348,16 @@ struct CheckRelease { )] baseline_rustdoc: Option, + /// Sets the release type instead of deriving it from the version number. + #[arg( + value_enum, + long, + value_name = "TYPE", + help_heading = "Overrides", + group = "overrides" + )] + release_type: Option, + #[command(flatten)] verbosity: clap_verbosity_flag::Verbosity, } diff --git a/src/query.rs b/src/query.rs index f7aa5b70..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, @@ -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)]