From 2bd0bb3728beef71918b8e17e26d84da71877934 Mon Sep 17 00:00:00 2001 From: har7an <99636919+har7an@users.noreply.github.com> Date: Sat, 20 Jan 2024 12:47:21 +0000 Subject: [PATCH] xtask: Disable pusing during publish (#3040) * xtask: Add `--no-push` flag to `publish` which can be used when simulating releases to work without a writable git fork of the zellij code. * xtask: Fix borrow issues * xtask/pipe: Require lockfile in publish to avoid errors from invalid dependency versions. * CHANGELOG: Add PR #3040. --- CHANGELOG.md | 1 + xtask/src/flags.rs | 3 +++ xtask/src/pipelines.rs | 10 ++++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 742103fed2..031ba79c07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) * perf(plugins): improve plugin download & load feature (https://github.com/zellij-org/zellij/pull/3001) * chore: bump Rust toolchain to 1.75.0 (https://github.com/zellij-org/zellij/pull/3039) * feat(plugins): introduce pipes to control data flow to plugins from the command line (https://github.com/zellij-org/zellij/pull/3066) +* feat(xtask): allow publishing without pushing changes (https://github.com/zellij-org/zellij/pull/3040) ## [0.39.2] - 2023-11-29 * fix(cli): typo in cli help (https://github.com/zellij-org/zellij/pull/2906) diff --git a/xtask/src/flags.rs b/xtask/src/flags.rs index dd076f5397..1c69362606 100644 --- a/xtask/src/flags.rs +++ b/xtask/src/flags.rs @@ -38,6 +38,8 @@ xflags::xflags! { cmd publish { /// Perform a dry-run (don't push/publish anything) optional --dry-run + /// Publish but don't push a commit to git (only works with '--cargo-registry') + optional --no-push /// Push commit to custom git remote optional --git-remote remote: OsString /// Publish crates to custom registry @@ -159,6 +161,7 @@ pub struct Manpage; #[derive(Debug)] pub struct Publish { pub dry_run: bool, + pub no_push: bool, pub git_remote: Option, pub cargo_registry: Option, } diff --git a/xtask/src/pipelines.rs b/xtask/src/pipelines.rs index 4195af7637..437cefbf25 100644 --- a/xtask/src/pipelines.rs +++ b/xtask/src/pipelines.rs @@ -197,10 +197,11 @@ pub fn publish(sh: &Shell, flags: flags::Publish) -> anyhow::Result<()> { None }; let remote = flags.git_remote.unwrap_or("origin".into()); - let registry = if let Some(registry) = flags.cargo_registry { + let registry = if let Some(ref registry) = flags.cargo_registry { Some(format!( "--registry={}", registry + .clone() .into_string() .map_err(|registry| anyhow::Error::msg(format!( "failed to convert '{:?}' to valid registry name", @@ -212,6 +213,9 @@ pub fn publish(sh: &Shell, flags: flags::Publish) -> anyhow::Result<()> { None }; let registry = registry.as_ref(); + if flags.no_push && flags.cargo_registry.is_none() { + anyhow::bail!("flag '--no-push' can only be used with '--cargo-registry'"); + } sh.change_dir(crate::project_root()); let cargo = crate::cargo().context(err_context)?; @@ -304,6 +308,8 @@ pub fn publish(sh: &Shell, flags: flags::Publish) -> anyhow::Result<()> { // Push commit and tag if flags.dry_run { println!("Skipping push due to dry-run"); + } else if flags.no_push { + println!("Skipping push due to no-push"); } else { cmd!(sh, "git push --atomic {remote} main v{version}") .run() @@ -331,7 +337,7 @@ pub fn publish(sh: &Shell, flags: flags::Publish) -> anyhow::Result<()> { if let Err(err) = cmd!( sh, - "{cargo} publish {registry...} {more_args...} {dry_run...}" + "{cargo} publish --locked {registry...} {more_args...} {dry_run...}" ) .run() .context(err_context)