Skip to content

Fix/cargo workspace deps version for publishing - #2017

Open
vemilano wants to merge 48 commits into
commitizen-tools:masterfrom
vemilano:fix/cargo-workspace-deps-version
Open

Fix/cargo workspace deps version for publishing#2017
vemilano wants to merge 48 commits into
commitizen-tools:masterfrom
vemilano:fix/cargo-workspace-deps-version

Conversation

@vemilano

Copy link
Copy Markdown
Contributor

Description

This PR makes 2 things:

  1. Fixes CRASH on cargo provider #2001. Commitizen was crashing when a workspace member had a fixed version
  2. Add support for rust projects with workspace members that want to publish their crates on crates.io

Regarding the second point, to provide more details, crates.io requires that each crate have a version specified in Cargo.toml. For projects that use a workspace, this means that all members using version.workspace = true must also have a version specified at the workspace.dependencies level (the specified version must be the same as that of workspace.version).

When performing a version bump, in addition to updating workspace.version (in Cargo.toml) and the versions in Cargo.lock, we must also update the versions specified in Cargo.toml, since they are actually dynamically managed by Cargo via version.workspace = true.

Projects such as crate-ci/cargo-release or pksunkara/cargo-workspaces also use the same process

Checklist

Was generative AI tooling used to co-author this PR?

no

Code Changes

  • Add test cases to all the changes you introduce
  • Run uv run poe all locally to ensure this change passes linter check and tests
  • Manually test the changes:
    • Verify the feature/bug fix works as expected in real-world scenarios
    • Test edge cases and error conditions
    • Ensure backward compatibility is maintained
    • Document any manual testing steps performed
  • Update the documentation for the changes

@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

⚠️ JUnit XML file not found

The CLI was unable to find any JUnit XML files to upload.
For more help, visit our troubleshooting guide.

@Lee-W
Lee-W force-pushed the fix/cargo-workspace-deps-version branch from bba3019 to 9277972 Compare June 19, 2026 13:56
bearomorphism and others added 24 commits August 24, 2026 14:16
…ommitizen-tools#2009)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
)

Signed-off-by: dependabot[bot] <support@github.com>
When iterating workspace members in `CargoProvider.set_lock_version`, the
code subscripted `package["version"]["workspace"]` inside a try/except
block that only caught `NonExistentKey`. If a member's `Cargo.toml`
declared a hardcoded version (`version = "x.y.z"`) instead of
`version.workspace = true`, `package["version"]` was a tomlkit `String`
and the subscript raised `TypeError: string indices must be integers,
not 'str'`, which was not caught and propagated as a crash.

Replace the exception-driven check with an `isinstance` type guard so
the inheritance lookup only runs when `version` is an actual table.

Fixes commitizen-tools#2001

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
….12.1,<3.8 (commitizen-tools#2021)

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: dependabot[bot] <support@github.com>
…ols#2029)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: dependabot[bot] <support@github.com>
…=0.9.17,<0.13 (commitizen-tools#2039)

Signed-off-by: dependabot[bot] <support@github.com>
commitizenbot Bot and others added 22 commits August 24, 2026 14:17
Co-authored-by: Tim Hsiung <26526132+bearomorphism@users.noreply.github.com>
)

Signed-off-by: dependabot[bot] <support@github.com>
)

Signed-off-by: dependabot[bot] <support@github.com>
cz init already treated prek as installed, but always ran
`pre-commit install`, which raised FileNotFoundError when only prek
was on PATH. Use the available installer, and ask when both exist.

Fixes commitizen-tools#2018
If neither pre-commit nor prek is on PATH, skip the hook-type
question instead of failing init. Users who want hooks can
install a tool and retry.
The InitFailedError branch in _ask_hook_installer was flagged by
codecov as the only uncovered line of the PR. Add a test where the
installer is available during the hook-type question but disappears
before the install step, so the guard is exercised instead of
removed.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* ci: restore changelog updates

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* ci: configure changelog updates on bump

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@vemilano

vemilano commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

I checked the fix for #2001 proposed by pull request #2002 and preferred to keep the fix I'm proposing in that pull request. The merged fix introduces a regression, since the try: expect: NonExistentKey block was removed, even though the "version" key is optional for a package.

@bearomorphism @Lee-W @woile , do you know if a review of this pull request is planned? Until it's merged, it's not possible to publish to crates.io with commitizen in a Rust project with a workspace.

To recall the objective of this PR, a project may have a Cargo.toml like this:

[workspace]
members = ["members/*"]
resolver = "2"

[workspace.package]
edition = "2024"
version = "0.1.0"

[workspace.dependencies]
member-hello = { path = "members/hello" }

And the Cargo.toml of the workspace member:

[package]
name = "member-hello"
version.workspace = true

In order to publish on crates.io (cargo publish --workspace), every dependency MUST have a specified version, so we need something like:

[workspace.dependencies]
member-hello = { path = "members/hello", version = "0.1.0" }

But this version is dynamically resolved (because the workspace member has version.workspace = true). So when we want to cz bump:

  • bump workspace version
  • update versions in Cargo.lock
  • update the "version" key for workspace dependencies that have a version specified and match a member inheriting (and handle potentially renamed deps)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CRASH on cargo provider

7 participants