-
Notifications
You must be signed in to change notification settings - Fork 378
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
feat(rust): Update Cargo.lock, preserve formatting in Cargo.{toml,lock} #705
feat(rust): Update Cargo.lock, preserve formatting in Cargo.{toml,lock} #705
Conversation
Another note: this also includes some partial typings for Since this is the first "typing extensions" for this repo, I had to touch |
Codecov Report
@@ Coverage Diff @@
## master #705 +/- ##
==========================================
+ Coverage 85.86% 86.77% +0.91%
==========================================
Files 52 55 +3
Lines 6204 6579 +375
Branches 576 616 +40
==========================================
+ Hits 5327 5709 +382
+ Misses 876 869 -7
Partials 1 1
Continue to review full report at Codecov.
|
@fasterthanlime seems reasonable as a stop gap, but could we open a tracking ticket on DefinitelyTyped? Let me know when you've added all the tests you'd like and I'll review. |
|
…n-monorepo scenarios
codecov is happy, I'm mostly happy - still going to add some unit tests to |
So, the windows tests are failing in CI, I got curious and ran them locally (Windows 10, node v15.5.0) and they run just fine here. It's a mystery! 🔎 |
@fasterthanlime I think you're probably getting bitten by line endings, I've had to add |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good to me, and I'm comfortable landing the way it is.
The only real concern I have is if we bump into any significant bugs with the TOML parser, and need to keep fleshing out that test suite -- it might eventually make sense for it to be its own repo.
@@ -4,8 +4,10 @@ | |||
"lib": ["es2018", "dom"], | |||
"rootDir": ".", | |||
"outDir": "build", | |||
"typeRoots": ["./typings", "./node_modules/@types"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL, I've never gotten this fancy with providing custom typings.
@fasterthanlime went ahead and addressed the newline issues for you, IMO this is ready to go. Shall I get it released for you tomorrow? |
@bcoe sounds good to me! Thanks for addressing the newline issue, I keep forgetting Git can be configured to check out with CRLF 🙈 I share your general concern re "parsers vs real world input", although 1) TOML is a relatively simple format compared to, say, YAML 2) I'm happy I found a solution based on that same parser, and not something entirely custom or a pile of regexps. |
Just thought of some more good test cases for the toml-edit part (mostly re: quoted keys and non-basic strings), maybe hold off on the release until I add them in ⏳ |
Supports multi-line strings, literal strings (single-quoted), string escapes, etc. Simpler mechanism to hook into the parser. More toml-edit tests.
Glad I took the time to look at some of the funkier TOML out there, all kinds of strings are now supported, I just want to add support for platform-specific dependencies before this lands: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#platform-specific-dependencies |
Platform-specific dependency support is in, adding a few more tests for good measure... ⌛ |
All unit tests are here, running this against a sample repo to be 101% sure. |
Ran successfully on a couple repositories - a complex private one, and this simple public one: fasterthanlime/release-please-sample#1 @bcoe This PR is ready for prime time! 🚀🐿 |
@fasterthanlime thanks for the contribution 👍 I might just need to learn rust. |
@bcoe thanks for maintaining this repo! Contributing has been a real pleasure If you do find some time to learn some Rust, I have quite a few articles you may enjoy ✨ |
The initial Rust support worked, but it didn't preserve formatting in
Cargo.toml
, because it parsed the whole file using@iarna/toml
and serialized it again, turning inputs like these:Into this:
(note: the spacing is part of the output).
The problem is not so much that it reformats the whole file (also that's annoying too), but that an important comment was lost in translation.
Additionally, with the initial support,
Cargo.lock
was not updated. This resulted in follow-up commits (whenever developers rancargo check
,cargo build
,cargo test
etc. locally) that had "Cargo.lock
update noise", but also, it prevented acargo publish
step from ever working on CI for non-monorepos that were binary crates (and thus have theirCargo.lock
file committed).This PR builds on
@iarna/toml
's low-level API: it introduces aTaggedTOMLParser
, which returns objects instead of string values. Those objects contain the location of the string in the original .toml file. A single function,replaceTomlString
, is exported, which parses a TOML payload, attempts to follow a path into the "object tree", replaces the string, and validates that the result is valid TOML.Both the
CargoToml
andCargoLock
updaters now use that function. Additionally, the code was reorganized a little, some comments were added, common parts were extracted to their own files.The
rust
releaser changes are fairly simple, and its existing tests are mostly untouched (modulo updating the snapshots, since it now preserves formatting!), I'm going to add some more tests to make sure it works both withCargo.lock
present and absent, both in a monorepo and non-monorepo scenario.Fixes #704 🦕