Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(publish): Block until it is in index #11062

Merged
merged 4 commits into from Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cargo/ops/registry.rs
Expand Up @@ -186,7 +186,7 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
opts.dry_run,
)?;
if !opts.dry_run {
const DEFAULT_TIMEOUT: u64 = 0;
const DEFAULT_TIMEOUT: u64 = 60;
let timeout = if opts.config.cli_unstable().publish_timeout {
let timeout: Option<u64> = opts.config.get("publish.timeout")?;
timeout.unwrap_or(DEFAULT_TIMEOUT)
Expand Down
12 changes: 12 additions & 0 deletions tests/testsuite/artifact_dep.rs
Expand Up @@ -1872,7 +1872,9 @@ fn env_vars_and_build_products_for_various_build_targets() {

#[cargo_test]
fn publish_artifact_dep() {
// HACK below allows us to use a local registry
let registry = registry::init();

Package::new("bar", "1.0.0").publish();
Package::new("baz", "1.0.0").publish();

Expand Down Expand Up @@ -1901,6 +1903,15 @@ fn publish_artifact_dep() {
.file("src/lib.rs", "")
.build();

// HACK: Inject `foo` directly into the index so `publish` won't block for it to be in
// the index.
//
// This is to ensure we can verify the Summary we post to the registry as doing so precludes
// the registry from processing the publish.
Package::new("foo", "0.1.0")
.file("src/lib.rs", "")
.publish();

p.cargo("publish -Z bindeps --no-verify")
.replace_crates_io(registry.index_url())
.masquerade_as_nightly_cargo(&["bindeps"])
Expand All @@ -1909,6 +1920,7 @@ fn publish_artifact_dep() {
[UPDATING] [..]
[PACKAGING] foo v0.1.0 [..]
[UPLOADING] foo v0.1.0 [..]
[UPDATING] [..]
",
)
.run();
Expand Down
14 changes: 13 additions & 1 deletion tests/testsuite/credential_process.rs
@@ -1,6 +1,6 @@
//! Tests for credential-process.

use cargo_test_support::registry::TestRegistry;
use cargo_test_support::registry::{Package, TestRegistry};
use cargo_test_support::{basic_manifest, cargo_process, paths, project, registry, Project};
use std::fs;

Expand Down Expand Up @@ -94,6 +94,16 @@ fn warn_both_token_and_process() {
.file("src/lib.rs", "")
.build();

// HACK: Inject `foo` directly into the index so `publish` won't block for it to be in
// the index.
//
// This is to ensure we can verify the Summary we post to the registry as doing so precludes
// the registry from processing the publish.
Package::new("foo", "0.1.0")
.file("src/lib.rs", "")
.alternative(true)
.publish();

p.cargo("publish --no-verify --registry alternative -Z credential-process")
.masquerade_as_nightly_cargo(&["credential-process"])
.with_status(101)
Expand Down Expand Up @@ -125,6 +135,7 @@ Only one of these values may be set, remove one or the other to proceed.
[UPDATING] [..]
[PACKAGING] foo v0.1.0 [..]
[UPLOADING] foo v0.1.0 [..]
[UPDATING] [..]
",
)
.run();
Expand Down Expand Up @@ -198,6 +209,7 @@ fn publish() {
[UPDATING] [..]
[PACKAGING] foo v0.1.0 [..]
[UPLOADING] foo v0.1.0 [..]
[UPDATING] [..]
",
)
.run();
Expand Down
4 changes: 3 additions & 1 deletion tests/testsuite/cross_publish.rs
Expand Up @@ -66,7 +66,8 @@ fn publish_with_target() {
return;
}

let registry = registry::init();
// `publish` generally requires a remote registry
let registry = registry::RegistryBuilder::new().http_api().build();

let p = project()
.file(
Expand Down Expand Up @@ -109,6 +110,7 @@ fn publish_with_target() {
[COMPILING] foo v0.0.0 ([CWD]/target/package/foo-0.0.0)
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[UPLOADING] foo v0.0.0 ([CWD])
[UPDATING] crates.io index
",
)
.run();
Expand Down
24 changes: 24 additions & 0 deletions tests/testsuite/features_namespaced.rs
Expand Up @@ -858,7 +858,9 @@ bar v1.0.0

#[cargo_test]
fn publish_no_implicit() {
// HACK below allows us to use a local registry
let registry = registry::init();

// Does not include implicit features or dep: syntax on publish.
Package::new("opt-dep1", "1.0.0").publish();
Package::new("opt-dep2", "1.0.0").publish();
Expand All @@ -885,13 +887,23 @@ fn publish_no_implicit() {
.file("src/lib.rs", "")
.build();

// HACK: Inject `foo` directly into the index so `publish` won't block for it to be in
// the index.
//
// This is to ensure we can verify the Summary we post to the registry as doing so precludes
// the registry from processing the publish.
Package::new("foo", "0.1.0")
.file("src/lib.rs", "")
.publish();

p.cargo("publish --no-verify")
.replace_crates_io(registry.index_url())
.with_stderr(
"\
[UPDATING] [..]
[PACKAGING] foo v0.1.0 [..]
[UPLOADING] foo v0.1.0 [..]
[UPDATING] [..]
",
)
.run();
Expand Down Expand Up @@ -971,7 +983,9 @@ feat = ["opt-dep1"]

#[cargo_test]
fn publish() {
// HACK below allows us to use a local registry
let registry = registry::init();

// Publish behavior with explicit dep: syntax.
Package::new("bar", "1.0.0").publish();
let p = project()
Expand All @@ -997,6 +1011,15 @@ fn publish() {
.file("src/lib.rs", "")
.build();

// HACK: Inject `foo` directly into the index so `publish` won't block for it to be in
// the index.
//
// This is to ensure we can verify the Summary we post to the registry as doing so precludes
// the registry from processing the publish.
Package::new("foo", "0.1.0")
.file("src/lib.rs", "")
.publish();

p.cargo("publish")
.replace_crates_io(registry.index_url())
.with_stderr(
Expand All @@ -1007,6 +1030,7 @@ fn publish() {
[COMPILING] foo v0.1.0 [..]
[FINISHED] [..]
[UPLOADING] foo v0.1.0 [..]
[UPDATING] [..]
",
)
.run();
Expand Down