Skip to content

feat: skip publish=false pkg when publishing entire workspace #15525

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 4 commits into from
May 14, 2025

Conversation

weihanglo
Copy link
Member

@weihanglo weihanglo commented May 14, 2025

What does this PR try to resolve?

Fixes #15006

This changes how cargo-publish works with the unstable
-Zpackage-workspace feature.

Before this, when publishing the entire workspace,
like cargo publish --workspace,
if there is a package with `package.pulibsh=false,
it'll fail the entire publish process.

After this, when --workspace is passed,
or when publishing the virtual workspace,
the intent is more like “publish all publishable in this workspace”,
so skip publish=false packages and proceed to publish others.

The new overall behavior looks like this:

  • cargo publish (inside a package.publish = false package): error
  • cargo publish -p publishable -p unpublishable: error
  • cargo publish --workspace: skips `package.publish = false

See #15006 (comment)

How should we test and review this PR?

  • workspace_flag_with_unpublishable_packages was added to ensure --workspace work with non-virtual workspace.
  • unpublishable_package_as_versioned_dev_dep was added to ensure versioned dev-dependencies won't be skipped and still fail cargo-publish, as they are required to be published.

There is a new scenario that nothing is going to publish.
I went with a warning instead of hard error because missing publish for the entire worspace should be a fairly visible. However, this is open for future to configure via Cargo lint system.

@rustbot
Copy link
Collaborator

rustbot commented May 14, 2025

r? @epage

rustbot has assigned @epage.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-interacts-with-crates.io Area: interaction with registries Command-publish S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 14, 2025
@@ -4103,10 +4103,183 @@ fn multiple_unpublishable_package() {

p.cargo("publish -Zpackage-workspace")
.masquerade_as_nightly_cargo(&["package-workspace"])
.replace_crates_io(registry.index_url())
.with_stderr_data(str![[r#"
[WARNING] nothing to publish, but found 2 unpublishable packages
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test isn't serving is no longer serving its purpose. We should add a publishable package to it and add a new test for "all are unpublishable".

@@ -4103,10 +4103,183 @@ fn multiple_unpublishable_package() {

p.cargo("publish -Zpackage-workspace")
.masquerade_as_nightly_cargo(&["package-workspace"])
.replace_crates_io(registry.index_url())
.with_stderr_data(str![[r#"
[WARNING] nothing to publish, but found 2 unpublishable packages
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a new scenario that nothing is going to publish.
I went with a warning instead of hard error because missing publish for the entire worspace should be a fairly visible. However, this is open for future to configure via Cargo lint system.

What happens if I do cargo check --bins and none are built due to required-features?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: target filter `bins` specified, but no targets matched; this is a no-op
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.03s

@@ -705,19 +745,6 @@ fn package_list(pkgs: impl IntoIterator<Item = PackageId>, final_sep: &str) -> S
}

fn validate_registry(pkgs: &[&Package], reg_or_index: Option<&RegistryOrIndex>) -> CargoResult<()> {
let unpublishable = pkgs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit, feel free to pass on. I'm mentioning this only since I had other comments.

Would make reviewing easier if ĵust moving this error check was a separate refactor commit.

@epage
Copy link
Contributor

epage commented May 14, 2025

Is there a reason this isn't marked as fixing #15006?

@weihanglo weihanglo force-pushed the package-workspace branch from c8ee810 to c364369 Compare May 14, 2025 05:12
weihanglo added 3 commits May 14, 2025 01:21
This changes how cargo-publish works with the unstable
`-Zpackage-workspace` feature.

Before this, when publishing the entire workspace,
like `cargo publish --workspace`,
if there is a package with `package.pulibsh=false,
it'll fail the entire publish process.

After this, when `--workspace` is passed,
or when publishing the virtual workspace,
the intent is more like “publish all publishable in this workspace”,
so skip `publish=false` packages and proceed to publish others.

The new overall behavior looks like this:

- `cargo publish` (inside a `package.publish = false` package): error
- `cargo publish -p publishable -p unpublishable`: error
- `cargo publish --workspace`: skips `package.publish = false

See rust-lang#15006 (comment)
This doesn't need to be an hard error because missing
publish for the entire worspace should be a fairly visible.
However, this is open for future to configure via Cargo lint system.
@weihanglo weihanglo force-pushed the package-workspace branch from c364369 to 090dcfe Compare May 14, 2025 05:23
@weihanglo
Copy link
Member Author

All review comments were addressed.

Is there a reason this isn't marked as fixing #15006?

I forgot 😬.

@epage epage enabled auto-merge May 14, 2025 05:31
@epage
Copy link
Contributor

epage commented May 14, 2025

Thanks!

@epage epage added this pull request to the merge queue May 14, 2025
Merged via the queue into rust-lang:master with commit a14791c May 14, 2025
23 checks passed
bors added a commit to rust-lang-ci/rust that referenced this pull request May 16, 2025
Update cargo

5 commits in 056f5f4f3c100cb36b5e9aed2d20b9ea70aae295..47c911e9e6f6461f90ce19142031fe16876a3b95
2025-05-09 14:54:18 +0000 to 2025-05-14 17:53:17 +0000
- Stabilize doctest-xcompile (rust-lang/cargo#15462)
- feat: skip `publish=false` pkg when publishing entire workspace (rust-lang/cargo#15525)
- chore: bump to 0.90.0; update changelog (rust-lang/cargo#15520)
- chore(triagebot): add `[no-mentions]` and `[note]` (rust-lang/cargo#15517)
- add glob pattern support for known_hosts (rust-lang/cargo#15508)

r? ghost
@rustbot rustbot added this to the 1.89.0 milestone May 16, 2025
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request May 19, 2025
Update cargo

5 commits in 056f5f4f3c100cb36b5e9aed2d20b9ea70aae295..47c911e9e6f6461f90ce19142031fe16876a3b95
2025-05-09 14:54:18 +0000 to 2025-05-14 17:53:17 +0000
- Stabilize doctest-xcompile (rust-lang/cargo#15462)
- feat: skip `publish=false` pkg when publishing entire workspace (rust-lang/cargo#15525)
- chore: bump to 0.90.0; update changelog (rust-lang/cargo#15520)
- chore(triagebot): add `[no-mentions]` and `[note]` (rust-lang/cargo#15517)
- add glob pattern support for known_hosts (rust-lang/cargo#15508)

r? ghost
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-interacts-with-crates.io Area: interaction with registries Command-publish S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cargo publish should optionally skip unpublishable packages
3 participants