-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CI: pre-commit check for generated files (#199)
* add pre-commit hook to check for swagger updates * update README with 'make buf-gen' * put correct exit codes in hook * remove unnecessary Makefile addition * update hook to check pb.go files and be blocking * init-hooks -> init-git-hooks Co-authored-by: Will Vedder <[email protected]> * fix makefile dep typo * change hook message wording to be more accurate * update README to point out --no-verify --------- Co-authored-by: Will Vedder <[email protected]>
- Loading branch information
Showing
3 changed files
with
37 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/sh | ||
# This is a simple check to ensure people remember to regenerate the docs | ||
# and the pb.go files if they change a .proto file. | ||
# It's not iron-clad 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 and in the generated pb.go files | ||
docs_change=$(git diff --cached --raw docs/) | ||
go_change=$(git diff --cached --raw proto/openfga/) | ||
if [ -n "$docs_change" ] && [ -n "$go_change" ]; then | ||
# Both were changed, we're good | ||
exit 0 | ||
else | ||
# One of the two directories does not have changes, block this commit | ||
echo "This commit contains .proto changes but either the docs or generated /proto files are not part of this commit." | ||
echo "${LIGHT_RED}Your changes were not committed, please run 'make all' and add the resulting changes${RESET}\n" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
all: patch-swagger-doc format | ||
|
||
buf-gen: | ||
buf-gen: init-git-hooks | ||
./buf.gen.yaml | ||
|
||
patch-swagger-doc: buf-gen | ||
./scripts/update_swagger.sh docs/openapiv2/apidocs.swagger.json | ||
|
||
format: buf-gen | ||
buf format -w | ||
|
||
init-git-hooks: | ||
git config --local core.hooksPath .githooks/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters