Skip to content

Commit

Permalink
Merge pull request #814 from epage/wait-less
Browse files Browse the repository at this point in the history
fix(publish): Remove our own waiting logic
  • Loading branch information
epage committed Sep 6, 2024
2 parents 761f05d + 6318a44 commit c32bc39
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 57 deletions.
41 changes: 0 additions & 41 deletions src/ops/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,47 +108,6 @@ pub fn publish(
call(command, false)
}

pub fn wait_for_publish(
index: &mut crate::ops::index::CratesIoIndex,
registry: Option<&str>,
name: &str,
version: &str,
timeout: std::time::Duration,
dry_run: bool,
certs_source: CertsSource,
) -> CargoResult<()> {
if !dry_run {
if registry.is_some() {
// HACK: `index` never reports crates as present for alternative registries
log::debug!("Not waiting for publish as that is only supported for crates.io; ensure you are using at least cargo v1.66 which will wait for you.");
return Ok(());
}

let now = std::time::Instant::now();
let sleep_time = std::time::Duration::from_secs(1);
let mut logged = false;
loop {
index.update_krate(registry, name);
if is_published(index, registry, name, version, certs_source) {
break;
} else if timeout < now.elapsed() {
anyhow::bail!("timeout waiting for crate to be published");
}

if !logged {
let _ = crate::ops::shell::status(
"Waiting",
format!("on {name} to propagate to index"),
);
logged = true;
}
std::thread::sleep(sleep_time);
}
}

Ok(())
}

pub fn is_published(
index: &mut crate::ops::index::CratesIoIndex,
registry: Option<&str>,
Expand Down
18 changes: 3 additions & 15 deletions src/steps/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl PublishStep {
super::confirm("Publish", &selected_pkgs, self.no_confirm, dry_run)?;

// STEP 3: cargo publish
publish(&ws_meta, &selected_pkgs, &mut index, dry_run)?;
publish(&ws_meta, &selected_pkgs, dry_run)?;

super::finish(failed, dry_run)
}
Expand All @@ -167,7 +167,6 @@ impl PublishStep {
pub fn publish(
ws_meta: &cargo_metadata::Metadata,
pkgs: &[plan::PackageRelease],
index: &mut crate::ops::index::CratesIoIndex,
dry_run: bool,
) -> Result<(), CliError> {
for pkg in pkgs {
Expand Down Expand Up @@ -207,19 +206,8 @@ pub fn publish(
return Err(101.into());
}

let timeout = std::time::Duration::from_secs(300);
let version = pkg.planned_version.as_ref().unwrap_or(&pkg.initial_version);
crate::ops::cargo::wait_for_publish(
index,
pkg.config.registry(),
crate_name,
&version.full_version_string,
timeout,
dry_run,
pkg.config.certs_source(),
)?;
// HACK: Even once the index is updated, there seems to be another step before the publish is fully ready.
// We don't have a way yet to check for that, so waiting for now in hopes everything is ready
// HACK: This is a fallback in case users can't or don't want to rely on cargo waiting for
// them
if !dry_run {
let publish_grace_sleep = std::env::var("PUBLISH_GRACE_SLEEP")
.unwrap_or_else(|_| Default::default())
Expand Down
2 changes: 1 addition & 1 deletion src/steps/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ impl ReleaseStep {
}

// STEP 3: cargo publish
super::publish::publish(&ws_meta, &selected_pkgs, &mut index, dry_run)?;
super::publish::publish(&ws_meta, &selected_pkgs, dry_run)?;
super::owner::ensure_owners(&selected_pkgs, dry_run)?;

// STEP 5: Tag
Expand Down

0 comments on commit c32bc39

Please sign in to comment.