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 #13501

Conversation

stupendoussuperpowers
Copy link
Contributor

Fixes #3662

This PR adds a check for existing version in the registry before we package and upload the crate.

With this PR we get an error pointing out that the same version exists in registry, and we abort the publish job.

Also adds tests for the same.

@rustbot
Copy link
Collaborator

rustbot commented Feb 29, 2024

r? @weihanglo

rustbot has assigned @weihanglo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-interacts-with-crates.io Area: interaction with registries Command-publish S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 29, 2024
@stupendoussuperpowers
Copy link
Contributor Author

Some tests with alt_registry are failing.

When we query the index for duplicate version, it prints out an extra "Updating [..] index" line. Which is missing in those test cases.

Should I be modifying the failing tests to add that line, or is there a different way to run the query where this log line is not outputted?

@weihanglo
Copy link
Member

weihanglo commented Feb 29, 2024

If the fix does change the behaviour of those test cases, then assertions of printing status seems reasonable to me.

Note that I haven't looked into the fix itself.


if !duplicate_query.is_empty() {
bail!(
"crate {} already has version {}. Aborting publish.",
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:
"crate {name}@{version} is already present in {registry}"
(have not looked into what "registery" variable would be appropriate to lit here)

  • Specifying the registry might be helpful in case someone is publishing to multiple as that gives them a chance to think "Oh whoops, I meant this other one"
  • We likely don't need an "Aborting publish" as thats what an error is
  • The current phrasing is a little awkward (saying a crate has a version reads a little funny to me)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

registry variable here can be source.describe() which would be "crates.io index" in this case.

@epage
Copy link
Contributor

epage commented Feb 29, 2024

When we query the index for duplicate version, it prints out an extra "Updating [..] index" line. Which is missing in those test cases.

Should I be modifying the failing tests to add that line, or is there a different way to run the query where this log line is not outputted?

Not looked into the details of when this message will show up or not but we likely don't need a new instance of SourceConfigMap and if we can reuse the way to look up registeries with other code, that'd likely help.

wait-for-publish has to go through some extra hoops because it needs to avoid reusing cached results.

@stupendoussuperpowers
Copy link
Contributor Author

The easy fix I found was to use source.set_quiet(true) - tests are passing with this.

I am also not able to find any other source present in this flow that we can re-use.

start_fetch() is supposed to be called only once per HttpRemote instance, I am unsure why creating a new source here is causing it to create a different instance for alternate registries but not for crates-io.

The first update in both cases happens when we create the registry object here - publish.rs#L130

For alternate registry upon querying it causes start_fetch() to be triggered again.

Any insight into how alternate registry queries work would be helpful. For now we can also continue with just adding set_quiet(true)

@stupendoussuperpowers
Copy link
Contributor Author

Hey, did anyone get a chance to check this?

In summary -

  1. We can use source.set_quiet(true) which makes the alternate publish pass
  2. I'll need some guidance into why there's different outputs for crates-io and an alternate registry

@weihanglo
Copy link
Member

I'll need some guidance into why there's different outputs for crates-io and an alternate registry

Could you show us the difference? Let us know when this PR is ready for review :)


Somehow I remembered this issue #13397. While this PR just make it fail fast, it might be something to consider in the future.

@torhovland
Copy link
Contributor

@stupendoussuperpowers Will you provide the difference in output asked for above?

@stupendoussuperpowers
Copy link
Contributor Author

start_fetch() is supposed to be called only once per HttpRemote instance, I am unsure why creating a new source here is causing it to create a different instance for alternate registries but not for crates-io.

The first update in both cases happens when we create the registry object here - publish.rs#L130

For alternate registry upon querying it causes start_fetch() to be triggered again.

Any insight into how alternate registry queries work would be helpful. For now we can also continue with just adding set_quiet(true)

The above comment is the depth to which I was able to analyze the issue.

The symptom for this is -

When I added the code to check for existing version of the package, it logged an extra "Updating [..] index" line IF used with an alternate registry. It did not do this with crates-io. This causes certain alternate registry tests to fail since the output doesn't expect "Updating [..] index" to be present twice.

@torhovland
Copy link
Contributor

The multiple Updating messages do make sense in a way. The first one is notifying about fetching /index/config.json, and the second one about /index/3/f/foo. If these fetches were running in the same RegistrySource there would only be one message, but they aren't. One is made within super::registry() and one is made just after in this PR in let mut source = SourceConfigMap::empty(opts.gctx)?.load(reg_ids.original, &HashSet::new())?;.

I tried reusing the first one, but that broke the publish::duplicate_version test.

@torhovland
Copy link
Contributor

But that was fixed by changing

    let query = Dependency::parse(pkg.name(), Some(&ver), reg_ids.original)?;

to

    let query = Dependency::parse(pkg.name(), Some(&ver), reg_ids.replacement)?;

Here's a full fix:

diff.txt

@stupendoussuperpowers Will you try to apply this?

@stupendoussuperpowers
Copy link
Contributor Author

thanks @torhovland for the help, let me try and apply this patch. will submit a patched PR.

@torhovland
Copy link
Contributor

Hi! I already applied the fix and submitted it in #14338, but it turns out there's yet another test that demands some work. You can certainly look into that if you want.

@stupendoussuperpowers stupendoussuperpowers marked this pull request as draft August 6, 2024 21:10
Fix duplicate updating messages when using alt registries by reusing the RegistrySource.

Merge Upstream
@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler A-cli-help Area: built-in command-line help A-console-output Area: Terminal output, colors, progress bar, etc. A-documenting-cargo-itself Area: Cargo's documentation A-environment-variables Area: environment variables A-home Area: the `home` crate A-infrastructure Area: infrastructure around the cargo repo, ci, releases, etc. labels Aug 6, 2024
@torhovland
Copy link
Contributor

Superseded by #14338.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-execution Area: anything dealing with executing the compiler A-cli-help Area: built-in command-line help A-console-output Area: Terminal output, colors, progress bar, etc. A-documenting-cargo-itself Area: Cargo's documentation A-environment-variables Area: environment variables A-home Area: the `home` crate A-infrastructure Area: infrastructure around the cargo repo, ci, releases, etc. A-interacts-with-crates.io Area: interaction with registries A-manifest Area: Cargo.toml issues A-rebuild-detection Area: rebuild detection and fingerprinting A-workspaces Area: workspaces Command-fix Command-login Command-owner Command-package Command-publish Command-search Command-vendor Command-yank S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fail fast when package version is already published
5 participants