Skip to content

Commit

Permalink
feat: add 'publish_all_features' config option to workspace/package c…
Browse files Browse the repository at this point in the history
…onfig (#1818)

Co-authored-by: Marco Ieni <[email protected]>
  • Loading branch information
sd2k and MarcoIeni authored Nov 8, 2024
1 parent d16b3cc commit 4631537
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .schema/latest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -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.",
Expand Down
7 changes: 7 additions & 0 deletions crates/release_plz/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ impl From<PackageConfig> 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);
}
Expand Down Expand Up @@ -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<Vec<String>>,
/// # Publish All Features
/// If `true`, add the `--all-features` flag to the `cargo publish` command.
pub publish_all_features: Option<bool>,
/// # Semver Check
/// Controls when to run cargo-semver-checks.
/// If unspecified, run cargo-semver-checks if the package is a library.
Expand Down Expand Up @@ -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),
Expand Down
17 changes: 17 additions & 0 deletions crates/release_plz_core/src/command/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<SecretString>> {
let is_registry_same_as_request = self.registry.as_deref() == registry;
Expand Down Expand Up @@ -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<String>,
/// 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<Utf8PathBuf>,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}

Expand Down
15 changes: 15 additions & 0 deletions website/docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 4631537

Please sign in to comment.