Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix workspace handling CLI bugs. #381

Merged
merged 12 commits into from
Feb 22, 2023
Merged
46 changes: 46 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
- run-on-bevy-gltf
- run-on-clap
- run-on-sqllogictest
- run-on-tokio
steps:
- run: exit 0

Expand Down Expand Up @@ -414,6 +415,51 @@ jobs:
- name: Run via package Cargo.toml
run: cargo run semver-checks check-release --manifest-path subject/sqllogictest/Cargo.toml

run-on-tokio:
# cargo-semver-checks crashed here due to improper CLI argument handling:
# https://github.com/obi1kenobi/cargo-semver-checks/issues/380
name: Run cargo-semver-checks on tokio ~v1.25.0
runs-on: ubuntu-latest
steps:
- name: Checkout cargo-semver-checks
uses: actions/checkout@v3
with:
persist-credentials: false

- name: Checkout tokio
uses: actions/checkout@v3
with:
persist-credentials: false
repository: 'tokio-rs/tokio'
ref: 'd7b7c6131774ab631be6529fef3680abfeeb4781'
path: 'subject'

- name: Install rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true

- uses: Swatinem/rust-cache@v2
with:
key: tokio

# This test caught a bug where the default baseline was set to the current path,
# instead of the default registry version.
- name: Run semver-checks on tokio crate manifest only
run: cargo run semver-checks check-release --manifest-path="subject/tokio/Cargo.toml" --release-type minor --exclude benches --exclude examples --exclude stress-test --exclude tests-build --exclude tests-integration

# This test caught a bug where `--exclude` was silently ignored
# if `--workspace` wasn't set at the same time.
- name: Run semver-checks on workspace manifest with explicit exclusions
run: cargo run semver-checks check-release --manifest-path="subject/Cargo.toml" --release-type minor --exclude examples --exclude stress-test --exclude tests-build --exclude tests-integration

# This test caught a bug where `publish = false` items in a workspace were semver-checked
# unless either explicit `--workspace` was present or was implied e.g. via `--exclude`.
- name: Run semver-checks on workspace manifest with implicit exclusions
run: cargo run semver-checks check-release --manifest-path="subject/Cargo.toml" --release-type minor

run-on-clap:
# clap v3.2.0 added a semver violation
# check whether cargo-semver-checks detects the issue
Expand Down
13 changes: 1 addition & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,7 @@ impl Check {
let crate_name = &selected.name;
let version = &selected.version;

let is_implied = matches!(
self.scope.mode,
ScopeMode::DenyList(PackageSelection {
selection: ScopeSelection::Workspace,
..
})
) && selected.publish == Some(vec![]);
let is_implied = selected.publish == Some(vec![]);
if is_implied {
config.verbose(|config| {
config.shell_status(
Expand All @@ -383,11 +377,6 @@ impl Check {
})?;
Ok(true)
} else {
config.shell_status(
"Parsing",
format_args!("{crate_name} v{version} (current)"),
)?;

let (current_crate, baseline_crate) = generate_versioned_crates(
&mut config,
&rustdoc_cmd,
Expand Down
32 changes: 16 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ fn main() -> anyhow::Result<()> {
}
}

#[derive(Parser)]
#[derive(Debug, Parser)]
#[command(name = "cargo")]
#[command(bin_name = "cargo")]
#[command(version, propagate_version = true)]
enum Cargo {
SemverChecks(SemverChecks),
}

#[derive(Args)]
#[derive(Debug, Args)]
#[command(args_conflicts_with_subcommands = true)]
struct SemverChecks {
#[arg(long, global = true, exclusive = true)]
Expand All @@ -119,13 +119,13 @@ struct SemverChecks {
}

/// Check your crate for semver violations.
#[derive(Subcommand)]
#[derive(Debug, Subcommand)]
enum SemverChecksCommands {
#[command(alias = "diff-files")]
CheckRelease(CheckRelease),
}

#[derive(Args)]
#[derive(Debug, Args)]
struct CheckRelease {
#[command(flatten, next_help_heading = "Current")]
pub manifest: clap_cargo::Manifest,
Expand Down Expand Up @@ -215,16 +215,16 @@ impl From<CheckRelease> for cargo_semver_checks::Check {
(Rustdoc::from_root(&project_root), Some(project_root))
};
let mut check = Self::new(current);
if value.workspace.all || value.workspace.workspace {
if value.workspace.all || value.workspace.workspace || !value.workspace.exclude.is_empty() {
let mut selection = PackageSelection::new(ScopeSelection::Workspace);
selection.with_excluded_packages(value.workspace.exclude);
check.with_package_selection(selection);
} else if !value.workspace.package.is_empty() {
check.with_packages(value.workspace.package);
}
let baseline = {
let custom_baseline = {
if let Some(baseline_version) = value.baseline_version {
Rustdoc::from_registry(baseline_version)
Some(Rustdoc::from_registry(baseline_version))
} else if let Some(baseline_rev) = value.baseline_rev {
let root = if let Some(baseline_root) = value.baseline_root {
baseline_root
Expand All @@ -233,22 +233,22 @@ impl From<CheckRelease> for cargo_semver_checks::Check {
} else {
std::env::current_dir().expect("can't determine current directory")
};
Rustdoc::from_git_revision(root, baseline_rev)
Some(Rustdoc::from_git_revision(root, baseline_rev))
} else if let Some(baseline_rustdoc) = value.baseline_rustdoc {
Rustdoc::from_path(baseline_rustdoc)
Some(Rustdoc::from_path(baseline_rustdoc))
} else {
let root = if let Some(baseline_root) = value.baseline_root {
baseline_root
} else {
std::env::current_dir().expect("can't determine current directory")
};
Rustdoc::from_root(root)
// Either there's a manually-set baseline root path, or fall through
// to the default behavior.
value.baseline_root.map(Rustdoc::from_root)
}
};
check.with_baseline(baseline);
if let Some(baseline) = custom_baseline {
check.with_baseline(baseline);
}
if let Some(log_level) = value.verbosity.log_level() {
check.with_log_level(log_level);
}

check
}
}
Expand Down