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

CI: pre-commit check for generated files #199

Merged
merged 9 commits into from
Sep 19, 2024
27 changes: 27 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh
# This is a simple check to remind people to update the swagger docs
# if they have made a change to a proto file. It's not iron-clad and non-blocking,
# but it's better than finding out later in github.

# AMD = added, modified, deleted
files=$(git diff --cached --name-only --diff-filter=AMD)

LIGHT_RED='\033[1;31m'
RESET='\033[0m' # No Color

# naive regex check for .proto extension
if [[ "$files" =~ \.proto ]]
then
# Check if there's a staged diff in /docs
result=$(git diff --cached --raw docs/)
justincoh marked this conversation as resolved.
Show resolved Hide resolved
if [ -n "$result" ]; then
# There is a doc update, assume we're ok and exit
exit 0
else
# Don't block, but warn that the docs need updating.
echo "This commit contains .proto changes but the docs have not been updated."
echo "Your changes were committed, but ${LIGHT_RED}please run 'make all' or this will fail in CI${RESET}\n"
fi
justincoh marked this conversation as resolved.
Show resolved Hide resolved
fi

exit 0
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
all: patch-swagger-doc format

buf-gen:
buf-gen: init-hooks
justincoh marked this conversation as resolved.
Show resolved Hide resolved
./buf.gen.yaml

patch-swagger-doc: buf-gen
./scripts/update_swagger.sh docs/openapiv2/apidocs.swagger.json

format: buf-gen
buf format -w

init-hooks:
justincoh marked this conversation as resolved.
Show resolved Hide resolved
git config --local core.hooksPath .githooks/
justincoh marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ To generate source code from the protobuf definitions contained in this project
> **Note**: You must have [Buf CLI](https://docs.buf.build/installation) installed to run the following command.
>
```bash
./buf.gen.yaml
make buf-gen
justincoh marked this conversation as resolved.
Show resolved Hide resolved
```

The command above will generate source code in the `proto/` directory.
Expand Down
Loading