Skip to content

Commit

Permalink
Add more information to wait-for-publish
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Feb 14, 2023
1 parent 5eef715 commit ec2a69a
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 75 deletions.
1 change: 1 addition & 0 deletions crates/cargo-test-support/src/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ fn substitute_macros(input: &str) -> String {
("[EXECUTABLE]", " Executable"),
("[SKIPPING]", " Skipping"),
("[WAITING]", " Waiting"),
("[PUBLISHED]", " Published"),
];
let mut result = input.to_owned();
for &(pat, subst) in &macros {
Expand Down
53 changes: 33 additions & 20 deletions src/cargo/ops/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use crate::util::config::{Config, SslVersionConfig, SslVersionConfigRange};
use crate::util::errors::CargoResult;
use crate::util::important_paths::find_root_manifest_for_wd;
use crate::util::{truncate_with_ellipsis, IntoUrl};
use crate::util::{Progress, ProgressStyle};
use crate::{drop_print, drop_println, version};

/// Registry settings loaded from config files.
Expand Down Expand Up @@ -442,13 +443,26 @@ fn wait_for_publish(
) -> CargoResult<()> {
let version_req = format!("={}", pkg.version());
let mut source = SourceConfigMap::empty(config)?.load(registry_src, &HashSet::new())?;
let source_description = source.describe();
// Disable the source's built-in progress bars. Repeatedly showing a bunch
// 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 query = Dependency::parse(pkg.name(), Some(&version_req), registry_src)?;

let now = std::time::Instant::now();
let sleep_time = std::time::Duration::from_secs(1);
let mut logged = false;
loop {
let max = timeout.as_secs() as usize;
config.shell().status("Published", pkg.to_string())?;
// Short does not include the registry name.
let short_pkg_description = format!("{} v{}", pkg.name(), pkg.version());
config.shell().note(format!(
"Waiting up to {max} seconds for `{short_pkg_description}` 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, config);
progress.tick_now(0, max, "")?;
let is_available = loop {
{
let _lock = config.acquire_package_cache_lock()?;
// Force re-fetching the source
Expand All @@ -470,31 +484,30 @@ fn wait_for_publish(
}
};
if !summaries.is_empty() {
break;
break true;
}
}

if timeout < now.elapsed() {
let elapsed = now.elapsed();
if timeout < elapsed {
config.shell().warn(format!(
"timed out waiting for `{}` to be in {}",
pkg.name(),
source_description
"timed out waiting for `{short_pkg_description}` to be available in {source_description}",
))?;
break;
}

if !logged {
config.shell().status(
"Waiting",
format!(
"on `{}` to propagate to {} (ctrl-c to wait asynchronously)",
pkg.name(),
source_description
),
config.shell().note(
"The registry may have a backlog that is delaying making the \
crate available. The crate should be available soon.",
)?;
logged = true;
break false;
}

progress.tick_now(elapsed.as_secs() as usize, max, "")?;
std::thread::sleep(sleep_time);
};
if is_available {
config.shell().status(
"Completed",
format!("{pkg} has been successfully published to {source_description}"),
)?;
}

Ok(())
Expand Down
5 changes: 4 additions & 1 deletion tests/testsuite/artifact_dep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1921,7 +1921,10 @@ fn publish_artifact_dep() {
[PACKAGING] foo v0.1.0 [..]
[PACKAGED] [..]
[UPLOADING] foo v0.1.0 [..]
[UPDATING] [..]
[PUBLISHED] foo v0.1.0 [..]
note: Waiting [..]
You may press ctrl-c [..]
[COMPLETED] foo v0.1.0 [..]
",
)
.run();
Expand Down
10 changes: 8 additions & 2 deletions tests/testsuite/credential_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ Only one of these values may be set, remove one or the other to proceed.
[PACKAGING] foo v0.1.0 [..]
[PACKAGED] [..]
[UPLOADING] foo v0.1.0 [..]
[UPDATING] [..]
[PUBLISHED] foo v0.1.0 [..]
note: Waiting [..]
You may press ctrl-c [..]
[COMPLETED] foo v0.1.0 [..]
",
)
.run();
Expand Down Expand Up @@ -230,7 +233,10 @@ fn publish() {
[PACKAGING] foo v0.1.0 [..]
[PACKAGED] [..]
[UPLOADING] foo v0.1.0 [..]
[UPDATING] [..]
[PUBLISHED] foo v0.1.0 [..]
note: Waiting [..]
You may press ctrl-c [..]
[COMPLETED] foo v0.1.0 [..]
",
)
.run();
Expand Down
5 changes: 4 additions & 1 deletion tests/testsuite/cross_publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ fn publish_with_target() {
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[PACKAGED] [..]
[UPLOADING] foo v0.0.0 ([CWD])
[UPDATING] crates.io index
[PUBLISHED] foo v0.0.0 ([CWD])
note: Waiting [..]
You may press ctrl-c [..]
[COMPLETED] foo v0.0.0 [..]
",
)
.run();
Expand Down
10 changes: 8 additions & 2 deletions tests/testsuite/features_namespaced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,10 @@ fn publish_no_implicit() {
[PACKAGING] foo v0.1.0 [..]
[PACKAGED] [..]
[UPLOADING] foo v0.1.0 [..]
[UPDATING] [..]
[PUBLISHED] foo v0.1.0 [..]
note: Waiting [..]
You may press ctrl-c [..]
[COMPLETED] foo v0.1.0 [..]
",
)
.run();
Expand Down Expand Up @@ -1032,7 +1035,10 @@ fn publish() {
[FINISHED] [..]
[PACKAGED] [..]
[UPLOADING] foo v0.1.0 [..]
[UPDATING] [..]
[PUBLISHED] foo v0.1.0 [..]
note: Waiting [..]
You may press ctrl-c [..]
[COMPLETED] foo v0.1.0 [..]
",
)
.run();
Expand Down
Loading

0 comments on commit ec2a69a

Please sign in to comment.