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

Bail publish job before packaging and upload (passing tests) #14338

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/cargo/ops/registry/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,10 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {

if !duplicate_query.is_empty() {
bail!(
"crate {} already has version {}. Aborting publish.",
"crate {}@{} already exists on {}",
pkg.name(),
pkg.version()
pkg.version(),
source.describe()
);
}

Expand Down
27 changes: 26 additions & 1 deletion tests/testsuite/credential_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,31 @@ You may press ctrl-c [..]
.with_stderr_data(output)
.run();

let output_non_independent = r#"[UPDATING] `alternative` index
{"v":1,"registry":{"index-url":"[..]","name":"alternative"},"kind":"get","operation":"read"}
[PACKAGING] foo v0.1.1 ([ROOT]/foo)
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
{"v":1,"registry":{"index-url":"[..]","name":"alternative"},"kind":"get","operation":"publish","name":"foo","vers":"0.1.1","cksum":"[..]"}
[UPLOADING] foo v0.1.1 ([ROOT]/foo)
[UPLOADED] foo v0.1.1 to registry `alternative`
[NOTE] waiting [..]
You may press ctrl-c [..]
[PUBLISHED] foo v0.1.1 at registry `alternative`
"#;

p.change_file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.1"
edition = "2015"
description = "foo"
license = "MIT"
homepage = "https://example.com/"
"#,
);

p.change_file(
".cargo/config.toml",
&format!(
Expand All @@ -557,7 +582,7 @@ You may press ctrl-c [..]
);

p.cargo("publish --registry alternative --no-verify")
.with_stderr_data(output)
.with_stderr_data(output_non_independent)
.run();
}

Expand Down
17 changes: 2 additions & 15 deletions tests/testsuite/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.

#[cargo_test]
fn duplicate_version() {
let arc: Arc<Mutex<u32>> = Arc::new(Mutex::new(0));
let registry_dupl = RegistryBuilder::new()
.http_api()
.http_index()
.add_responder("/index/3/f/foo", move |req, server| {
let mut lock = arc.lock().unwrap();
*lock += 1;
if *lock <= 1 {
server.not_found(req)
} else {
server.index(req)
}
})
.build();
let registry_dupl = RegistryBuilder::new().http_api().http_index().build();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we update the original test with these changes?


let p = project()
.file(
Expand All @@ -171,7 +158,7 @@ fn duplicate_version() {
.replace_crates_io(registry_dupl.index_url())
.with_stderr_data(str![[r#"
[UPDATING] crates.io index
[ERROR] crate foo already has version 0.0.1. Aborting publish.
[ERROR] crate foo@0.0.1 already exists on [..]

"#]])
.with_status(101)
Expand Down
9 changes: 5 additions & 4 deletions tests/testsuite/registry_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,9 +565,10 @@ fn token_not_logged() {
// 2. config.json again for verification
// 3. /index/3/b/bar
// 4. /dl/bar/1.0.0/download
// 5. /api/v1/crates/new
// 6. config.json for the "wait for publish"
// 7. /index/3/f/foo for the "wait for publish"
assert_eq!(authorizations.len(), 7);
// 5. /index/3/f/foo for checking duplicate version
// 6. /api/v1/crates/new
// 7. config.json for the "wait for publish"
// 8. /index/3/f/foo for the "wait for publish"
assert_eq!(authorizations.len(), 8);
Comment on lines +568 to +572
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be squashed into the appropriate commit? Ideally all commits pass tests

assert!(!log.contains("a-unique_token"));
}