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

READY: (alpha/willbe): .publish and .publish.diff new options #1472

Merged
merged 4 commits into from
Nov 6, 2024
Merged
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
5 changes: 5 additions & 0 deletions module/move/willbe/src/action/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ mod private
///
/// # Arguments
/// * `patterns` - A vector of patterns specifying the folders to search for packages.
/// * `exclude_dev_dependencies` - A boolean value indicating whether to exclude dev dependencies from manifest before publish.
/// * `dry` - A boolean value indicating whether to perform a dry run.
/// * `temp` - A boolean value indicating whether to use a temporary directory.
///
Expand All @@ -119,6 +120,8 @@ mod private
(
patterns : Vec< String >,
channel : channel::Channel,
exclude_dev_dependencies : bool,
commit_changes : bool,
dry : bool,
temp : bool
)
Expand Down Expand Up @@ -233,6 +236,8 @@ mod private
.channel( channel )
.workspace_dir( CrateDir::try_from( workspace_root_dir ).unwrap() )
.option_base_temp_dir( dir.clone() )
.exclude_dev_dependencies( exclude_dev_dependencies )
.commit_changes( commit_changes )
.dry( dry )
.roots( roots )
.packages( queue )
Expand Down
22 changes: 12 additions & 10 deletions module/move/willbe/src/action/publish_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ mod private
pub struct PublishDiffOptions
{
path : PathBuf,
exclude_dev_dependencies : bool,
keep_archive : Option< PathBuf >,
}

Expand Down Expand Up @@ -141,16 +142,17 @@ mod private
let name = &package.name()?;
let version = &package.version()?;

_ = cargo::pack
(
cargo::PackOptions::former()
.path( dir.as_ref() )
.allow_dirty( true )
.checking_consistency( false )
.dry( false ).form()
)?;
let l = CrateArchive::read( packed_crate::local_path( name, version, dir )? )?;
let r = CrateArchive::download_crates_io( name, version ).unwrap();
_ = cargo::pack
(
cargo::PackOptions::former()
.path( dir.as_ref() )
.allow_dirty( true )
.checking_consistency( false )
.exclude_dev_dependencies( o.exclude_dev_dependencies)
.dry( false ).form()
)?;
let l = CrateArchive::read( packed_crate::local_path( name, version, dir )? )?;
let r = CrateArchive::download_crates_io( name, version ).unwrap();


if let Some( out_path ) = &o.keep_archive
Expand Down
15 changes: 15 additions & 0 deletions module/move/willbe/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ mod private
.kind( Type::String )
.optional( true )
.end()
.property( "exclude_dev_dependencies" )
.hint( "Setting this option to true will temporarily remove development dependencies before executing the command, then restore them afterward. Default is `true`." )
.kind( Type::Bool )
.optional( true )
.end()
.property( "commit_changes" )
.hint( "Indicates whether changes should be committed. Default is `false`." )
.kind( Type::Bool )
.optional( true )
.end()
.property( "dry" )
.hint( "Enables 'dry run'. Does not publish, only simulates. Default is `true`." )
.kind( Type::Bool )
Expand All @@ -47,6 +57,11 @@ mod private
.kind( Type::Path )
.optional( true )
.end()
.property( "exclude_dev_dependencies" )
.hint( "Setting this option to true will temporarily remove development dependencies before executing the command, then restore them afterward. Default is `true`." )
.kind( Type::Bool )
.optional( true )
.end()
.property( "keep_archive" )
.hint( "Save remote package version to the specified path" )
.kind( Type::Path )
Expand Down
12 changes: 11 additions & 1 deletion module/move/willbe/src/command/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ mod private
{
#[ former( default = Channel::Stable ) ]
channel : Channel,
#[ former( default = false ) ]
exclude_dev_dependencies : bool,
#[ former( default = false ) ]
commit_changes : bool,
#[ former( default = true ) ]
dry : bool,
#[ former( default = true ) ]
Expand Down Expand Up @@ -52,10 +56,12 @@ mod private
let PublishProperties
{
channel,
exclude_dev_dependencies,
commit_changes,
dry,
temp
} = o.props.try_into()?;
let plan = action::publish_plan( patterns, channel, dry, temp )
let plan = action::publish_plan( patterns, channel, exclude_dev_dependencies, commit_changes, dry, temp )
.context( "Failed to plan the publication process" )?;

let mut formatted_plan = String::new();
Expand Down Expand Up @@ -110,6 +116,10 @@ mod private
else
{ this };

this = if let Some( v ) = value
.get_owned( "exclude_dev_dependencies" ) { this.exclude_dev_dependencies::< bool >( v ) } else { this };
this = if let Some( v ) = value
.get_owned( "commit_changes" ) { this.commit_changes::< bool >( v ) } else { this };
this = if let Some( v ) = value
.get_owned( "dry" ) { this.dry::< bool >( v ) } else { this };
this = if let Some( v ) = value
Expand Down
13 changes: 11 additions & 2 deletions module/move/willbe/src/command/publish_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ mod private
#[ derive( former::Former ) ]
struct PublishDiffProperties
{
#[ former( default = false ) ]
exclude_dev_dependencies : bool,
keep_archive : Option< PathBuf >,
}

Expand All @@ -33,10 +35,11 @@ mod private
pub fn publish_diff( o : VerifiedCommand ) -> error::untyped::Result< () > // qqq : use typed error
{
let path : PathBuf = o.args.get_owned( 0 ).unwrap_or( std::env::current_dir()? );
let PublishDiffProperties { keep_archive } = o.props.try_into()?;
let PublishDiffProperties { keep_archive, exclude_dev_dependencies } = o.props.try_into()?;

let mut o = action::PublishDiffOptions::former()
.path( path );
.path( path )
.exclude_dev_dependencies( exclude_dev_dependencies );
if let Some( k ) = keep_archive.clone() { o = o.keep_archive( k ); }
let o = o.form();

Expand All @@ -57,6 +60,12 @@ mod private
{
let mut this = Self::former();

this = if let Some( v ) = value
.get_owned( "exclude_dev_dependencies" )
{ this.exclude_dev_dependencies::< bool >( v ) }
else
{ this };

this = if let Some( v ) = value
.get_owned( "keep_archive" )
{ this.keep_archive::< PathBuf >( v ) }
Expand Down
92 changes: 63 additions & 29 deletions module/move/willbe/src/entity/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mod private
/// Options for bumping the package version.
pub bump : version::BumpOptions,
/// Git options related to the package.
pub git_options : entity::git::GitOptions,
pub git_options : Option< entity::git::GitOptions >,
/// Options for publishing the package using Cargo.
pub publish : cargo::PublishOptions,
/// Indicates whether the process should be dry-run (no actual publishing).
Expand All @@ -42,6 +42,9 @@ mod private
package : package::Package< 'a >,
channel : channel::Channel,
base_temp_dir : Option< path::PathBuf >,
exclude_dev_dependencies : bool,
#[ former( default = true ) ]
commit_changes : bool,
#[ former( default = true ) ]
dry : bool,
}
Expand All @@ -58,6 +61,7 @@ mod private
channel : self.channel,
allow_dirty : self.dry,
checking_consistency : !self.dry,
exclude_dev_dependencies : self.exclude_dev_dependencies,
temp_path : self.base_temp_dir.clone(),
dry : self.dry,
};
Expand All @@ -73,17 +77,21 @@ mod private
dependencies : dependencies.clone(),
dry : self.dry,
};
let git_options = entity::git::GitOptions
let git_options = if self.commit_changes
{
git_root : workspace_root,
items : dependencies.iter().chain([ &crate_dir ]).map( | d | d.clone().absolute_path().join( "Cargo.toml" ) ).collect(),
message : format!( "{}-v{}", self.package.name().unwrap(), new_version ),
dry : self.dry,
};
Some( entity::git::GitOptions
{
git_root : workspace_root,
items : dependencies.iter().chain([ &crate_dir ]).map( | d | d.clone().absolute_path().join( "Cargo.toml" ) ).collect(),
message : format!( "{}-v{}", self.package.name().unwrap(), new_version ),
dry : self.dry,
})
} else { None };
let publish = cargo::PublishOptions
{
path : crate_dir.clone().absolute_path().inner(),
temp_path : self.base_temp_dir.clone(),
exclude_dev_dependencies : self.exclude_dev_dependencies,
retry_count : 2,
dry : self.dry,
};
Expand Down Expand Up @@ -121,6 +129,14 @@ mod private
/// Release channels for rust.
pub channel : channel::Channel,

/// Setting this option to true will temporarily remove development dependencies before executing the command, then restore them afterward.
#[ allow( dead_code ) ] // former related
pub exclude_dev_dependencies : bool,

/// Indicates whether changes should be committed.
#[ former( default = true ) ]
pub commit_changes : bool,

/// `dry` - A boolean value indicating whether to do a dry run. If set to `true`, the application performs
/// a simulated run without making any actual changes. If set to `false`, the operations are actually executed.
/// This property is optional and defaults to `true`.
Expand Down Expand Up @@ -246,6 +262,14 @@ mod private
{
plan = plan.dry( dry );
}
if let Some( exclude_dev_dependencies ) = &self.storage.exclude_dev_dependencies
{
plan = plan.exclude_dev_dependencies( *exclude_dev_dependencies )
}
if let Some( commit_changes ) = &self.storage.commit_changes
{
plan = plan.commit_changes( *commit_changes )
}
let plan = plan
.channel( channel )
.package( package )
Expand Down Expand Up @@ -362,45 +386,55 @@ mod private
} = instruction;
pack.dry = dry;
bump.dry = dry;
git_options.dry = dry;
git_options.as_mut().map( | d | d.dry = dry );
publish.dry = dry;

report.get_info = Some( cargo::pack( pack ).err_with_report( &report )? );
// aaa : redundant field? // aaa : removed
let bump_report = version::bump( bump ).err_with_report( &report )?;
report.bump = Some( bump_report.clone() );
let git_root = git_options.git_root.clone();
let git = match entity::git::perform_git_commit( git_options )

let git_root = git_options.as_ref().map( | g | g.git_root.clone() );
if let Some( git_options ) = git_options
{
Ok( git ) => git,
Err( e ) =>
let git = match entity::git::perform_git_commit( git_options )
{
version::revert( &bump_report )
.map_err( | le | format_err!( "Base error:\n{}\nRevert error:\n{}", e.to_string().replace( '\n', "\n\t" ), le.to_string().replace( '\n', "\n\t" ) ) )
.err_with_report( &report )?;
return Err(( report, e ));
}
};
report.add = git.add;
report.commit = git.commit;
Ok( git ) => git,
Err( e ) =>
{
version::revert( &bump_report )
.map_err( | le | format_err!( "Base error:\n{}\nRevert error:\n{}", e.to_string().replace( '\n', "\n\t" ), le.to_string().replace( '\n', "\n\t" ) ) )
.err_with_report( &report )?;
return Err(( report, e ));
}
};
report.add = git.add;
report.commit = git.commit;
}
report.publish = match cargo::publish( publish )
{
Ok( publish ) => Some( publish ),
Err( e ) =>
{
tool::git::reset( git_root.as_ref(), true, 1, false )
.map_err
(
| le |
format_err!( "Base error:\n{}\nRevert error:\n{}", e.to_string().replace( '\n', "\n\t" ), le.to_string().replace( '\n', "\n\t" ) )
)
.err_with_report( &report )?;
if let Some( git_root ) = git_root.as_ref()
{
tool::git::reset( git_root.as_ref(), true, 1, false )
.map_err
(
| le |
format_err!( "Base error:\n{}\nRevert error:\n{}", e.to_string().replace( '\n', "\n\t" ), le.to_string().replace( '\n', "\n\t" ) )
)
.err_with_report( &report )?;
}
return Err(( report, e ));
}
};

let res = tool::git::push( &git_root, dry ).err_with_report( &report )?;
report.push = Some( res );
if let Some( git_root ) = git_root.as_ref()
{
let res = tool::git::push( &git_root, dry ).err_with_report( &report )?;
report.push = Some( res );
}

Ok( report )
}
Expand Down
Loading
Loading