From 46315376883f35755493c05d76c61b2a9d6f1166 Mon Sep 17 00:00:00 2001 From: Ben Sully Date: Fri, 8 Nov 2024 08:11:57 +0000 Subject: [PATCH] feat: add 'publish_all_features' config option to workspace/package config (#1818) Co-authored-by: Marco Ieni <11428655+MarcoIeni@users.noreply.github.com> --- .schema/latest.json | 17 +++++++++++++++++ crates/release_plz/src/config.rs | 7 +++++++ crates/release_plz_core/src/command/release.rs | 17 +++++++++++++++++ website/docs/config.md | 15 +++++++++++++++ 4 files changed, 56 insertions(+) diff --git a/.schema/latest.json b/.schema/latest.json index ff75c16098..51ce7ff9a9 100644 --- a/.schema/latest.json +++ b/.schema/latest.json @@ -56,6 +56,7 @@ "pr_labels": [], "pr_name": null, "publish": null, + "publish_all_features": null, "publish_allow_dirty": null, "publish_features": null, "publish_no_verify": null, @@ -371,6 +372,14 @@ "null" ] }, + "publish_all_features": { + "title": "Publish All Features", + "description": "If `true`, add the `--all-features` flag to the `cargo publish` command.", + "type": [ + "boolean", + "null" + ] + }, "publish_allow_dirty": { "title": "Publish Allow Dirty", "description": "If `true`, add the `--allow-dirty` flag to the `cargo publish` command.", @@ -653,6 +662,14 @@ "null" ] }, + "publish_all_features": { + "title": "Publish All Features", + "description": "If `true`, add the `--all-features` flag to the `cargo publish` command.", + "type": [ + "boolean", + "null" + ] + }, "publish_allow_dirty": { "title": "Publish Allow Dirty", "description": "If `true`, add the `--allow-dirty` flag to the `cargo publish` command.", diff --git a/crates/release_plz/src/config.rs b/crates/release_plz/src/config.rs index fa55e9ade4..b916c668a3 100644 --- a/crates/release_plz/src/config.rs +++ b/crates/release_plz/src/config.rs @@ -235,6 +235,9 @@ impl From for release_plz_core::ReleaseConfig { if let Some(features) = value.publish_features { cfg = cfg.with_features(features); } + if let Some(all_features) = value.publish_all_features { + cfg = cfg.with_all_features(all_features); + } if let Some(allow_dirty) = value.publish_allow_dirty { cfg = cfg.with_allow_dirty(allow_dirty); } @@ -319,6 +322,9 @@ pub struct PackageConfig { /// # Publish Features /// If `["a", "b", "c"]`, add the `--features=a,b,c` flag to the `cargo publish` command. pub publish_features: Option>, + /// # Publish All Features + /// If `true`, add the `--all-features` flag to the `cargo publish` command. + pub publish_all_features: Option, /// # Semver Check /// Controls when to run cargo-semver-checks. /// If unspecified, run cargo-semver-checks if the package is a library. @@ -372,6 +378,7 @@ impl PackageConfig { publish_allow_dirty: self.publish_allow_dirty.or(default.publish_allow_dirty), publish_no_verify: self.publish_no_verify.or(default.publish_no_verify), publish_features: self.publish_features.or(default.publish_features), + publish_all_features: self.publish_all_features.or(default.publish_all_features), git_tag_enable: self.git_tag_enable.or(default.git_tag_enable), git_tag_name: self.git_tag_name.or(default.git_tag_name), release: self.release.or(default.release), diff --git a/crates/release_plz_core/src/command/release.rs b/crates/release_plz_core/src/command/release.rs index c2dddd8b93..f38a866079 100644 --- a/crates/release_plz_core/src/command/release.rs +++ b/crates/release_plz_core/src/command/release.rs @@ -180,6 +180,11 @@ impl ReleaseRequest { config.features.clone() } + pub fn all_features(&self, package: &str) -> bool { + let config = self.get_package_config(package); + config.all_features + } + /// Find the token to use for the given `registry` ([`Option::None`] means crates.io). fn find_registry_token(&self, registry: Option<&str>) -> anyhow::Result> { let is_registry_same_as_request = self.registry.as_deref() == registry; @@ -243,6 +248,9 @@ pub struct ReleaseConfig { /// Features to be enabled when packaging the crate. /// If non-empty, pass the `--features` flag to `cargo publish`. features: Vec, + /// Enable all features when packaging the crate. + /// If true, pass the `--all-features` flag to `cargo publish`. + all_features: bool, /// High-level toggle to process this package or ignore it release: bool, changelog_path: Option, @@ -282,6 +290,11 @@ impl ReleaseConfig { self } + pub fn with_all_features(mut self, all_features: bool) -> Self { + self.all_features = all_features; + self + } + pub fn with_release(mut self, release: bool) -> Self { self.release = release; self @@ -315,6 +328,7 @@ impl Default for ReleaseConfig { no_verify: false, allow_dirty: false, features: vec![], + all_features: false, release: true, changelog_path: None, changelog_update: true, @@ -877,6 +891,9 @@ fn run_cargo_publish( args.push("--features"); args.push(&features); } + if input.all_features(&package.name) { + args.push("--all-features"); + } run_cargo(workspace_root, &args) } diff --git a/website/docs/config.md b/website/docs/config.md index 429a662d68..2bc6419785 100644 --- a/website/docs/config.md +++ b/website/docs/config.md @@ -42,6 +42,7 @@ name = "package_b" semver_check = true # enable semver_check for `package_b` publish_no_verify = true # add `--no-verify` to `cargo publish` for `package_b` publish_features = ["a", "b"] # add `--features=a,b` to `cargo publish` for `package_b` +publish_all_features = true # add `--all-features` to `cargo publish` for `package_b` [[package]] name = "package_c" @@ -80,6 +81,7 @@ the following sections: - [`publish_allow_dirty`](#the-publish_allow_dirty-field) — Package dirty directories. - [`publish_no_verify`](#the-publish_no_verify-field) — Don't verify package build. - [`publish_features`](#the-publish_features-field) — List of features to pass to `cargo publish`. + - [`publish_all_features`](#the-publish_all_features-field) — Pass `--all-features` to `cargo publish`. - [`publish_timeout`](#the-publish_timeout-field) — `cargo publish` timeout. - [`release`](#the-release-field) - Enable the processing of the packages. - [`release_always`](#the-release_always-field) - Release always or when you merge the release PR only. @@ -106,6 +108,8 @@ the following sections: - [`publish_no_verify`](#the-publish_no_verify-field-package-section) — Don't verify package build. - [`publish_features`](#the-publish_features-field-package-section) — List of features to pass to `cargo publish`. + - [`publish_all_features`](#the-publish_all_features-field-package-section) + — Pass `--all-features` to `cargo publish`. - [`release`](#the-release-field-package-section) - Enable the processing of this package. - [`semver_check`](#the-semver_check-field-package-section) — Run [cargo-semver-checks]. - [`version_group`](#the-version_group-field) — Group of packages with the same version. @@ -456,6 +460,13 @@ Pass a list of features to use for verification by `cargo publish`. `cargo publish`. - If not set or if it is empty, no list of features will be passed to `cargo publish`. +#### The `publish_all_features` field + +Whether to pass the `--all-features` to `cargo publish` when verifying. + +- If `true`, `release-plz` adds the `--all-features` flag to `cargo publish`. +- If `false`, `release-plz` doesn't add the `--all-features` flag to `cargo publish`. + #### The `publish_timeout` field The timeout used when: @@ -704,6 +715,10 @@ Overrides the [`workspace.publish_no_verify`](#the-publish_no_verify-field) fiel Overrides the [`workspace.publish_features`](#the-publish_features-field) field. +#### The `publish_all_features` field (`package` section) + +Overrides the [`workspace.publish_all_features`](#the-publish_all_features-field) field. + #### The `release` field (`package` section) Overrides the [`workspace.release`](#the-release-field) field.