Skip to content

Commit e175621

Browse files
committed
smart-release tries harder to wait for previously published packages (#364)
1 parent 8e5cb65 commit e175621

File tree

1 file changed

+61
-1
lines changed
  • cargo-smart-release/src/command/release

1 file changed

+61
-1
lines changed

cargo-smart-release/src/command/release/mod.rs

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,20 @@ fn perform_release(ctx: &Context, options: Options, crates: &[traverse::Dependen
405405
false
406406
};
407407
let mut tag_names = Vec::new();
408-
let mut successful_publishees_and_version = Vec::new();
408+
let mut successful_publishees_and_version = Vec::<(&cargo_metadata::Package, &semver::Version)>::new();
409409
let mut publish_err = None;
410410
for (publishee, new_version) in crates.iter().filter_map(try_to_published_crate_and_new_version) {
411+
if let Some((crate_, version)) = successful_publishees_and_version.last() {
412+
if let Err(err) = wait_for_release(*crate_, version, options) {
413+
log::warn!(
414+
"Failed to wait for crates-index update - trying to publish '{} v{}' anyway: {}.",
415+
publishee.name,
416+
new_version,
417+
err
418+
);
419+
}
420+
}
421+
411422
if let Err(err) = cargo::publish_crate(publishee, options) {
412423
publish_err = Some(err);
413424
break;
@@ -440,6 +451,55 @@ fn perform_release(ctx: &Context, options: Options, crates: &[traverse::Dependen
440451
publish_err.map(Err).unwrap_or(Ok(()))
441452
}
442453

454+
fn wait_for_release(
455+
crate_: &cargo_metadata::Package,
456+
crate_version: &semver::Version,
457+
Options {
458+
dry_run,
459+
dry_run_cargo_publish,
460+
skip_publish,
461+
..
462+
}: Options,
463+
) -> anyhow::Result<()> {
464+
use anyhow::Context;
465+
466+
if skip_publish || dry_run || dry_run_cargo_publish {
467+
return Ok(());
468+
}
469+
let timeout = std::time::Duration::from_secs(60);
470+
let start = std::time::Instant::now();
471+
let sleep_time = std::time::Duration::from_secs(1);
472+
let crate_version = crate_version.to_string();
473+
474+
log::info!("Waiting for '{} v{}' to arrive in index…", crate_.name, crate_version);
475+
let mut crates_index = crates_index::Index::new_cargo_default()?;
476+
let mut attempt = 0;
477+
while start.elapsed() < timeout {
478+
attempt += 1;
479+
log::trace!("Updating crates index…");
480+
crates_index.update()?;
481+
let crate_ = crates_index.crate_(&crate_.name).with_context(|| {
482+
format!(
483+
"Couldn't find crate '{}' in index anymore - unexpected and fatal",
484+
crate_.name
485+
)
486+
})?;
487+
488+
if crate_
489+
.versions()
490+
.iter()
491+
.rev()
492+
.any(|version| version.version() == crate_version)
493+
{
494+
break;
495+
}
496+
497+
std::thread::sleep(sleep_time);
498+
log::info!("attempt {}", attempt);
499+
}
500+
Ok(())
501+
}
502+
443503
enum WriteMode {
444504
Tag,
445505
GitHubRelease,

0 commit comments

Comments
 (0)