Skip to content

Commit

Permalink
Merge pull request #1377 from Barsik-sus/willbe-publish_channel
Browse files Browse the repository at this point in the history
READY: (willbe): Added `channel` property for `publish` command
  • Loading branch information
Wandalen authored Jun 10, 2024
2 parents 7295939 + 31eb7e1 commit 77a5e89
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 6 deletions.
4 changes: 3 additions & 1 deletion module/move/willbe/src/action/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod private
use _path::AbsolutePath;
use workspace::Workspace;
use package::Package;
use channel::Channel;

/// Represents a report of publishing packages
#[ derive( Debug, Default, Clone ) ]
Expand Down Expand Up @@ -107,7 +108,7 @@ mod private
/// # Returns
/// A Result containing a `PublishPlan` if successful, or an `Error` otherwise.
#[ cfg_attr( feature = "tracing", tracing::instrument ) ]
pub fn publish_plan( patterns : Vec< String >, dry : bool, temp : bool ) -> Result< package::PublishPlan, Error >
pub fn publish_plan( patterns : Vec< String >, channel : Channel, dry : bool, temp : bool ) -> Result< package::PublishPlan, Error >
{
let mut paths = HashSet::new();
// find all packages by specified folders
Expand Down Expand Up @@ -173,6 +174,7 @@ mod private
let roots = packages_to_publish.iter().map( | p | package_map.get( p ).unwrap().crate_dir() ).collect::< Vec< _ > >();

let plan = package::PublishPlan::former()
.channel( channel )
.workspace_dir( CrateDir::try_from( workspace_root_dir ).unwrap() )
.option_base_temp_dir( dir.clone() )
.dry( dry )
Expand Down
5 changes: 5 additions & 0 deletions module/move/willbe/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ pub( crate ) mod private
.kind( Type::List( Type::String.into(), ',' ) )
.optional( true )
.end()
.property( "channel" )
.hint( "Release channels for rust." )
.kind( Type::String )
.optional( true )
.end()
.property( "dry" )
.hint( "Enables 'dry run'. Does not publish, only simulates. Default is `true`." )
.kind( Type::Bool )
Expand Down
8 changes: 6 additions & 2 deletions module/move/willbe/src/command/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ mod private
use wtools::error::{ Result, for_app::Context };
use former::Former;
use std::fmt::Write;
use channel::Channel;

#[ derive( Former ) ]
struct PublishProperties
{
#[ former( default = Channel::Stable ) ]
channel : Channel,
#[ former( default = true ) ]
dry : bool,
#[ former( default = true ) ]
Expand All @@ -29,8 +32,8 @@ 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" )?;
let PublishProperties { channel, dry, temp } = o.props.try_into()?;
let plan = action::publish_plan( patterns, channel, dry, temp ).context( "Failed to plan the publication process" )?;

let mut formatted_plan = String::new();
writeln!( &mut formatted_plan, "Tree :" )?;
Expand Down Expand Up @@ -75,6 +78,7 @@ mod private
{
let mut this = Self::former();

this = if let Some( v ) = value.get_owned( "channel" ) { this.channel::< Channel >( { let v : String = v; Channel::try_from( v )? } ) } else { this };
this = if let Some( v ) = value.get_owned( "dry" ) { this.dry::< bool >( v ) } else { this };
this = if let Some( v ) = value.get_owned( "temp" ) { this.temp::< bool >( v ) } else { this };

Expand Down
14 changes: 14 additions & 0 deletions module/move/willbe/src/entity/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ mod private
}
}
}

impl TryFrom< String > for Channel
{
type Error = error::for_app::Error;
fn try_from( value : String ) -> Result< Self, Self::Error >
{
Ok( match value.as_ref()
{
"stable" => Self::Stable,
"nightly" => Self::Nightly,
other => error::for_app::bail!( "Unexpected channel value. Expected [stable, channel]. Got: `{other}`" ),
})
}
}

/// Retrieves a list of available channels.
///
Expand Down
8 changes: 8 additions & 0 deletions module/move/willbe/src/entity/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ mod private
use diff::crate_diff;
use version::version_revert;
use error_tools::for_app::Error;
use channel::Channel;

///
#[ derive( Debug, Clone ) ]
Expand Down Expand Up @@ -364,6 +365,7 @@ mod private
{
workspace_dir : CrateDir,
package : Package,
channel : Channel,
base_temp_dir : Option< PathBuf >,
#[ former( default = true ) ]
dry : bool,
Expand All @@ -378,6 +380,7 @@ mod private
let pack = cargo::PackOptions
{
path : crate_dir.as_ref().into(),
channel : self.channel,
allow_dirty : self.dry,
no_verify : self.dry,
temp_path : self.base_temp_dir.clone(),
Expand Down Expand Up @@ -508,6 +511,9 @@ mod private
/// optional as not all operations will require temporary storage. The type used is `PathBuf` which allows
/// manipulation of the filesystem paths.
pub base_temp_dir : Option< PathBuf >,

/// Release channels for rust.
pub channel : Channel,

/// `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.
Expand Down Expand Up @@ -617,6 +623,7 @@ mod private
where
IntoPackage : Into< Package >,
{
let channel = self.storage.channel.unwrap_or_default();
let mut plan = PublishSinglePackagePlanner::former();
if let Some( workspace ) = &self.storage.workspace_dir
{
Expand All @@ -631,6 +638,7 @@ mod private
plan = plan.dry( dry );
}
let plan = plan
.channel( channel )
.package( package )
.perform();
let mut plans = self.storage.plans.unwrap_or_default();
Expand Down
8 changes: 5 additions & 3 deletions module/move/willbe/src/tool/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ mod private
use former::Former;
use process_tools::process::*;
use wtools::error::Result;
use channel::Channel;

/// Represents pack options
#[ derive( Debug, Former, Clone ) ]
pub struct PackOptions
{
pub( crate ) path : PathBuf,
pub( crate ) path : PathBuf,
pub( crate ) channel : Channel,
#[ former( default = true ) ]
pub( crate ) allow_dirty : bool,
#[ former( default = true ) ]
Expand All @@ -36,7 +38,7 @@ mod private
{
fn to_pack_args( &self ) -> Vec< String >
{
[ "package".to_string() ]
[ "run".to_string(), self.channel.to_string(), "cargo".into(), "package".into() ]
.into_iter()
.chain( if self.allow_dirty { Some( "--allow-dirty".to_string() ) } else { None } )
.chain( if self.no_verify { Some( "--no-verify".to_string() ) } else { None } )
Expand All @@ -60,7 +62,7 @@ mod private
)]
pub fn pack( args : PackOptions ) -> Result< Report >
{
let ( program, options ) = ( "cargo", args.to_pack_args() );
let ( program, options ) = ( "rustup", args.to_pack_args() );

if args.dry
{
Expand Down

0 comments on commit 77a5e89

Please sign in to comment.