Skip to content

Commit

Permalink
Add --release-type flag (#361)
Browse files Browse the repository at this point in the history
* Add --assume-semver flag

* Rename SEMVER_TYPE to TYPE in help message

* Update src/main.rs

Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>

* Rename assume_semver to release_type

* Add ReleaseType enum

* Beautify code

* Beautification

---------

Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
  • Loading branch information
Finomnis and obi1kenobi authored Feb 11, 2023
1 parent 618dc8f commit 9b4a735
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
14 changes: 11 additions & 3 deletions src/check_release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use trustfall_rustdoc::{VersionedCrate, VersionedIndexedCrate, VersionedRustdocA

use crate::{
query::{ActualSemverUpdate, RequiredSemverUpdate, SemverQuery},
GlobalConfig,
GlobalConfig, ReleaseType,
};

type QueryResultItem = BTreeMap<Arc<str>, FieldValue>;
Expand Down Expand Up @@ -83,11 +83,14 @@ pub(super) fn run_check_release(
crate_name: &str,
current_crate: VersionedCrate,
baseline_crate: VersionedCrate,
release_type: Option<ReleaseType>,
) -> anyhow::Result<bool> {
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(
Expand All @@ -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();

Expand All @@ -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
),
)?;
Expand Down
28 changes: 26 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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()?;
Expand Down Expand Up @@ -184,6 +190,7 @@ fn main() -> anyhow::Result<()> {
crate_name,
current_crate,
baseline_crate,
args.release_type,
)?)
}
})
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -334,6 +348,16 @@ struct CheckRelease {
)]
baseline_rustdoc: Option<PathBuf>,

/// 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<ReleaseType>,

#[command(flatten)]
verbosity: clap_verbosity_flag::Verbosity<clap_verbosity_flag::InfoLevel>,
}
Expand Down
12 changes: 12 additions & 0 deletions src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -37,6 +39,16 @@ impl ActualSemverUpdate {
}
}

impl From<ReleaseType> 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)]
Expand Down

0 comments on commit 9b4a735

Please # to comment.