Open zimbatm opened 6 months ago
I am looking into this. I think it should not be too difficult to do. @zimbatm have you put any effort into it yet?
Edit: Small wrinkle.
So making the action itself is pretty trivial, but I realized that the main crux is the formatters. As treefmt
itself does not do any formatting. I'm thinking about how best to handle that.
I haven't touched this yet. I was going to look at https://github.com/goreleaser/goreleaser-action for inspiration, but this one is probably much simpler.
The user is responsible for the dependencies. They might rely on the ones that come with the GitHub action environment. Or install the formatters in a previous step before invoking the treefmt-action step to install and run treefmt.
I can see users installing formatters using nix (via some previous install nix action), or just a simple apt get
etc depending on the runner.
We should have a few examples to help people kick start things with the more popular formatters.
I was going down the path of using nix and having the action accept a list of formatters, which would be installed at runtime.
I like your idea better of just having the user responsible for installing them prior the treefmt-action
running.
Alright, here's my first crack at the action: treefmt-action.
I tested it with act and it all works nicely. I also have a test.yml workflow that uses the action.
The default uses --fail-on-change
, which I believe is the intended use-case for CI, but the action allows (almost all) treefmt
options to be accessed.
Nice.
@isbecker I did notice this:
Currently, if you run this action on a Windows-based runner, it will use the older treefmt version 0.6.1. This is because the newer versions of treefmt are not yet supported on Windows.
I'm only just realising there are no windows artefacts in the releases. @zimbatm, was this just an oversight when configuring go-releaser or was there any issue?
@isbecker nice! Thanks for working on this.
The lack of Windows releases is an oversight. Windows support has yet to be thoroughly tested and might have some issues.
@zimbatm @isbecker I created https://github.com/numtide/treefmt/issues/332 to track this.
@zimbatm @brianmcgee Do you think that the treefmt
project should have a workflow to run treefmt-action
on itself?
I noticed that there is no longer a top-level treefmt.toml
(maybe after the re-write it hasn't been added back yet?).
We're defining the formatter using https://github.com/numtide/treefmt-nix. Then, blueprint automatically creates a check.
We could emit the treefmt.toml
that is being used and have the action run with it as an extra check / demonstrator. :thinking:
On the plus side, it would ensure that treefmt-action is exercised. On the negative side, it will probably complicate maintenance by creating a circular dependency.
We could configure it on the new docs repo to avoid the circular dependency. We could also use a treefmt.toml
in that repo instead of treefmt-nix to make integration easier.
We're defining the formatter using https://github.com/numtide/treefmt-nix. Then, blueprint automatically creates a check.
I see, so no need for it.
On the plus side, it would ensure that treefmt-action is exercised. On the negative side, it will probably complicate maintenance by creating a circular dependency.
Sure, it doesn't seem necessary for the treefmt
project itself anyway. It can be exercised by users of the project :smile:
We could configure it on the new docs repo to avoid the circular dependency. We could also use a treefmt.toml in that repo instead of treefmt-nix to make integration easier.
Makes sense. I was mostly wondering if there's any further action on the issue that I might be able to help with. Let me know if you would like me to look into setting it up for the docs repo.
Next step is to make it more visible.
- Add it to our docs.
Can do. Do you want a new section in the README under the IDE integration section? Also, I can add it to the treefmt-docs repo or to this one. I'm not sure what the status is exactly on that new docs repo.
- If you want, move it next to the main repo?
Meaning in the numtide
org? As in numtide/treefmt-action
? I would be fine with that. Are you looking to take over maintainership or would you add me to the org?
- Publish to GitHub Marketplace.
Already available :slightly_smiling_face: https://github.com/marketplace/actions/treefmt-github-action
Is your feature request related to a problem? Please describe.
There is no easy to to run treefmt inside of github actions without using nix.
Describe the solution you'd like
Provide a github action that installs and invokes treefmt on the current repo.
Describe alternatives you've considered
Create a
curl | sh
installer.Additional context