openfga / api

Protocol Buffers used by OpenFGA
Apache License 2.0
19 stars 14 forks source link

CI: pre-commit check for generated files #199

Closed justincoh closed 1 month ago

justincoh commented 1 month ago

Description

When updating a proto file last week, I forgot to update the docs. We have a github action check for this scenario but it's annoying to have to wait for such a simple fix.

This PR adds a ~non~ blocking pre-commit hook to remind the author if the docs or generated files need updating.

It does the following:

  1. If an update to a .proto file is being committed
  2. Check if the /docs and /proto/openfga/ folder are also being committed
  3. If /docs and /proto/openfga/ are being committed, hook exits successfully
  4. If one of the two above is not being committed, ~remind the author to update the docs but also exit successfully (non-blocking)~ block the commit and remind the author to update the generated files.

https://github.com/user-attachments/assets/c9e710f2-47f9-4d78-ba9e-947879e9754d

jpadilla commented 1 month ago

✨ nice!

We have a github action check for this scenario

I wonder if maybe the github action we have today can reuse the same logic introduced in the precommit script?

rhamzeh commented 1 month ago

I deleted my comment b/c realized we're not modifying the github action in this PR.

In a follow up PR, can you fix that?

https://github.com/openfga/api/blob/main/.github/workflows/review.yaml#L33-L36

We don't need to limit to docs and protos, any change anywhere should error.

(not a big issue b/c at the moment, we're not likely to modify those files, but if that changes or e.g. someone updates go.mod manually and keeps go.sum not updated)