Skip to content
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

github action formatter #312

Open
zimbatm opened this issue Jun 3, 2024 · 15 comments
Open

github action formatter #312

zimbatm opened this issue Jun 3, 2024 · 15 comments
Labels
enhancement New feature or request

Comments

@zimbatm
Copy link
Member

zimbatm commented Jun 3, 2024

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

@zimbatm zimbatm added the enhancement New feature or request label Jun 3, 2024
@isbecker
Copy link
Contributor

isbecker commented Jul 2, 2024

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.

@zimbatm
Copy link
Member Author

zimbatm commented Jul 2, 2024

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.

@brianmcgee
Copy link
Member

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.

@isbecker
Copy link
Contributor

isbecker commented Jul 2, 2024

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.

@isbecker
Copy link
Contributor

isbecker commented Jul 3, 2024

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.

@brianmcgee
Copy link
Member

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?

@zimbatm
Copy link
Member Author

zimbatm commented Jul 3, 2024

@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.

@brianmcgee
Copy link
Member

@zimbatm @isbecker I created #332 to track this.

@isbecker
Copy link
Contributor

isbecker commented Jul 5, 2024

@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?).

@brianmcgee
Copy link
Member

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. 🤔

@zimbatm
Copy link
Member Author

zimbatm commented Jul 5, 2024

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.

@brianmcgee
Copy link
Member

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.

@isbecker
Copy link
Contributor

isbecker commented Jul 8, 2024

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 😄

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.

@zimbatm
Copy link
Member Author

zimbatm commented Jul 11, 2024

Next step is to make it more visible.

  1. Add it to our docs.
  2. If you want, move it next to the main repo?
  3. Publish to GitHub Marketplace.

@isbecker
Copy link
Contributor

  1. 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.

  1. 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?

  1. Publish to GitHub Marketplace.

Already available 🙂
https://github.com/marketplace/actions/treefmt-github-action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants