Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add --release-type flag #361

Merged
merged 7 commits into from
Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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