-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Ensure configured owners are set
Example use case: Automatically add the clap maintainers group as new crates get published. I went ahead and made it so this always runs and not just after first-publish so its easy to set owners after-the-fact. Maybe we should make a distinction on that between `cargo release` and `cargo release owner` Fixes #529
- Loading branch information
Showing
7 changed files
with
250 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
use crate::error::CliError; | ||
use crate::ops::git; | ||
use crate::steps::plan; | ||
|
||
/// Owner the specified packages | ||
/// | ||
/// Will automatically skip published versions | ||
#[derive(Debug, Clone, clap::Args)] | ||
pub struct OwnerStep { | ||
#[command(flatten)] | ||
manifest: clap_cargo::Manifest, | ||
|
||
#[command(flatten)] | ||
workspace: clap_cargo::Workspace, | ||
|
||
/// Custom config file | ||
#[arg(short, long = "config")] | ||
custom_config: Option<String>, | ||
|
||
/// Ignore implicit configuration files. | ||
#[arg(long)] | ||
isolated: bool, | ||
|
||
/// Comma-separated globs of branch names a release can happen from | ||
#[arg(long, value_delimiter = ',')] | ||
allow_branch: Option<Vec<String>>, | ||
|
||
/// Actually perform a release. Dry-run mode is the default | ||
#[arg(short = 'x', long)] | ||
execute: bool, | ||
|
||
/// Skip release confirmation and version preview | ||
#[arg(long)] | ||
no_confirm: bool, | ||
} | ||
|
||
impl OwnerStep { | ||
pub fn run(&self) -> Result<(), CliError> { | ||
git::git_version()?; | ||
|
||
let ws_meta = self | ||
.manifest | ||
.metadata() | ||
// When evaluating dependency ordering, we need to consider optional dependencies | ||
.features(cargo_metadata::CargoOpt::AllFeatures) | ||
.exec()?; | ||
let config = self.to_config(); | ||
let ws_config = crate::config::load_workspace_config(&config, &ws_meta)?; | ||
let mut pkgs = plan::load(&config, &ws_meta)?; | ||
|
||
let (_selected_pkgs, excluded_pkgs) = self.workspace.partition_packages(&ws_meta); | ||
for excluded_pkg in excluded_pkgs { | ||
let pkg = if let Some(pkg) = pkgs.get_mut(&excluded_pkg.id) { | ||
pkg | ||
} else { | ||
// Either not in workspace or marked as `release = false`. | ||
continue; | ||
}; | ||
pkg.config.publish = Some(false); | ||
pkg.config.owners = Some(vec![]); | ||
pkg.config.release = Some(false); | ||
|
||
let crate_name = pkg.meta.name.as_str(); | ||
log::debug!("Disabled by user, skipping {}", crate_name,); | ||
} | ||
|
||
let pkgs = plan::plan(pkgs)?; | ||
|
||
let (selected_pkgs, _excluded_pkgs): (Vec<_>, Vec<_>) = pkgs | ||
.into_iter() | ||
.map(|(_, pkg)| pkg) | ||
.partition(|p| p.config.release()); | ||
if selected_pkgs.is_empty() { | ||
log::info!("No packages selected."); | ||
return Err(2.into()); | ||
} | ||
|
||
let dry_run = !self.execute; | ||
let mut failed = false; | ||
|
||
// STEP 0: Help the user make the right decisions. | ||
failed |= !super::verify_git_is_clean( | ||
ws_meta.workspace_root.as_std_path(), | ||
dry_run, | ||
log::Level::Error, | ||
)?; | ||
|
||
failed |= !super::verify_git_branch( | ||
ws_meta.workspace_root.as_std_path(), | ||
&ws_config, | ||
dry_run, | ||
log::Level::Error, | ||
)?; | ||
|
||
failed |= !super::verify_if_behind( | ||
ws_meta.workspace_root.as_std_path(), | ||
&ws_config, | ||
dry_run, | ||
log::Level::Warn, | ||
)?; | ||
|
||
// STEP 1: Release Confirmation | ||
super::confirm("Owner", &selected_pkgs, self.no_confirm, dry_run)?; | ||
|
||
ensure_owners(&selected_pkgs, dry_run)?; | ||
|
||
super::finish(failed, dry_run) | ||
} | ||
|
||
fn to_config(&self) -> crate::config::ConfigArgs { | ||
crate::config::ConfigArgs { | ||
custom_config: self.custom_config.clone(), | ||
isolated: self.isolated, | ||
allow_branch: self.allow_branch.clone(), | ||
..Default::default() | ||
} | ||
} | ||
} | ||
|
||
pub fn ensure_owners(pkgs: &[plan::PackageRelease], dry_run: bool) -> Result<(), CliError> { | ||
for pkg in pkgs { | ||
if !pkg.config.publish() { | ||
continue; | ||
} | ||
|
||
let crate_name = pkg.meta.name.as_str(); | ||
crate::ops::cargo::ensure_owners( | ||
crate_name, | ||
pkg.config.owners(), | ||
pkg.config.registry(), | ||
dry_run, | ||
)?; | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters