Skip to content

fix(publish): Don't tell people to ctrl-c without knowing consequences #15632

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

Merged
merged 5 commits into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 46 additions & 28 deletions src/cargo/ops/registry/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,52 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
DEFAULT_TIMEOUT
};
if 0 < timeout {
let source_description = source.source_id().to_string();
let short_pkg_descriptions = package_list(to_confirm.iter().copied(), "or");
if plan.is_empty() {
opts.gctx.shell().note(format!(
"waiting for {short_pkg_descriptions} to be available at {source_description}.\n\
You may press ctrl-c to skip waiting; the {crate} should be available shortly.",
crate = if to_confirm.len() == 1 { "crate" } else {"crates"}
))?;
} else {
opts.gctx.shell().note(format!(
"waiting for {short_pkg_descriptions} to be available at {source_description}.\n\
{count} remaining {crate} to be published",
count = plan.len(),
crate = if plan.len() == 1 { "crate" } else {"crates"}
))?;
}

let timeout = Duration::from_secs(timeout);
wait_for_any_publish_confirmation(
let confirmed = wait_for_any_publish_confirmation(
opts.gctx,
source_ids.original,
&to_confirm,
timeout,
)?
)?;
if !confirmed.is_empty() {
let short_pkg_description = package_list(confirmed.iter().copied(), "and");
opts.gctx.shell().status(
"Published",
format!("{short_pkg_description} at {source_description}"),
)?;
} else {
let short_pkg_descriptions = package_list(to_confirm.iter().copied(), "or");
opts.gctx.shell().warn(format!(
"timed out waiting for {short_pkg_descriptions} to be available in {source_description}",
))?;
opts.gctx.shell().note(format!(
"the registry may have a backlog that is delaying making the \
{crate} available. The {crate} should be available soon.",
crate = if to_confirm.len() == 1 {
"crate"
} else {
"crates"
}
))?;
}
confirmed
} else {
BTreeSet::new()
}
Expand Down Expand Up @@ -317,17 +356,10 @@ fn wait_for_any_publish_confirmation(
// of independent progress bars can be a little confusing. There is an
// overall progress bar managed here.
source.set_quiet(true);
let source_description = source.source_id().to_string();

let now = std::time::Instant::now();
let sleep_time = Duration::from_secs(1);
let max = timeout.as_secs() as usize;
// Short does not include the registry name.
let short_pkg_descriptions = package_list(pkgs.iter().copied(), "or");
gctx.shell().note(format!(
"waiting for {short_pkg_descriptions} to be available at {source_description}.\n\
You may press ctrl-c to skip waiting; the crate should be available shortly."
))?;
let mut progress = Progress::with_style("Waiting", ProgressStyle::Ratio, gctx);
progress.tick_now(0, max, "")?;
let available = loop {
Expand Down Expand Up @@ -356,30 +388,12 @@ fn wait_for_any_publish_confirmation(

let elapsed = now.elapsed();
if timeout < elapsed {
gctx.shell().warn(format!(
"timed out waiting for {short_pkg_descriptions} to be available in {source_description}",
))?;
gctx.shell().note(
"the registry may have a backlog that is delaying making the \
crate available. The crate should be available soon.",
)?;
break BTreeSet::new();
}

progress.tick_now(elapsed.as_secs() as usize, max, "")?;
std::thread::sleep(sleep_time);
};
if !available.is_empty() {
let short_pkg_description = available
.iter()
.map(|pkg| format!("{} v{}", pkg.name(), pkg.version()))
.sorted()
.join(", ");
gctx.shell().status(
"Published",
format!("{short_pkg_description} at {source_description}"),
)?;
}

Ok(available)
}
Expand Down Expand Up @@ -691,6 +705,10 @@ impl PublishPlan {
self.dependencies_count.is_empty()
}

fn len(&self) -> usize {
self.dependencies_count.len()
}

/// Returns the set of packages that are ready for publishing (i.e. have no outstanding dependencies).
///
/// These will not be returned in future calls.
Expand Down Expand Up @@ -727,7 +745,7 @@ impl PublishPlan {
fn package_list(pkgs: impl IntoIterator<Item = PackageId>, final_sep: &str) -> String {
let mut names: Vec<_> = pkgs
.into_iter()
.map(|pkg| format!("`{} v{}`", pkg.name(), pkg.version()))
.map(|pkg| format!("{} v{}", pkg.name(), pkg.version()))
.collect();
names.sort();

Expand Down
6 changes: 3 additions & 3 deletions tests/testsuite/alt_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[UPLOADING] foo v0.0.1 ([ROOT]/foo)
[UPLOADED] foo v0.0.1 to registry `alternative`
[NOTE] waiting for `foo v0.0.1` to be available at registry `alternative`.
[NOTE] waiting for foo v0.0.1 to be available at registry `alternative`.
You may press ctrl-c to skip waiting; the crate should be available shortly.
[PUBLISHED] foo v0.0.1 at registry `alternative`

Expand Down Expand Up @@ -519,7 +519,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[UPLOADING] foo v0.0.1 ([ROOT]/foo)
[UPLOADED] foo v0.0.1 to registry `alternative`
[NOTE] waiting for `foo v0.0.1` to be available at registry `alternative`.
[NOTE] waiting for foo v0.0.1 to be available at registry `alternative`.
You may press ctrl-c to skip waiting; the crate should be available shortly.
[PUBLISHED] foo v0.0.1 at registry `alternative`

Expand Down Expand Up @@ -601,7 +601,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[UPLOADING] foo v0.0.1 ([ROOT]/foo)
[UPLOADED] foo v0.0.1 to registry `alternative`
[NOTE] waiting for `foo v0.0.1` to be available at registry `alternative`.
[NOTE] waiting for foo v0.0.1 to be available at registry `alternative`.
You may press ctrl-c to skip waiting; the crate should be available shortly.
[PUBLISHED] foo v0.0.1 at registry `alternative`

Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/artifact_dep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2258,7 +2258,7 @@ fn publish_artifact_dep() {
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
[UPLOADING] foo v0.1.0 ([ROOT]/foo)
[UPLOADED] foo v0.1.0 to registry `crates-io`
[NOTE] waiting for `foo v0.1.0` to be available at registry `crates-io`.
[NOTE] waiting for foo v0.1.0 to be available at registry `crates-io`.
You may press ctrl-c to skip waiting; the crate should be available shortly.
[PUBLISHED] foo v0.1.0 at registry `crates-io`

Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/cargo_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[UPLOADING] a v0.0.1 ([ROOT]/foo)
[UPLOADED] a v0.0.1 to registry `crates-io`
[NOTE] waiting for `a v0.0.1` to be available at registry `crates-io`.
[NOTE] waiting for a v0.0.1 to be available at registry `crates-io`.
You may press ctrl-c to skip waiting; the crate should be available shortly.
[PUBLISHED] a v0.0.1 at registry `crates-io`

Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/credential_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn publish() {
[UPLOADING] foo v0.1.0 ([ROOT]/foo)
{"v":1,"registry":{"index-url":"[..]","name":"alternative"},"kind":"get","operation":"publish","name":"foo","vers":"0.1.0","cksum":"[..]"}
[UPLOADED] foo v0.1.0 to registry `alternative`
[NOTE] waiting for `foo v0.1.0` to be available at registry `alternative`.
[NOTE] waiting for foo v0.1.0 to be available at registry `alternative`.
You may press ctrl-c [..]
[PUBLISHED] foo v0.1.0 at registry `alternative`

Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/cross_publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fn publish_with_target() {
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[UPLOADING] foo v0.0.0 ([ROOT]/foo)
[UPLOADED] foo v0.0.0 to registry `crates-io`
[NOTE] waiting for `foo v0.0.0` to be available at registry `crates-io`.
[NOTE] waiting for foo v0.0.0 to be available at registry `crates-io`.
You may press ctrl-c to skip waiting; the crate should be available shortly.
[PUBLISHED] foo v0.0.0 at registry `crates-io`

Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/features_namespaced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ fn publish_no_implicit() {
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
[UPLOADING] foo v0.1.0 ([ROOT]/foo)
[UPLOADED] foo v0.1.0 to registry `crates-io`
[NOTE] waiting for `foo v0.1.0` to be available at registry `crates-io`.
[NOTE] waiting for foo v0.1.0 to be available at registry `crates-io`.
You may press ctrl-c to skip waiting; the crate should be available shortly.
[PUBLISHED] foo v0.1.0 at registry `crates-io`

Expand Down Expand Up @@ -1074,7 +1074,7 @@ fn publish() {
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[UPLOADING] foo v0.1.0 ([ROOT]/foo)
[UPLOADED] foo v0.1.0 to registry `crates-io`
[NOTE] waiting for `foo v0.1.0` to be available at registry `crates-io`.
[NOTE] waiting for foo v0.1.0 to be available at registry `crates-io`.
You may press ctrl-c to skip waiting; the crate should be available shortly.
[PUBLISHED] foo v0.1.0 at registry `crates-io`

Expand Down
10 changes: 5 additions & 5 deletions tests/testsuite/inheritable_workspace_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn inherit_own_workspace_fields() {
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[UPLOADING] foo v1.2.3 ([ROOT]/foo)
[UPLOADED] foo v1.2.3 to registry `crates-io`
[NOTE] waiting for `foo v1.2.3` to be available at registry `crates-io`.
[NOTE] waiting for foo v1.2.3 to be available at registry `crates-io`.
You may press ctrl-c to skip waiting; the crate should be available shortly.
[PUBLISHED] foo v1.2.3 at registry `crates-io`

Expand Down Expand Up @@ -334,7 +334,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[UPLOADING] bar v0.2.0 ([ROOT]/foo)
[UPLOADED] bar v0.2.0 to registry `crates-io`
[NOTE] waiting for `bar v0.2.0` to be available at registry `crates-io`.
[NOTE] waiting for bar v0.2.0 to be available at registry `crates-io`.
You may press ctrl-c to skip waiting; the crate should be available shortly.
[PUBLISHED] bar v0.2.0 at registry `crates-io`

Expand Down Expand Up @@ -501,7 +501,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[UPLOADING] bar v0.2.0 ([ROOT]/foo)
[UPLOADED] bar v0.2.0 to registry `crates-io`
[NOTE] waiting for `bar v0.2.0` to be available at registry `crates-io`.
[NOTE] waiting for bar v0.2.0 to be available at registry `crates-io`.
You may press ctrl-c to skip waiting; the crate should be available shortly.
[PUBLISHED] bar v0.2.0 at registry `crates-io`

Expand Down Expand Up @@ -762,7 +762,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#the-license-and-lice
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[UPLOADING] bar v1.2.3 ([ROOT]/foo/bar)
[UPLOADED] bar v1.2.3 to registry `crates-io`
[NOTE] waiting for `bar v1.2.3` to be available at registry `crates-io`.
[NOTE] waiting for bar v1.2.3 to be available at registry `crates-io`.
You may press ctrl-c to skip waiting; the crate should be available shortly.
[PUBLISHED] bar v1.2.3 at registry `crates-io`

Expand Down Expand Up @@ -936,7 +936,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[UPLOADING] bar v0.2.0 ([ROOT]/foo/bar)
[UPLOADED] bar v0.2.0 to registry `crates-io`
[NOTE] waiting for `bar v0.2.0` to be available at registry `crates-io`.
[NOTE] waiting for bar v0.2.0 to be available at registry `crates-io`.
You may press ctrl-c to skip waiting; the crate should be available shortly.
[PUBLISHED] bar v0.2.0 at registry `crates-io`

Expand Down
Loading