Skip to content

Commit

Permalink
Update publish action and refactoring functions
Browse files Browse the repository at this point in the history
Modified the publish action in publish.rs to add a verification check for packages before publication. Code refactoring was also done for the functions display_as_tree and display_as_list in package.rs to use "write" instead of "display". Minor updates were also added in the command publish.rs.
  • Loading branch information
Barsik-sus committed Apr 16, 2024
1 parent a1d1cab commit b989df5
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 13 deletions.
55 changes: 46 additions & 9 deletions module/move/willbe/src/action/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,8 @@ mod private
write!( f, "Nothing to publish" )?;
return Ok( () );
}
if let Some( plan ) = &self.plan
{
write!( f, "Tree{} :\n", if plan.roots.len() > 1 { "s" } else { "" } )?;
plan.display_as_tree( f )?;

writeln!( f, "The following packages are pending for publication :" )?;
plan.display_as_list( f )?;
}

writeln!( f, "\nActions :" )?;
writeln!( f, "Actions :" )?;
for ( path, report ) in &self.packages
{
let report = report.to_string().replace("\n", "\n ");
Expand All @@ -56,6 +48,51 @@ mod private
};
write!( f, "Publishing crate by `{}` path\n {report}", path.display() )?;
}
if let Some( plan ) = &self.plan
{
if !plan.dry
{
let expected_to_publish = plan
.plans
.iter()
.map( | p | ( p.version_bump.crate_dir.absolute_path(), p.package_name.clone(), p.version_bump.clone() ) )
.collect::< Vec< _ > >();
let mut actually_published = self.packages.iter()
.filter_map
(
|( path, repo )|
if repo.publish.as_ref().is_some_and( | r | r.error.is_ok() )
{
Some( path.clone() )
}
else
{
None
}
)
.collect::< Vec< _ > >();

writeln!( f, "Status :" )?;
for ( path, name, version ) in expected_to_publish
{
if let Some( pos ) = actually_published.iter().position( | p | p == &path )
{
write!( f, "✅ {name} {}", version.new_version )?;
// want to check that only expected packages actually published
_ = actually_published.remove( pos );
}
else
{
write!( f, "❌ {name} {}", version.old_version )?;
}
}
if !actually_published.is_empty()
{
writeln!( f, "Logical error. Published unexpected packages" )?;
return Err( std::fmt::Error );
}
}
}

Ok( () )
}
Expand Down
17 changes: 15 additions & 2 deletions module/move/willbe/src/command/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ mod private
use colored::Colorize;

use wca::VerifiedCommand;
use wtools::error::Result;
use wtools::error::{ Result, for_app::Context };
use former::Former;
use std::fmt::Write;

#[ derive( Former ) ]
struct PublishProperties
Expand All @@ -29,8 +30,20 @@ mod private
let patterns : Vec< _ > = o.args.get_owned( 0 ).unwrap_or_else( || vec![ "./".into() ] );

let PublishProperties { dry, temp } = o.props.try_into()?;
let plan = action::publish_plan( patterns, dry, temp ).context( "Failed to plan the publication process" )?;

match action::publish( patterns, dry, temp )
let mut formatted_plan = String::new();
writeln!( &mut formatted_plan, "Tree :" )?;
plan.write_as_tree( &mut formatted_plan )?;

if !plan.plans.is_empty()
{
writeln!( &mut formatted_plan, "The following packages are pending for publication :" )?;
plan.write_as_list( &mut formatted_plan )?;
}
println!( "{formatted_plan}" );

match action::publish( plan )
{
Ok( report ) =>
{
Expand Down
8 changes: 6 additions & 2 deletions module/move/willbe/src/entity/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,9 @@ mod private
/// # Errors
///
/// Returns a `std::fmt::Error` if there is an error writing to the formatter.
pub fn display_as_tree( &self, f : &mut Formatter< '_ > ) -> std::fmt::Result
pub fn write_as_tree< W >( &self, f : &mut W ) -> std::fmt::Result
where
W : std::fmt::Write
{
let name_bump_report = self
.plans
Expand Down Expand Up @@ -545,7 +547,9 @@ mod private
/// # Errors
///
/// Returns a `std::fmt::Error` if there is an error writing to the formatter.
pub fn display_as_list( &self, f : &mut Formatter< '_ > ) -> std::fmt::Result
pub fn write_as_list< W >( &self, f : &mut W ) -> std::fmt::Result
where
W : std::fmt::Write
{
for ( idx, package ) in self.plans.iter().enumerate()
{
Expand Down

0 comments on commit b989df5

Please sign in to comment.