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

Add exclude unchanged to release step #777

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Options:
--unpublished Process all packages whose current version is unpublished
-m, --metadata <METADATA> Semver metadata
-x, --execute Actually perform a release. Dry-run mode is the default
--exclude-unchanged Exclude unchanged packages
--no-confirm Skip release confirmation and version preview
--prev-tag-name <NAME> The name of tag for the previous release
-c, --config <PATH> Custom config file
Expand Down
6 changes: 5 additions & 1 deletion src/steps/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ pub struct HookStep {
#[arg(short = 'n', long, conflicts_with = "execute", hide = true)]
dry_run: bool,

/// Exclude unchanged packages
#[arg(long)]
exclude_unchanged: bool,

/// Skip release confirmation and version preview
#[arg(long)]
no_confirm: bool,
Expand Down Expand Up @@ -126,7 +130,7 @@ impl HookStep {
log::Level::Warn,
)?;

super::warn_changed(&ws_meta, &selected_pkgs)?;
let selected_pkgs = super::detect_changed(&ws_meta, &selected_pkgs, self.exclude_unchanged)?;

failed |= !super::verify_git_branch(
ws_meta.workspace_root.as_std_path(),
Expand Down
29 changes: 22 additions & 7 deletions src/steps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,11 @@ pub fn verify_metadata(
Ok(success)
}

pub fn warn_changed(
pub fn detect_changed(
ws_meta: &cargo_metadata::Metadata,
pkgs: &[plan::PackageRelease],
) -> Result<(), crate::error::CliError> {
exclude_unchanged: bool
) -> Result<Vec<plan::PackageRelease>, crate::error::CliError> {
let mut changed_pkgs = std::collections::HashSet::new();
for pkg in pkgs {
let version = pkg.planned_version.as_ref().unwrap_or(&pkg.initial_version);
Expand Down Expand Up @@ -366,10 +367,18 @@ pub fn warn_changed(
changed_pkgs.insert(&pkg.meta.id);
changed_pkgs.extend(pkg.dependents.iter().map(|d| &d.pkg.id));
} else {
let _ = crate::ops::shell::warn(format!(
"updating {} to {} despite no changes made since tag {}",
crate_name, version.full_version_string, prior_tag_name
));
if exclude_unchanged {
log::debug!(
"Excluding {}, no changes made since tag {}",
crate_name,
prior_tag_name,
);
} else {
let _ = crate::ops::shell::warn(format!(
"updating {} to {} despite no changes made since tag {}",
crate_name, version.full_version_string, prior_tag_name
));
}
}
} else {
log::debug!(
Expand All @@ -386,7 +395,13 @@ pub fn warn_changed(
}
}

Ok(())
let packages = if exclude_unchanged {
pkgs.iter().filter(|p| changed_pkgs.contains(&p.meta.id)).cloned().collect()
} else {
pkgs.to_vec()
};

Ok(packages)
}

pub fn find_shared_versions(
Expand Down
4 changes: 2 additions & 2 deletions src/steps/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn plan(
Ok(pkgs)
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct PackageRelease {
pub meta: cargo_metadata::Package,
pub manifest_path: PathBuf,
Expand Down Expand Up @@ -328,7 +328,7 @@ fn find_dependents<'w>(
})
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Dependency {
pub pkg: cargo_metadata::Package,
pub req: semver::VersionReq,
Expand Down
6 changes: 5 additions & 1 deletion src/steps/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ pub struct ReleaseStep {
#[arg(short = 'n', long, conflicts_with = "execute", hide = true)]
dry_run: bool,

/// Exclude unchanged packages
#[arg(long)]
exclude_unchanged: bool,

/// Skip release confirmation and version preview
#[arg(long)]
no_confirm: bool,
Expand Down Expand Up @@ -228,7 +232,7 @@ impl ReleaseStep {
}
}

super::warn_changed(&ws_meta, &selected_pkgs)?;
let selected_pkgs = super::detect_changed(&ws_meta, &selected_pkgs, self.exclude_unchanged)?;

failed |= !super::verify_git_branch(
ws_meta.workspace_root.as_std_path(),
Expand Down
6 changes: 5 additions & 1 deletion src/steps/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ pub struct ReplaceStep {
#[arg(short = 'n', long, conflicts_with = "execute", hide = true)]
dry_run: bool,

/// Exclude unchanged packages
#[arg(long)]
exclude_unchanged: bool,

/// Skip release confirmation and version preview
#[arg(long)]
no_confirm: bool,
Expand Down Expand Up @@ -122,7 +126,7 @@ impl ReplaceStep {
log::Level::Warn,
)?;

super::warn_changed(&ws_meta, &selected_pkgs)?;
let selected_pkgs = super::detect_changed(&ws_meta, &selected_pkgs, self.exclude_unchanged)?;

failed |= !super::verify_git_branch(
ws_meta.workspace_root.as_std_path(),
Expand Down
6 changes: 5 additions & 1 deletion src/steps/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ pub struct VersionStep {
#[arg(short = 'n', long, conflicts_with = "execute", hide = true)]
dry_run: bool,

/// Exclude unchanged packages
#[arg(long)]
exclude_unchanged: bool,

/// Skip release confirmation and version preview
#[arg(long)]
no_confirm: bool,
Expand Down Expand Up @@ -118,7 +122,7 @@ impl VersionStep {
failed |=
!super::verify_monotonically_increasing(&selected_pkgs, dry_run, log::Level::Error)?;

super::warn_changed(&ws_meta, &selected_pkgs)?;
let selected_pkgs = super::detect_changed(&ws_meta, &selected_pkgs, self.exclude_unchanged)?;

failed |= !super::verify_git_branch(
ws_meta.workspace_root.as_std_path(),
Expand Down