Skip to content

Commit 0920140

Browse files
authored
Merge pull request #1470 from Barsik-sus/willbe_publish_new_options
READY: (willbe): `.publish` and `.publish.diff` new options
2 parents fbef98c + b71a7aa commit 0920140

File tree

7 files changed

+192
-42
lines changed

7 files changed

+192
-42
lines changed

module/move/willbe/src/action/publish.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ mod private
109109
///
110110
/// # Arguments
111111
/// * `patterns` - A vector of patterns specifying the folders to search for packages.
112+
/// * `exclude_dev_dependencies` - A boolean value indicating whether to exclude dev dependencies from manifest before publish.
112113
/// * `dry` - A boolean value indicating whether to perform a dry run.
113114
/// * `temp` - A boolean value indicating whether to use a temporary directory.
114115
///
@@ -119,6 +120,8 @@ mod private
119120
(
120121
patterns : Vec< String >,
121122
channel : channel::Channel,
123+
exclude_dev_dependencies : bool,
124+
commit_changes : bool,
122125
dry : bool,
123126
temp : bool
124127
)
@@ -233,6 +236,8 @@ mod private
233236
.channel( channel )
234237
.workspace_dir( CrateDir::try_from( workspace_root_dir ).unwrap() )
235238
.option_base_temp_dir( dir.clone() )
239+
.exclude_dev_dependencies( exclude_dev_dependencies )
240+
.commit_changes( commit_changes )
236241
.dry( dry )
237242
.roots( roots )
238243
.packages( queue )

module/move/willbe/src/action/publish_diff.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ mod private
2222
pub struct PublishDiffOptions
2323
{
2424
path : PathBuf,
25+
exclude_dev_dependencies : bool,
2526
keep_archive : Option< PathBuf >,
2627
}
2728

@@ -141,16 +142,17 @@ mod private
141142
let name = &package.name()?;
142143
let version = &package.version()?;
143144

144-
_ = cargo::pack
145-
(
146-
cargo::PackOptions::former()
147-
.path( dir.as_ref() )
148-
.allow_dirty( true )
149-
.checking_consistency( false )
150-
.dry( false ).form()
151-
)?;
152-
let l = CrateArchive::read( packed_crate::local_path( name, version, dir )? )?;
153-
let r = CrateArchive::download_crates_io( name, version ).unwrap();
145+
_ = cargo::pack
146+
(
147+
cargo::PackOptions::former()
148+
.path( dir.as_ref() )
149+
.allow_dirty( true )
150+
.checking_consistency( false )
151+
.exclude_dev_dependencies( o.exclude_dev_dependencies)
152+
.dry( false ).form()
153+
)?;
154+
let l = CrateArchive::read( packed_crate::local_path( name, version, dir )? )?;
155+
let r = CrateArchive::download_crates_io( name, version ).unwrap();
154156

155157

156158
if let Some( out_path ) = &o.keep_archive

module/move/willbe/src/command/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ mod private
2525
.kind( Type::String )
2626
.optional( true )
2727
.end()
28+
.property( "exclude_dev_dependencies" )
29+
.hint( "Setting this option to true will temporarily remove development dependencies before executing the command, then restore them afterward. Default is `true`." )
30+
.kind( Type::Bool )
31+
.optional( true )
32+
.end()
33+
.property( "commit_changes" )
34+
.hint( "Indicates whether changes should be committed. Default is `false`." )
35+
.kind( Type::Bool )
36+
.optional( true )
37+
.end()
2838
.property( "dry" )
2939
.hint( "Enables 'dry run'. Does not publish, only simulates. Default is `true`." )
3040
.kind( Type::Bool )
@@ -47,6 +57,11 @@ mod private
4757
.kind( Type::Path )
4858
.optional( true )
4959
.end()
60+
.property( "exclude_dev_dependencies" )
61+
.hint( "Setting this option to true will temporarily remove development dependencies before executing the command, then restore them afterward. Default is `true`." )
62+
.kind( Type::Bool )
63+
.optional( true )
64+
.end()
5065
.property( "keep_archive" )
5166
.hint( "Save remote package version to the specified path" )
5267
.kind( Type::Path )

module/move/willbe/src/command/publish.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ mod private
1515
{
1616
#[ former( default = Channel::Stable ) ]
1717
channel : Channel,
18+
#[ former( default = false ) ]
19+
exclude_dev_dependencies : bool,
20+
#[ former( default = false ) ]
21+
commit_changes : bool,
1822
#[ former( default = true ) ]
1923
dry : bool,
2024
#[ former( default = true ) ]
@@ -52,10 +56,12 @@ mod private
5256
let PublishProperties
5357
{
5458
channel,
59+
exclude_dev_dependencies,
60+
commit_changes,
5561
dry,
5662
temp
5763
} = o.props.try_into()?;
58-
let plan = action::publish_plan( patterns, channel, dry, temp )
64+
let plan = action::publish_plan( patterns, channel, exclude_dev_dependencies, commit_changes, dry, temp )
5965
.context( "Failed to plan the publication process" )?;
6066

6167
let mut formatted_plan = String::new();
@@ -110,6 +116,10 @@ mod private
110116
else
111117
{ this };
112118

119+
this = if let Some( v ) = value
120+
.get_owned( "exclude_dev_dependencies" ) { this.exclude_dev_dependencies::< bool >( v ) } else { this };
121+
this = if let Some( v ) = value
122+
.get_owned( "commit_changes" ) { this.commit_changes::< bool >( v ) } else { this };
113123
this = if let Some( v ) = value
114124
.get_owned( "dry" ) { this.dry::< bool >( v ) } else { this };
115125
this = if let Some( v ) = value

module/move/willbe/src/command/publish_diff.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ mod private
1313
#[ derive( former::Former ) ]
1414
struct PublishDiffProperties
1515
{
16+
#[ former( default = false ) ]
17+
exclude_dev_dependencies : bool,
1618
keep_archive : Option< PathBuf >,
1719
}
1820

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

3840
let mut o = action::PublishDiffOptions::former()
39-
.path( path );
41+
.path( path )
42+
.exclude_dev_dependencies( exclude_dev_dependencies );
4043
if let Some( k ) = keep_archive.clone() { o = o.keep_archive( k ); }
4144
let o = o.form();
4245

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

63+
this = if let Some( v ) = value
64+
.get_owned( "exclude_dev_dependencies" )
65+
{ this.exclude_dev_dependencies::< bool >( v ) }
66+
else
67+
{ this };
68+
6069
this = if let Some( v ) = value
6170
.get_owned( "keep_archive" )
6271
{ this.keep_archive::< PathBuf >( v ) }

module/move/willbe/src/entity/publish.rs

Lines changed: 63 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ mod private
2626
/// Options for bumping the package version.
2727
pub bump : version::BumpOptions,
2828
/// Git options related to the package.
29-
pub git_options : entity::git::GitOptions,
29+
pub git_options : Option< entity::git::GitOptions >,
3030
/// Options for publishing the package using Cargo.
3131
pub publish : cargo::PublishOptions,
3232
/// Indicates whether the process should be dry-run (no actual publishing).
@@ -42,6 +42,9 @@ mod private
4242
package : package::Package< 'a >,
4343
channel : channel::Channel,
4444
base_temp_dir : Option< path::PathBuf >,
45+
exclude_dev_dependencies : bool,
46+
#[ former( default = true ) ]
47+
commit_changes : bool,
4548
#[ former( default = true ) ]
4649
dry : bool,
4750
}
@@ -58,6 +61,7 @@ mod private
5861
channel : self.channel,
5962
allow_dirty : self.dry,
6063
checking_consistency : !self.dry,
64+
exclude_dev_dependencies : self.exclude_dev_dependencies,
6165
temp_path : self.base_temp_dir.clone(),
6266
dry : self.dry,
6367
};
@@ -73,17 +77,21 @@ mod private
7377
dependencies : dependencies.clone(),
7478
dry : self.dry,
7579
};
76-
let git_options = entity::git::GitOptions
80+
let git_options = if self.commit_changes
7781
{
78-
git_root : workspace_root,
79-
items : dependencies.iter().chain([ &crate_dir ]).map( | d | d.clone().absolute_path().join( "Cargo.toml" ) ).collect(),
80-
message : format!( "{}-v{}", self.package.name().unwrap(), new_version ),
81-
dry : self.dry,
82-
};
82+
Some( entity::git::GitOptions
83+
{
84+
git_root : workspace_root,
85+
items : dependencies.iter().chain([ &crate_dir ]).map( | d | d.clone().absolute_path().join( "Cargo.toml" ) ).collect(),
86+
message : format!( "{}-v{}", self.package.name().unwrap(), new_version ),
87+
dry : self.dry,
88+
})
89+
} else { None };
8390
let publish = cargo::PublishOptions
8491
{
8592
path : crate_dir.clone().absolute_path().inner(),
8693
temp_path : self.base_temp_dir.clone(),
94+
exclude_dev_dependencies : self.exclude_dev_dependencies,
8795
retry_count : 2,
8896
dry : self.dry,
8997
};
@@ -121,6 +129,14 @@ mod private
121129
/// Release channels for rust.
122130
pub channel : channel::Channel,
123131

132+
/// Setting this option to true will temporarily remove development dependencies before executing the command, then restore them afterward.
133+
#[ allow( dead_code ) ] // former related
134+
pub exclude_dev_dependencies : bool,
135+
136+
/// Indicates whether changes should be committed.
137+
#[ former( default = true ) ]
138+
pub commit_changes : bool,
139+
124140
/// `dry` - A boolean value indicating whether to do a dry run. If set to `true`, the application performs
125141
/// a simulated run without making any actual changes. If set to `false`, the operations are actually executed.
126142
/// This property is optional and defaults to `true`.
@@ -246,6 +262,14 @@ mod private
246262
{
247263
plan = plan.dry( dry );
248264
}
265+
if let Some( exclude_dev_dependencies ) = &self.storage.exclude_dev_dependencies
266+
{
267+
plan = plan.exclude_dev_dependencies( *exclude_dev_dependencies )
268+
}
269+
if let Some( commit_changes ) = &self.storage.commit_changes
270+
{
271+
plan = plan.commit_changes( *commit_changes )
272+
}
249273
let plan = plan
250274
.channel( channel )
251275
.package( package )
@@ -362,45 +386,55 @@ mod private
362386
} = instruction;
363387
pack.dry = dry;
364388
bump.dry = dry;
365-
git_options.dry = dry;
389+
git_options.as_mut().map( | d | d.dry = dry );
366390
publish.dry = dry;
367391

368392
report.get_info = Some( cargo::pack( pack ).err_with_report( &report )? );
369393
// aaa : redundant field? // aaa : removed
370394
let bump_report = version::bump( bump ).err_with_report( &report )?;
371395
report.bump = Some( bump_report.clone() );
372-
let git_root = git_options.git_root.clone();
373-
let git = match entity::git::perform_git_commit( git_options )
396+
397+
let git_root = git_options.as_ref().map( | g | g.git_root.clone() );
398+
if let Some( git_options ) = git_options
374399
{
375-
Ok( git ) => git,
376-
Err( e ) =>
400+
let git = match entity::git::perform_git_commit( git_options )
377401
{
378-
version::revert( &bump_report )
379-
.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" ) ) )
380-
.err_with_report( &report )?;
381-
return Err(( report, e ));
382-
}
383-
};
384-
report.add = git.add;
385-
report.commit = git.commit;
402+
Ok( git ) => git,
403+
Err( e ) =>
404+
{
405+
version::revert( &bump_report )
406+
.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" ) ) )
407+
.err_with_report( &report )?;
408+
return Err(( report, e ));
409+
}
410+
};
411+
report.add = git.add;
412+
report.commit = git.commit;
413+
}
386414
report.publish = match cargo::publish( publish )
387415
{
388416
Ok( publish ) => Some( publish ),
389417
Err( e ) =>
390418
{
391-
tool::git::reset( git_root.as_ref(), true, 1, false )
392-
.map_err
393-
(
394-
| le |
395-
format_err!( "Base error:\n{}\nRevert error:\n{}", e.to_string().replace( '\n', "\n\t" ), le.to_string().replace( '\n', "\n\t" ) )
396-
)
397-
.err_with_report( &report )?;
419+
if let Some( git_root ) = git_root.as_ref()
420+
{
421+
tool::git::reset( git_root.as_ref(), true, 1, false )
422+
.map_err
423+
(
424+
| le |
425+
format_err!( "Base error:\n{}\nRevert error:\n{}", e.to_string().replace( '\n', "\n\t" ), le.to_string().replace( '\n', "\n\t" ) )
426+
)
427+
.err_with_report( &report )?;
428+
}
398429
return Err(( report, e ));
399430
}
400431
};
401432

402-
let res = tool::git::push( &git_root, dry ).err_with_report( &report )?;
403-
report.push = Some( res );
433+
if let Some( git_root ) = git_root.as_ref()
434+
{
435+
let res = tool::git::push( &git_root, dry ).err_with_report( &report )?;
436+
report.push = Some( res );
437+
}
404438

405439
Ok( report )
406440
}

0 commit comments

Comments
 (0)