Skip to content

Commit ec0e246

Browse files
authored
fix(publish): Don't tell people to ctrl-c without knowing consequences (#15632)
### What does this PR try to resolve? Telling people they are free to hit ctrl-c while waiting for packages could mean some packages may not be published and the user wouldn't know until they get a complaint about a missing package. Instead, if there are remaining packages, we'll tell the user that. Fixes #15005 ### How to test and review this PR?
2 parents a7be79b + 2e1f971 commit ec0e246

11 files changed

+107
-89
lines changed

src/cargo/ops/registry/publish.rs

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,52 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
270270
DEFAULT_TIMEOUT
271271
};
272272
if 0 < timeout {
273+
let source_description = source.source_id().to_string();
274+
let short_pkg_descriptions = package_list(to_confirm.iter().copied(), "or");
275+
if plan.is_empty() {
276+
opts.gctx.shell().note(format!(
277+
"waiting for {short_pkg_descriptions} to be available at {source_description}.\n\
278+
You may press ctrl-c to skip waiting; the {crate} should be available shortly.",
279+
crate = if to_confirm.len() == 1 { "crate" } else {"crates"}
280+
))?;
281+
} else {
282+
opts.gctx.shell().note(format!(
283+
"waiting for {short_pkg_descriptions} to be available at {source_description}.\n\
284+
{count} remaining {crate} to be published",
285+
count = plan.len(),
286+
crate = if plan.len() == 1 { "crate" } else {"crates"}
287+
))?;
288+
}
289+
273290
let timeout = Duration::from_secs(timeout);
274-
wait_for_any_publish_confirmation(
291+
let confirmed = wait_for_any_publish_confirmation(
275292
opts.gctx,
276293
source_ids.original,
277294
&to_confirm,
278295
timeout,
279-
)?
296+
)?;
297+
if !confirmed.is_empty() {
298+
let short_pkg_description = package_list(confirmed.iter().copied(), "and");
299+
opts.gctx.shell().status(
300+
"Published",
301+
format!("{short_pkg_description} at {source_description}"),
302+
)?;
303+
} else {
304+
let short_pkg_descriptions = package_list(to_confirm.iter().copied(), "or");
305+
opts.gctx.shell().warn(format!(
306+
"timed out waiting for {short_pkg_descriptions} to be available in {source_description}",
307+
))?;
308+
opts.gctx.shell().note(format!(
309+
"the registry may have a backlog that is delaying making the \
310+
{crate} available. The {crate} should be available soon.",
311+
crate = if to_confirm.len() == 1 {
312+
"crate"
313+
} else {
314+
"crates"
315+
}
316+
))?;
317+
}
318+
confirmed
280319
} else {
281320
BTreeSet::new()
282321
}
@@ -317,17 +356,10 @@ fn wait_for_any_publish_confirmation(
317356
// of independent progress bars can be a little confusing. There is an
318357
// overall progress bar managed here.
319358
source.set_quiet(true);
320-
let source_description = source.source_id().to_string();
321359

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

357389
let elapsed = now.elapsed();
358390
if timeout < elapsed {
359-
gctx.shell().warn(format!(
360-
"timed out waiting for {short_pkg_descriptions} to be available in {source_description}",
361-
))?;
362-
gctx.shell().note(
363-
"the registry may have a backlog that is delaying making the \
364-
crate available. The crate should be available soon.",
365-
)?;
366391
break BTreeSet::new();
367392
}
368393

369394
progress.tick_now(elapsed.as_secs() as usize, max, "")?;
370395
std::thread::sleep(sleep_time);
371396
};
372-
if !available.is_empty() {
373-
let short_pkg_description = available
374-
.iter()
375-
.map(|pkg| format!("{} v{}", pkg.name(), pkg.version()))
376-
.sorted()
377-
.join(", ");
378-
gctx.shell().status(
379-
"Published",
380-
format!("{short_pkg_description} at {source_description}"),
381-
)?;
382-
}
383397

384398
Ok(available)
385399
}
@@ -691,6 +705,10 @@ impl PublishPlan {
691705
self.dependencies_count.is_empty()
692706
}
693707

708+
fn len(&self) -> usize {
709+
self.dependencies_count.len()
710+
}
711+
694712
/// Returns the set of packages that are ready for publishing (i.e. have no outstanding dependencies).
695713
///
696714
/// These will not be returned in future calls.
@@ -727,7 +745,7 @@ impl PublishPlan {
727745
fn package_list(pkgs: impl IntoIterator<Item = PackageId>, final_sep: &str) -> String {
728746
let mut names: Vec<_> = pkgs
729747
.into_iter()
730-
.map(|pkg| format!("`{} v{}`", pkg.name(), pkg.version()))
748+
.map(|pkg| format!("{} v{}", pkg.name(), pkg.version()))
731749
.collect();
732750
names.sort();
733751

tests/testsuite/alt_registry.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
356356
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
357357
[UPLOADING] foo v0.0.1 ([ROOT]/foo)
358358
[UPLOADED] foo v0.0.1 to registry `alternative`
359-
[NOTE] waiting for `foo v0.0.1` to be available at registry `alternative`.
359+
[NOTE] waiting for foo v0.0.1 to be available at registry `alternative`.
360360
You may press ctrl-c to skip waiting; the crate should be available shortly.
361361
[PUBLISHED] foo v0.0.1 at registry `alternative`
362362
@@ -519,7 +519,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
519519
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
520520
[UPLOADING] foo v0.0.1 ([ROOT]/foo)
521521
[UPLOADED] foo v0.0.1 to registry `alternative`
522-
[NOTE] waiting for `foo v0.0.1` to be available at registry `alternative`.
522+
[NOTE] waiting for foo v0.0.1 to be available at registry `alternative`.
523523
You may press ctrl-c to skip waiting; the crate should be available shortly.
524524
[PUBLISHED] foo v0.0.1 at registry `alternative`
525525
@@ -601,7 +601,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
601601
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
602602
[UPLOADING] foo v0.0.1 ([ROOT]/foo)
603603
[UPLOADED] foo v0.0.1 to registry `alternative`
604-
[NOTE] waiting for `foo v0.0.1` to be available at registry `alternative`.
604+
[NOTE] waiting for foo v0.0.1 to be available at registry `alternative`.
605605
You may press ctrl-c to skip waiting; the crate should be available shortly.
606606
[PUBLISHED] foo v0.0.1 at registry `alternative`
607607

tests/testsuite/artifact_dep.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2258,7 +2258,7 @@ fn publish_artifact_dep() {
22582258
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
22592259
[UPLOADING] foo v0.1.0 ([ROOT]/foo)
22602260
[UPLOADED] foo v0.1.0 to registry `crates-io`
2261-
[NOTE] waiting for `foo v0.1.0` to be available at registry `crates-io`.
2261+
[NOTE] waiting for foo v0.1.0 to be available at registry `crates-io`.
22622262
You may press ctrl-c to skip waiting; the crate should be available shortly.
22632263
[PUBLISHED] foo v0.1.0 at registry `crates-io`
22642264

tests/testsuite/cargo_features.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
643643
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
644644
[UPLOADING] a v0.0.1 ([ROOT]/foo)
645645
[UPLOADED] a v0.0.1 to registry `crates-io`
646-
[NOTE] waiting for `a v0.0.1` to be available at registry `crates-io`.
646+
[NOTE] waiting for a v0.0.1 to be available at registry `crates-io`.
647647
You may press ctrl-c to skip waiting; the crate should be available shortly.
648648
[PUBLISHED] a v0.0.1 at registry `crates-io`
649649

tests/testsuite/credential_process.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn publish() {
7979
[UPLOADING] foo v0.1.0 ([ROOT]/foo)
8080
{"v":1,"registry":{"index-url":"[..]","name":"alternative"},"kind":"get","operation":"publish","name":"foo","vers":"0.1.0","cksum":"[..]"}
8181
[UPLOADED] foo v0.1.0 to registry `alternative`
82-
[NOTE] waiting for `foo v0.1.0` to be available at registry `alternative`.
82+
[NOTE] waiting for foo v0.1.0 to be available at registry `alternative`.
8383
You may press ctrl-c [..]
8484
[PUBLISHED] foo v0.1.0 at registry `alternative`
8585

tests/testsuite/cross_publish.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fn publish_with_target() {
114114
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
115115
[UPLOADING] foo v0.0.0 ([ROOT]/foo)
116116
[UPLOADED] foo v0.0.0 to registry `crates-io`
117-
[NOTE] waiting for `foo v0.0.0` to be available at registry `crates-io`.
117+
[NOTE] waiting for foo v0.0.0 to be available at registry `crates-io`.
118118
You may press ctrl-c to skip waiting; the crate should be available shortly.
119119
[PUBLISHED] foo v0.0.0 at registry `crates-io`
120120

tests/testsuite/features_namespaced.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ fn publish_no_implicit() {
930930
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
931931
[UPLOADING] foo v0.1.0 ([ROOT]/foo)
932932
[UPLOADED] foo v0.1.0 to registry `crates-io`
933-
[NOTE] waiting for `foo v0.1.0` to be available at registry `crates-io`.
933+
[NOTE] waiting for foo v0.1.0 to be available at registry `crates-io`.
934934
You may press ctrl-c to skip waiting; the crate should be available shortly.
935935
[PUBLISHED] foo v0.1.0 at registry `crates-io`
936936
@@ -1074,7 +1074,7 @@ fn publish() {
10741074
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
10751075
[UPLOADING] foo v0.1.0 ([ROOT]/foo)
10761076
[UPLOADED] foo v0.1.0 to registry `crates-io`
1077-
[NOTE] waiting for `foo v0.1.0` to be available at registry `crates-io`.
1077+
[NOTE] waiting for foo v0.1.0 to be available at registry `crates-io`.
10781078
You may press ctrl-c to skip waiting; the crate should be available shortly.
10791079
[PUBLISHED] foo v0.1.0 at registry `crates-io`
10801080

tests/testsuite/inheritable_workspace_fields.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ fn inherit_own_workspace_fields() {
167167
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
168168
[UPLOADING] foo v1.2.3 ([ROOT]/foo)
169169
[UPLOADED] foo v1.2.3 to registry `crates-io`
170-
[NOTE] waiting for `foo v1.2.3` to be available at registry `crates-io`.
170+
[NOTE] waiting for foo v1.2.3 to be available at registry `crates-io`.
171171
You may press ctrl-c to skip waiting; the crate should be available shortly.
172172
[PUBLISHED] foo v1.2.3 at registry `crates-io`
173173
@@ -334,7 +334,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
334334
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
335335
[UPLOADING] bar v0.2.0 ([ROOT]/foo)
336336
[UPLOADED] bar v0.2.0 to registry `crates-io`
337-
[NOTE] waiting for `bar v0.2.0` to be available at registry `crates-io`.
337+
[NOTE] waiting for bar v0.2.0 to be available at registry `crates-io`.
338338
You may press ctrl-c to skip waiting; the crate should be available shortly.
339339
[PUBLISHED] bar v0.2.0 at registry `crates-io`
340340
@@ -501,7 +501,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
501501
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
502502
[UPLOADING] bar v0.2.0 ([ROOT]/foo)
503503
[UPLOADED] bar v0.2.0 to registry `crates-io`
504-
[NOTE] waiting for `bar v0.2.0` to be available at registry `crates-io`.
504+
[NOTE] waiting for bar v0.2.0 to be available at registry `crates-io`.
505505
You may press ctrl-c to skip waiting; the crate should be available shortly.
506506
[PUBLISHED] bar v0.2.0 at registry `crates-io`
507507
@@ -762,7 +762,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#the-license-and-lice
762762
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
763763
[UPLOADING] bar v1.2.3 ([ROOT]/foo/bar)
764764
[UPLOADED] bar v1.2.3 to registry `crates-io`
765-
[NOTE] waiting for `bar v1.2.3` to be available at registry `crates-io`.
765+
[NOTE] waiting for bar v1.2.3 to be available at registry `crates-io`.
766766
You may press ctrl-c to skip waiting; the crate should be available shortly.
767767
[PUBLISHED] bar v1.2.3 at registry `crates-io`
768768
@@ -936,7 +936,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
936936
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
937937
[UPLOADING] bar v0.2.0 ([ROOT]/foo/bar)
938938
[UPLOADED] bar v0.2.0 to registry `crates-io`
939-
[NOTE] waiting for `bar v0.2.0` to be available at registry `crates-io`.
939+
[NOTE] waiting for bar v0.2.0 to be available at registry `crates-io`.
940940
You may press ctrl-c to skip waiting; the crate should be available shortly.
941941
[PUBLISHED] bar v0.2.0 at registry `crates-io`
942942

0 commit comments

Comments
 (0)