Skip to content

Commit

Permalink
refactor: Consolidate consolidate version update
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Oct 18, 2022
1 parent eb81827 commit 2aa17b9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 39 deletions.
27 changes: 6 additions & 21 deletions src/steps/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,29 +233,14 @@ impl ReleaseStep {

// STEP 2: update current version, save and commit
if consolidate_commits {
for pkg in &selected_pkgs {
if let Some(version) = pkg.planned_version.as_ref() {
let crate_name = pkg.meta.name.as_str();
log::info!(
"Update {} to version {}",
crate_name,
version.full_version_string
);
cargo::set_package_version(
&pkg.manifest_path,
version.full_version_string.as_str(),
dry_run,
)?;
crate::steps::version::update_dependent_versions(
&ws_meta, pkg, version, dry_run,
)?;
let update_lock = super::version::update_versions(&ws_meta, &selected_pkgs, dry_run)?;
if update_lock {
log::debug!("Updating lock file");
if !dry_run {
let workspace_path = ws_meta.workspace_root.as_std_path().join("Cargo.toml");
crate::ops::cargo::update_lock(&workspace_path)?;
}
}
log::debug!("Updating lock file");
if !dry_run {
let workspace_path = ws_meta.workspace_root.as_std_path().join("Cargo.toml");
crate::ops::cargo::update_lock(&workspace_path)?;
}

for pkg in &selected_pkgs {
super::replace::replace(pkg, dry_run)?;
Expand Down
46 changes: 28 additions & 18 deletions src/steps/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,24 +157,7 @@ impl VersionStep {
super::confirm("Bump", &selected_pkgs, self.no_confirm, dry_run)?;

// STEP 2: update current version, save and commit
let mut update_lock = false;
for pkg in &selected_pkgs {
if let Some(version) = pkg.planned_version.as_ref() {
let crate_name = pkg.meta.name.as_str();
log::info!(
"Update {} to version {}",
crate_name,
version.full_version_string
);
crate::ops::cargo::set_package_version(
&pkg.manifest_path,
version.full_version_string.as_str(),
dry_run,
)?;
update_dependent_versions(&ws_meta, pkg, version, dry_run)?;
update_lock = true;
}
}
let update_lock = update_versions(&ws_meta, &selected_pkgs, dry_run)?;
if update_lock {
log::debug!("Updating lock file");
if !dry_run {
Expand Down Expand Up @@ -242,6 +225,33 @@ pub fn changed_since<'m>(
Some((changed, lock_changed))
}

pub fn update_versions(
ws_meta: &cargo_metadata::Metadata,
selected_pkgs: &[plan::PackageRelease],
dry_run: bool,
) -> Result<bool, FatalError> {
let mut changed = false;
for pkg in selected_pkgs {
if let Some(version) = pkg.planned_version.as_ref() {
let crate_name = pkg.meta.name.as_str();
log::info!(
"Update {} to version {}",
crate_name,
version.full_version_string
);
crate::ops::cargo::set_package_version(
&pkg.manifest_path,
version.full_version_string.as_str(),
dry_run,
)?;
update_dependent_versions(&ws_meta, pkg, version, dry_run)?;
changed = true;
}
}

Ok(changed)
}

pub fn update_dependent_versions(
ws_meta: &cargo_metadata::Metadata,
pkg: &plan::PackageRelease,
Expand Down

0 comments on commit 2aa17b9

Please sign in to comment.