Skip to content

Commit

Permalink
Merge pull request #1195 from Barsik-sus/willbe_publish_plans
Browse files Browse the repository at this point in the history
READY: (willbe):Refactoring the publication process
  • Loading branch information
Wandalen authored Mar 22, 2024
2 parents 09c95c1 + 40037d3 commit 4da4623
Show file tree
Hide file tree
Showing 14 changed files with 790 additions and 315 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -459,17 +459,17 @@ default-features = true
## test experimental

[workspace.dependencies.test_experimental_a]
version = "~0.3.0"
version = "~0.5.0"
path = "module/test/a"
default-features = true

[workspace.dependencies.test_experimental_b]
version = "~0.2.0"
version = "~0.3.0"
path = "module/test/b"
default-features = true

[workspace.dependencies.test_experimental_c]
version = "~0.2.0"
version = "~0.3.0"
path = "module/test/c"
default-features = true

Expand Down
103 changes: 26 additions & 77 deletions module/move/willbe/src/action/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mod private
pub workspace_root_dir : Option< AbsolutePath >,
/// Represents a collection of packages that are roots of the trees.
pub wanted_to_publish : Vec< CrateDir >,
pub plan : Option< package::PublishPlan >,
/// Represents a collection of packages and their associated publishing reports.
pub packages : Vec<( AbsolutePath, package::PublishReport )>
}
Expand All @@ -30,62 +31,19 @@ mod private
{
if self.packages.is_empty()
{
f.write_fmt( format_args!( "Nothing to publish" ) )?;
write!( f, "Nothing to publish" )?;
return Ok( () );
}
write!( f, "Tree(-s):\n" )?;
let name_bump_report = self
.packages
.iter()
.filter_map( |( _, r )| r.bump.as_ref() )
.map( | b | &b.base )
.filter_map( | b | b.name.as_ref().and_then( | name | b.old_version.as_ref().and_then( | old | b.new_version.as_ref().map( | new | ( name, ( old, new ) ) ) ) ) )
.collect::< HashMap< _, _ > >();
for wanted in &self.wanted_to_publish
if let Some( plan ) = &self.plan
{
let list = action::list
(
action::list::ListOptions::former()
.path_to_manifest( wanted.clone() )
.format( action::list::ListFormat::Tree )
.dependency_sources([ action::list::DependencySource::Local ])
.dependency_categories([ action::list::DependencyCategory::Primary ])
.form()
)
.map_err( |( _, _e )| std::fmt::Error )?;
let action::list::ListReport::Tree( list ) = list else { unreachable!() };

fn callback( name_bump_report : &HashMap< &String, ( &String, &String) >, mut r : action::list::ListNodeReport ) -> action::list::ListNodeReport
{
if let Some(( old, new )) = name_bump_report.get( &r.name )
{
r.version = Some( format!( "({old} -> {new})" ) );
}
r.normal_dependencies = r.normal_dependencies.into_iter().map( | r | callback( name_bump_report, r ) ).collect();
r.dev_dependencies = r.dev_dependencies.into_iter().map( | r | callback( name_bump_report, r ) ).collect();
r.build_dependencies = r.build_dependencies.into_iter().map( | r | callback( name_bump_report, r ) ).collect();

r
}
let list = list.into_iter().map( | r | callback( &name_bump_report, r ) ).collect();
write!( f, "Tree{} :\n", if self.wanted_to_publish.len() > 1 { "s" } else { "" } )?;
plan.display_as_tree( f, &self.wanted_to_publish )?;

let list = action::list::ListReport::Tree( list );
write!( f, "{}\n", list )?;
}
writeln!( f, "The following packages are pending for publication :" )?;
for ( idx, package ) in self.packages.iter().map( |( _, p )| p ).enumerate()
{
if let Some( bump ) = &package.bump
{
match ( &bump.base.name, &bump.base.old_version, &bump.base.new_version )
{
( Some( name ), Some( old ), Some( new ) ) => writeln!( f, "[{idx}] {name} ({old} -> {new})" )?,
_ => {}
}
}
writeln!( f, "The following packages are pending for publication :" )?;
plan.display_as_list( f )?;
}

write!( f, "\nActions :\n" )?;
writeln!( f, "\nActions :" )?;
for ( path, report ) in &self.packages
{
let report = report.to_string().replace("\n", "\n ");
Expand All @@ -98,7 +56,7 @@ mod private
{
path.as_ref()
};
f.write_fmt( format_args!( "Publishing crate by `{}` path\n {report}\n", path.display() ) )?;
write!( f, "Publishing crate by `{}` path\n {report}", path.display() )?;
}

Ok( () )
Expand Down Expand Up @@ -135,14 +93,12 @@ mod private

Workspace::with_crate_dir( dir ).err_with( || report.clone() )?
};
report.workspace_root_dir = Some
(
metadata
.workspace_root()
.err_with( || report.clone() )?
.try_into()
.err_with( || report.clone() )?
);
let workspace_root_dir : AbsolutePath = metadata
.workspace_root()
.err_with( || report.clone() )?
.try_into()
.err_with( || report.clone() )?;
report.workspace_root_dir = Some( workspace_root_dir.clone() );
let packages = metadata.load().err_with( || report.clone() )?.packages().err_with( || report.clone() )?;
let packages_to_publish : Vec< _ > = packages
.iter()
Expand Down Expand Up @@ -184,26 +140,19 @@ mod private
let subgraph = graph::remove_not_required_to_publish( &package_map, &tmp, &packages_to_publish, dir.clone() );
let subgraph = subgraph.map( | _, n | n, | _, e | e );

let queue = graph::toposort( subgraph ).unwrap().into_iter().map( | n | package_map.get( &n ).unwrap() ).collect::< Vec< _ > >();
let queue = graph::toposort( subgraph ).unwrap().into_iter().map( | n | package_map.get( &n ).unwrap() ).cloned().collect::< Vec< _ > >();

for package in queue
let plan = package::PublishPlan::former()
.workspace_dir( CrateDir::try_from( workspace_root_dir ).unwrap() )
.option_base_temp_dir( dir.clone() )
.dry( dry )
.packages( queue )
.form();
report.plan = Some( plan.clone() );
for package_report in package::perform_packages_publish( plan ).err_with( || report.clone() )?
{
let args = package::PublishSingleOptions::former()
.package( package )
.force( true )
.option_base_temp_dir( &dir )
.dry( dry )
.form();
let current_report = package::publish_single( args )
.map_err
(
| ( current_report, e ) |
{
report.packages.push(( package.crate_dir().absolute_path(), current_report.clone() ));
( report.clone(), e.context( "Publish list of packages" ) )
}
)?;
report.packages.push(( package.crate_dir().absolute_path(), current_report ));
let path : &std::path::Path = package_report.get_info.as_ref().unwrap().current_path.as_ref();
report.packages.push(( AbsolutePath::try_from( path ).unwrap(), package_report ));
}

if temp
Expand Down
8 changes: 4 additions & 4 deletions module/move/willbe/src/entity/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub( crate ) mod private

impl TryFrom< AbsolutePath > for CrateDir
{
// qqq : make better errors
// aaa : make better errors
// aaa : use `CrateDirError` for it
type Error = CrateDirError;

Expand Down Expand Up @@ -100,7 +100,7 @@ pub( crate ) mod private

impl TryFrom< AbsolutePath > for Manifest
{
// qqq : make better errors
// aaa : make better errors
// aaa : return `ManifestError`
type Error = ManifestError;

Expand Down Expand Up @@ -159,7 +159,7 @@ pub( crate ) mod private
Ok( () )
}

// qqq : for Bohdan : don't abuse anyhow
// aaa : for Bohdan : don't abuse anyhow
// aaa : return `io` error
/// Store manifest.
pub fn store( &self ) -> io::Result< () >
Expand Down Expand Up @@ -200,7 +200,7 @@ pub( crate ) mod private
}

/// Create and load manifest by specified path
// qqq : for Bohdan : use newtype, add proper errors handing
// aaa : for Bohdan : use newtype, add proper errors handing
// aaa : return `ManifestError`
pub fn open( path : AbsolutePath ) -> Result< Manifest, ManifestError >
{
Expand Down
Loading

0 comments on commit 4da4623

Please sign in to comment.