Skip to content

feat(autodiscovery/cargo): switch cargo update to cargo-upgrade #4793

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

Merged
merged 10 commits into from
May 5, 2025

Conversation

loispostula
Copy link
Contributor

Fix #4792

Change the update in the Cargo.toml from toml to shell with cargo-upgrade.

This allows for the change to not reformat the Cargo.toml

Test

To test this pull request, you can run the following commands:

cd <to_package_directory>
go test

Additional Information

Checklist

  • I have updated the documentation via pull request in website repository.

Tradeoff

cargo-edit becomes a requirement for this to work

Potential improvement

@loispostula loispostula changed the title fest(autodiscovery/cargo): switch cargo update to cargo-upgrade feat(autodiscovery/cargo): switch cargo update to cargo-upgrade Apr 9, 2025
@loispostula loispostula requested a review from olblak April 11, 2025 06:36
@olblak
Copy link
Member

olblak commented Apr 11, 2025

This would be a breaking change today, what if the cargo update is not available?
I think it would be better to have a second template if cargo is available then run this
otherwise fallback to the toml plugin.

We uses this approach on the npm plugin which I like, it provides an easy fallback

@loispostula loispostula force-pushed the lp/ad-cargo-improvement branch 6 times, most recently from fbfaa2f to 76d2175 Compare April 29, 2025 19:30
@loispostula loispostula force-pushed the lp/ad-cargo-improvement branch from 76d2175 to 206dd9a Compare April 30, 2025 05:56
@loispostula loispostula marked this pull request as draft April 30, 2025 08:02
@loispostula loispostula marked this pull request as ready for review April 30, 2025 14:48
@olblak olblak added enhancement New feature or request autodiscovery All things related to the autodiscovery feature resource-cargo Related to Rust crate labels May 2, 2025
@olblak olblak requested a review from Copilot May 2, 2025 06:47
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the Cargo plugin to use cargo-upgrade instead of cargo update, preventing unwanted reformatting of Cargo.toml files. Key changes include adding new helper functions to detect cargo and cargo-upgrade availability, updating test cases for various workspace and lockfile scenarios, and modifying the dependency manifest generation to run shell commands when cargo-upgrade is available.

Reviewed Changes

Copilot reviewed 19 out of 20 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/plugins/resources/cargopackage/source_test.go Adds a new test case for retrieving the latest crate-test version.
pkg/plugins/autodiscovery/cargo/utils_test.go Introduces additional tests for cargo file discovery and metadata parsing.
pkg/plugins/autodiscovery/cargo/utils.go Adds helper functions (isCargoAvailable/isCargoUpgradeAvailable) and updates getCrateMetadata.
pkg/plugins/autodiscovery/cargo/testdata/** Updates various Cargo.toml and source files for workspace and lock scenarios with new syntax.
pkg/plugins/autodiscovery/cargo/main.go Adds fields for cargo and cargo-upgrade availability, and switches version filter constant.
pkg/plugins/autodiscovery/cargo/dependencyManifest.go Updates the manifest template to use cargo-upgrade when available.
pkg/plugins/autodiscovery/cargo/dependencies.go Incorporates new metadata fields and refines manifest generation and dependency processing.
Files not reviewed (1)
  • pkg/plugins/autodiscovery/cargo/testdata/.gitignore: Language not supported

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@olblak
Copy link
Member

olblak commented May 2, 2025

I just tested on updatecli-test/kwctl#1
It looks great

@olblak
Copy link
Member

olblak commented May 2, 2025

I think it would be nice to update the documentation to highlight that Updatecli leverages cargo-edit if it's installed

@olblak olblak enabled auto-merge (squash) May 5, 2025 09:58
@olblak olblak merged commit 77c4f59 into main May 5, 2025
6 of 8 checks passed
@olblak olblak deleted the lp/ad-cargo-improvement branch May 5, 2025 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autodiscovery All things related to the autodiscovery feature enhancement New feature or request resource-cargo Related to Rust crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Improve cargo resource
2 participants