-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cargo publish should be opt-in #6153
Comments
My initial inclination is against doing something like this, but I could be convinced. There are a few barriers already against accidentally publishing:
My own experience of publishing is that I almost always run afoul of one of the existing checks when I go to publish - usually I haven't set a license or description field. Often the code you don't want to publish is a project you intend to publish someday (and you may have already published a previous version of it). Its perfectly possible to set the publish bit and then run More succinctly, the only interface that will prevent people from accidentally publishing is to disallow publishing entirely. I don't think accidental publishing happens often enough right now that there need to be more roadblocks than there already are. |
I agree that accidentally publishing is probably a niche issue, but I don't see how yours are arguments against this proposal, so much as they are arguments that in your experience it's unnecessary. One way to think about it is this: if we're going to have a As for the other barriers, I think they should all remain, but none of them are as explicit as "I don't want this published". For example, you might choose to not set a license, or not log in, simply because you don't want to publish. But in a year's time, you're unlikely to remember that. The advantage of the |
cc @rust-lang/cargo, others likely have thoughts on this as well! |
My initial feeling is -0 (weakly opposed). I don't feel strongly about this, it just feels like a bit of an unnecessary stumbling block in a new project. I can absolutely understand the desire to make sure people don't publish accidentally, however. |
I think I want to have things publishable by default (less friction, expected behavior for open source projects) but would like to have the option to opt out for commercial ones. |
@ralfbiedert that's the current behavior via the |
There are actions that are reversible and actions that are irreversible. Another idea is to allow 5 minutes staging time to delete the published crate on crates.io. |
Publishing a new crate or a new stable version of a crate is pretty rare. |
@LucianBuzzo The point that people might accidentally (or lazily) have secrets in code they don't intend to publish is a good point I hadn't thought of. Personally, I find the current behaviour at odds with the usual approach to safety in Rust. Publishing code (especially to crates.io, which has no easy removal mechanism) is an "unsafe" action, therefore it should require some explicit opt-in on the part of a human. |
That's almost implemented via rustc compilation times -- there's usually plenty of time after typing
The only time I ran I tend to (weakly) agree with the opinions already expressed that the current behaviour is not too bad -- there are many "irreversible" commands one can run (e.g. From the 3 solutions proposed by the OP, 1 seems particularly unappealing as the default should be open source, not a corporate environment (writing this as someone who mostly uses Rust in a closed source corporate env). |
Sorry, you didn't mention my last proposal - all args mandatory:
I suppose developers use the bash history for all the frequent commands. Also for this. |
There are 2 extreme philosofies and a big gray area between:
Javascript and dynamic languages are very comfortable. You dont need to think about types or lifetimes. But that is also less secure when later refactoring. The compiler will not help you to spot errors. |
As an alternative to changing defaults, would it be more palatable to allow users to specify a behavior for new projects in their config.toml hierarchy? This is already an option for name, email, and vcs. [cargo-new]
# Avoid publishing my hello_world projects
publish = false
email = "test@example.com" Would it make more sense to allow specifying all defaults for cargo-new's manifest, bypassing the special-casing for name/email/vcs? [cargo-new.default-manifest]
[cargo-new.default-manifest.package]
edition = 2018
publish = false
license = "MIT"
[cargo-new.default-manifest.badges]
maintenance = { status = "experimental" } |
Maybe an approach like |
I think I like option 3 the most. It could show the crate name and what registry index it will be published to, and prompt for the crate name instead of asking Yes/No, to stop the people that won't check the crate name from shooting themselves in the foot. The prompt could be disabled with a cli opt, in config.toml, and maybe be disabled by default if there's no tty. |
So, this conversation fizzled out. Having reviewed the above discussion, my argument is that: Priors:
Thus, we have a risk of something very rare but potentially also very damaging (always difficult to deal with proportionally) and also a risk that "fixing" it may introduce annoyances. My suggestion is therefore to de-risk by making the unsafe option explicitly opt-in in the simplest way possible, but also to use the error message(s) to provide useful feedback about how to publish (thus turning the stumbling block instead into a teaching moment). Suggestion:
I hope this strikes a good balance between safety and ergonomics (doesn't that sound like Rust 😉 ) |
I have something to add here that I haven't seen discussed which has almost slipped me up several times. The cargo release project, which is used by quite a few people, will publish your crate when cutting a new version if |
Disclaimer: I'm new to publishing crates (I uploaded my first crate yesterday). I am also worried about accidentally publishing something that I don't want to publish (and if I understand it right, then Update: Publishing untracked files only seems to happen only with Mercurial, but not with Git. |
I almost accidentally pushed my crate for my employer to crates.io because I've misunderstood something with the configuration of registry:s First time publishing a crate should maybe prompt some extra security. Like "Are you sure these files ..... will be uploaded to crates.io/xx/yy" ?! Thank god I've not configured an access token to crates.io |
Shouldn't have marked this closed by #12786. We've now made |
Thanks for re-opening. I agree that #12786 (while a positive change) does not close this issue. Not least because "this is now opt-in if you do this non-default thing" is the definition of opt-out, not opt-in. Previous commenters have pointed to other barriers to publishing (logging in, licence set, description set, etc.), but I think my main problem with all of them is that they are proxies and I don't think that Cargo should lean on implicit proxies for interaction design that can stop a footgun. I think it should explicitly design against footguns, which defaulting Again, happy to write a PR for this if the maintainers can be persuaded that it is the right thing to do. |
We already established that the command For backward compatibility an explicit # publish to registry crates.io. Only this files.
publish = true
registry= crates.io
include = [
"Cargo.toml",
"LICENSE",
"README.md",
"src/*"
] |
Aren't $ cargo add bitflags && cargo check -p bitflags --example fmt I don't know whether omitting those targets would do any harm in practice, but at least that doesn't seem to be no-op. Anyway, I think that making I think the option 2. proposed in OP is the most uncontroversial change for starter, as there is a precedent for changing the default manifest, that is, I wonder if there is a motivation against this approach: in particular, does #6153 (comment) still stand? |
After some discussion on zulip, here's what I propose:
Per the contributing guide, if this issue is marked as |
Publishing, whether to crates.io or elsewhere, should be opt-in rather by on-by-default. Although rare, people do sometimes publish accidentally. Given that the default is currently to publish to crates.io publicly, this is potentially dangerous for using cargo in a corporate closed-source environment. My guess is that even most always-intended-to-be-open-source projects would rather keep things private until they're ready for some sort of release.
I see several options for making this work:Havecargo new
addpublish = false
orpublish = []
or equivalent in the defaultCargo.toml
. This is probably the most minor change and I can't imagine this will break any existing uses.Change the behaviour so thatpublish = true
inCargo.toml
is required forcargo publish
to work, with an error message explaining this. This might break workflow for some existing projects, but it would be a very easy fix.Change the behaviour ofcargo publish
so that if there is nopublish = True
inCargo.toml
it interactively asks whether you're sure. Possibly with a-y
/--yes
option (a laapt install
) to automatically say "yes".Personally, I'd prefer both 1 and 2. I'd be happy to make a PR if people like this idea.Originally raised as an idea on #6123, but was decided it belonged as a separate issue.
Proposal as per this comment is to change the default Cargo.toml generated by
cargo new
to includepublish = false
with a comment pointing towards documentation about publishing.A separate issue will be opened to cover breaking changes to behaviour to be targeted at an edition boundary.
The text was updated successfully, but these errors were encountered: