-
Notifications
You must be signed in to change notification settings - Fork 78
ci: format TOML files using taplo and enforced CI formatting #1027
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
Conversation
nothingmuch
left a comment
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.
I verified that formatting with taplo results in almost the same TOML files, the comitted ones additionally sort things (presumably CI enforcement of that is in a followup PR?)
This shouldn't be a problem in CI, but in a local env note that running taplo format with direnv in use will find sources in the nix store which are readonly, and error if any toml files therein are inconsistent, that includes any toml file from any package that might end up in the devshell so it's an annoying false positive. I don't see a straightforward way to ignore .direnv, -o exclude=.direnv or -o exclude=.direnv/**/*.toml don't work, i suspect it needs to be added to a config file and TAPLO_CONFIG set in .envrc in order for it to work out of the box with no additional config.
I just used taplo format $( git ls-files | grep '\.toml$' ). If you want to add taplo to devshell in flake.nix you could additionally include a definition for a taplo flake app, so that nix run .#taplo will do the right thing (either use git ls-files or add an exclusion).
Pull Request Test Coverage Report for Build 17336950193Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
|
this will probably generate conflicts for some other PRs, to help merge this with minimum friction please also split it into two commits, one to apply the formatting, which includes the precise command to run (look into bitcoin core's scripted diffs for a standard way to do this), and then the small commit to enforce. this way rebasing it can be automated to avoid conflicts (by replacing the |
7b8f665 to
195cf2f
Compare
|
There are some unintended changes caused in some rust files. I will undo then and improve the commits asap |
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.
i don't see changes to rust files FWIW, but either way to eliminate the merge commit i would suggest the following:
git remote updateand thengit reset --hard origin/master- format all the toml files using
taplo format $( git ls-files | grep '\.toml$' ), andgit commit -a -C f29970d051a6d62ef6968d14b91a2d2cf8e66f37(update: oops i wrote this before fixing the config file, git ls-files no longer necessary so the commit message should be updated, and the config file commit should be cherry-picked before this step) git cherry-pick 765cff7ffddf427ef88ee39c368c6bf679ded828
please also add taplo to the packages list in the devshells in flake.nix
since it detects a config file in the workspace root then tere's no need to setup TAPLO_CONFIG env var like i suggested before, and a nix flake app also seems a bit superfluous (though we might want a fmt program that runs rustfmt, taplo, shfmt, and whatever is a la mode for python these days, but that's definitely for a future PR and not this one)
however the config file does need some corrections in order to have the desired effect
Run: taplo format This standardizes indentation, whitespace, and sorts keys in Cargo.toml files. Scripted-diff: taplo format
- Add taplo.toml config with proper excludes and sorting rules - Run `taplo format --check` in CI using `cargo install taplo-cli` - Add taplo to devShell for easy local use
db6e5ee to
f76057d
Compare
|
see https://github.com/jonatack/bitcoin-development/blob/master/scripted-diffs.md for a description, it just makes it easier to verify that large diffs do exactly what they are supposed to the first one is not a scripted diff as it can't be recreated by just running the command, if i switch to it reset all the toml files to be as they were in the previous commit apart from the taplo.toml file that is introduced, i still can't reproduce the diff exactly since there is some reordering presumably by cargo sort sorry to be a stickler about this but there are multiple PRs that are already open that change dependencies and therefore will conflict with this PR, to avoid blocking those PRs i prefer if we wait with merging this one, making it really a scripted diff means it's trivial to rebase this commit without having to deal with conflicts when it's time to do so if you prefer i could do this for you and rebase it when it's time to merge this (i could also add the flake stuff) |
|
Sure @nothingmuch Thank you |
|
Couple weeks without activity on this PR. |
|
This PR was effectively folded into #1221... Thanks @Cyber-Lord and sorry for taking so long to merge your changes |
Pull Request Checklist
Please confirm the following before requesting review:
AI
in the body of this PR.
In this PR, I have used ChatGPT to research available formatting tools, compared them and identified best fit for this issue #1016
The PR aims to close #1016 by formatting and sorting the TOML files in the repository and introduced a check on CI to enforce formatting.
taplois used for this and ensured consistent whitespace, indentation, and ordering across all TOML files.Added to the GitHub Actions workflow to run
taplo format --checkon pull requests and pushes tomain. This will ensure future PRs don’t introduce formatting inconsistencies in TOML files.