posener / goreadme

Generate readme file from Go doc. Now available as a Github action!
MIT License
213 stars 31 forks source link

Add pre-commit support #133

Closed alexandregv closed 1 month ago

alexandregv commented 2 months ago

pre-commit is "A framework for managing and maintaining multi-language pre-commit hooks", so kinda like a local CI. It's a popular tool with a lot of community-made hooks. I thought it would be very handy to have pre-commit support in goreadme, allowing to rewrite the readme each time the doc is changed, even before pushing.

The PR only consists of a new file used by pre-commit, and the new instructions in README. It has no impact on goreadme itself.
I tested it on a private repo and it works well.

alexandregv commented 2 months ago

I just added a commit making the "Use as a command line tool" sentence a header too, since it was currently included in the "GitHub Action" section, which felt wrong. Let me know if that doesn't seem right to you. Btw, a little off-topic, but shouldn't it be updated to go install github.com/posener/goreadme/cmd/goreadme@latest ?

posener commented 2 months ago

Sorry for the late reply.

This is cool.

I have no objection to add it.

Is there any way to test the integration?

alexandregv commented 2 months ago

Hi, thanks for the reply!

I just created a demo repo, here: https://github.com/alexandregv/goreadme-precommit-demo I pushed a main.go file with some sample Go doc, but I voluntarily skipped the pre-commit run, so you can do it yourself.

  1. Install pre-commit: https://pre-commit.com/#install
  2. Clone the demo repo
  3. In the cloned repo, run pre-commit install (to register the hooks in .git/hooks/)
  4. Modify the main.go file so you can commit it
  5. Commit, see the pre-commit logs
  6. Check the modified README ! It should now contain the go doc info I skipped earlier.

You can also force-run pre-commit at all times with pre-commit run --all-files.

posener commented 1 month ago

Looks good. Thanks for the contribution.