Skip to content

Commit 7e4764a

Browse files
committed
Add more information to wait-for-publish
1 parent 7b19a6e commit 7e4764a

File tree

9 files changed

+178
-75
lines changed

9 files changed

+178
-75
lines changed

crates/cargo-test-support/src/compare.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ fn substitute_macros(input: &str) -> String {
232232
("[EXECUTABLE]", " Executable"),
233233
("[SKIPPING]", " Skipping"),
234234
("[WAITING]", " Waiting"),
235+
("[PUBLISHED]", " Published"),
235236
];
236237
let mut result = input.to_owned();
237238
for &(pat, subst) in &macros {

src/cargo/ops/registry.rs

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use crate::util::config::{Config, SslVersionConfig, SslVersionConfigRange};
3636
use crate::util::errors::CargoResult;
3737
use crate::util::important_paths::find_root_manifest_for_wd;
3838
use crate::util::{truncate_with_ellipsis, IntoUrl};
39+
use crate::util::{Progress, ProgressStyle};
3940
use crate::{drop_print, drop_println, version};
4041

4142
/// Registry settings loaded from config files.
@@ -442,13 +443,26 @@ fn wait_for_publish(
442443
) -> CargoResult<()> {
443444
let version_req = format!("={}", pkg.version());
444445
let mut source = SourceConfigMap::empty(config)?.load(registry_src, &HashSet::new())?;
445-
let source_description = source.describe();
446+
// Disable the source's built-in progress bars. Repeatedly showing a bunch
447+
// of independent progress bars can be a little confusing. There is an
448+
// overall progress bar managed here.
449+
source.set_quiet(true);
450+
let source_description = source.source_id().to_string();
446451
let query = Dependency::parse(pkg.name(), Some(&version_req), registry_src)?;
447452

448453
let now = std::time::Instant::now();
449454
let sleep_time = std::time::Duration::from_secs(1);
450-
let mut logged = false;
451-
loop {
455+
let max = timeout.as_secs() as usize;
456+
config.shell().status("Published", pkg.to_string())?;
457+
// Short does not include the registry name.
458+
let short_pkg_description = format!("{} v{}", pkg.name(), pkg.version());
459+
config.shell().note(format!(
460+
"Waiting up to {max} seconds for `{short_pkg_description}` to be available at {source_description}.\n\
461+
You may press ctrl-c to skip waiting; the crate should be available shortly."
462+
))?;
463+
let mut progress = Progress::with_style("Waiting", ProgressStyle::Ratio, config);
464+
progress.tick_now(0, max, "")?;
465+
let is_available = loop {
452466
{
453467
let _lock = config.acquire_package_cache_lock()?;
454468
// Force re-fetching the source
@@ -470,31 +484,30 @@ fn wait_for_publish(
470484
}
471485
};
472486
if !summaries.is_empty() {
473-
break;
487+
break true;
474488
}
475489
}
476490

477-
if timeout < now.elapsed() {
491+
let elapsed = now.elapsed();
492+
if timeout < elapsed {
478493
config.shell().warn(format!(
479-
"timed out waiting for `{}` to be in {}",
480-
pkg.name(),
481-
source_description
494+
"timed out waiting for `{short_pkg_description}` to be available in {source_description}",
482495
))?;
483-
break;
484-
}
485-
486-
if !logged {
487-
config.shell().status(
488-
"Waiting",
489-
format!(
490-
"on `{}` to propagate to {} (ctrl-c to wait asynchronously)",
491-
pkg.name(),
492-
source_description
493-
),
496+
config.shell().note(
497+
"The registry may have a backlog that is delaying making the \
498+
crate available. The crate should be available soon.",
494499
)?;
495-
logged = true;
500+
break false;
496501
}
502+
503+
progress.tick_now(elapsed.as_secs() as usize, max, "")?;
497504
std::thread::sleep(sleep_time);
505+
};
506+
if is_available {
507+
config.shell().status(
508+
"Completed",
509+
format!("{pkg} has been successfully published to {source_description}"),
510+
)?;
498511
}
499512

500513
Ok(())

tests/testsuite/artifact_dep.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1911,7 +1911,10 @@ fn publish_artifact_dep() {
19111911
[PACKAGING] foo v0.1.0 [..]
19121912
[PACKAGED] [..]
19131913
[UPLOADING] foo v0.1.0 [..]
1914-
[UPDATING] [..]
1914+
[PUBLISHED] foo v0.1.0 [..]
1915+
note: Waiting [..]
1916+
You may press ctrl-c [..]
1917+
[COMPLETED] foo v0.1.0 [..]
19151918
",
19161919
)
19171920
.run();

tests/testsuite/credential_process.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ Only one of these values may be set, remove one or the other to proceed.
130130
[PACKAGING] foo v0.1.0 [..]
131131
[PACKAGED] [..]
132132
[UPLOADING] foo v0.1.0 [..]
133-
[UPDATING] [..]
133+
[PUBLISHED] foo v0.1.0 [..]
134+
note: Waiting [..]
135+
You may press ctrl-c [..]
136+
[COMPLETED] foo v0.1.0 [..]
134137
",
135138
)
136139
.run();
@@ -222,7 +225,10 @@ fn publish() {
222225
[PACKAGING] foo v0.1.0 [..]
223226
[PACKAGED] [..]
224227
[UPLOADING] foo v0.1.0 [..]
225-
[UPDATING] [..]
228+
[PUBLISHED] foo v0.1.0 [..]
229+
note: Waiting [..]
230+
You may press ctrl-c [..]
231+
[COMPLETED] foo v0.1.0 [..]
226232
",
227233
)
228234
.run();

tests/testsuite/cross_publish.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ fn publish_with_target() {
112112
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
113113
[PACKAGED] [..]
114114
[UPLOADING] foo v0.0.0 ([CWD])
115-
[UPDATING] crates.io index
115+
[PUBLISHED] foo v0.0.0 ([CWD])
116+
note: Waiting [..]
117+
You may press ctrl-c [..]
118+
[COMPLETED] foo v0.0.0 [..]
116119
",
117120
)
118121
.run();

tests/testsuite/features_namespaced.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,10 @@ fn publish_no_implicit() {
894894
[PACKAGING] foo v0.1.0 [..]
895895
[PACKAGED] [..]
896896
[UPLOADING] foo v0.1.0 [..]
897-
[UPDATING] [..]
897+
[PUBLISHED] foo v0.1.0 [..]
898+
note: Waiting [..]
899+
You may press ctrl-c [..]
900+
[COMPLETED] foo v0.1.0 [..]
898901
",
899902
)
900903
.run();
@@ -1013,7 +1016,10 @@ fn publish() {
10131016
[FINISHED] [..]
10141017
[PACKAGED] [..]
10151018
[UPLOADING] foo v0.1.0 [..]
1016-
[UPDATING] [..]
1019+
[PUBLISHED] foo v0.1.0 [..]
1020+
note: Waiting [..]
1021+
You may press ctrl-c [..]
1022+
[COMPLETED] foo v0.1.0 [..]
10171023
",
10181024
)
10191025
.run();

0 commit comments

Comments
 (0)