fix(publish): make allow_public actually reach crates.io - #341
Merged
Conversation
allow_public added a registry named "crates.io", which no part of the
publish path could use.
Cargo rejects that name outright ('invalid character `.` in registry
name'), and publish passes the name straight to 'cargo publish
--registry', so the upload could never have run. Before that, the
registry resolved with index: None, because crates-io has no
[registries] entry to read one from and cargo knows the index natively.
check_crate_exists therefore failed, and its caller swallows an error
into publish = false, so the crate silently never went out. opd-parser
shipped 0.6.0 to the private registry while crates.io stayed on 0.5.0.
Use cargo's own spelling, crates-io, so the entry collapses with any
crates-io contributed by package.publish instead of sitting beside it as
a second unusable one, and default the sparse index behind the existing
env and config overrides.
Verified against real cargo: 'cargo publish --dry-run --registry
crates-io' reaches Uploading, both bare and with the
CARGO_REGISTRIES_CRATES_IO_INDEX/_TOKEN vars get_registry_env injects.
Note that repos relying on this need 'crates-io' in package.publish;
a publish list naming only the private registry still blocks the
upload, which is cargo's check, not this one.
Signed-off-by: Loïs Postula <lois@postu.la>
test_crates_io_defaults_to_its_sparse_index built a registry through CargoRegistry::new, which merges CARGO_REGISTRIES_CRATES_IO_INDEX before applying the default. CI sets that var from vault, so the assertion held locally and failed there. Split the fallback into default_index() and assert on that, which is the logic the test meant to cover. The override test keeps going through new: merge only fills fields that are still None, so an explicitly passed index holds whatever the env supplies. Signed-off-by: Loïs Postula <lois@postu.la>
JulianRuiseco
approved these changes
Aug 27, 2026
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: JulianRuiseco The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
allow_publicinserted a registry namedcrates.io. Cargo does not accept that as a registry name, so the public publish was unreachable for every repo relying on it.publish/mod.rs:1155passes the registry name verbatim tocargo publish --registry, and cargo rejects it:Real consequence:
opd-parsershipped 0.6.0 to the private registry while crates.io stayed at 0.5.0.The fix
Canonicalize on cargo's own spelling,
crates-io.That makes the
allow_publicentry collapse with anycrates-ioalready contributed bypackage.publish, instead of sitting beside it as a second, unusable entry. It also makes the pre-existingfilter(|r| *r != "crates-io")atcheck_workspace/mod.rs:876correct for both sources — that line already assumed this spelling.Also defaults the sparse index for
crates-io, since it has no[registries]entry to read one from (cargo knows the index natively). This sits after the env and config merges, so an explicit argument,CARGO_REGISTRIES_CRATES_IO_INDEX, or a config entry still wins.Verification
Against real cargo, not just unit tests:
The second matters because
get_registry_envinjects exactly those vars, and cargo could plausibly have rejected an index override on its built-in registry. It does not.243 tests pass,
cargo fmt --checkclean. Also verified green withCARGO_REGISTRIES_CRATES_IO_INDEXset to the real index, matching how CI runs.Correction to my first description of this PR
I originally claimed a second, independent failure: that the missing index made
check_crate_existsfail in production, and its caller swallowed the error intopublish = false.The CI failure on the first push disproved that. My test asserted the default index by constructing a registry through
CargoRegistry::new, and it failed on Prow — because Prow does setCARGO_REGISTRIES_CRATES_IO_INDEXfrom vault, so the env supplied an index and the default never applied. Which means the registry very likely resolved an index in the real publish job too, and the existence check was not necessarily the thing that broke.The illegal registry name is fatal on its own and is proven, so the fix stands unchanged. The index default is now a robustness improvement for environments that do not set that var, not a claimed root cause. The test was rewritten to assert
default_index()directly rather than read ambient env.Consumers need one more thing
crates-iomust be listed inpackage.publish. A publish list naming only the private registry still blocks the upload — cargo's own allowlist, not this code. Foropd-parserthat is fslabs/opd_parser#17.Unrelated, not fixed here
cargo clippy --all-targets -- -D warningsfails ongenerate_wix/mod.rs:917(iter_kv_map). Confirmed pre-existing by stashing this change and re-running. Toolchain drift: this repo pins 1.93, my local cargo is 1.98. Left alone as out of scope.