diff --git a/.github/scripts/json-schema-drift-check.sh b/.github/scripts/json-schema-drift-check.sh new file mode 100755 index 00000000000..95b02aa9ea6 --- /dev/null +++ b/.github/scripts/json-schema-drift-check.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +set -u + +if ! git diff-index --quiet HEAD --; then + git diff-index HEAD -- + echo "there are uncommitted changes, please commit them before running this check" + exit 1 +fi + +success=true + +if ! make generate-json-schema; then + echo "Generating json schema failed" + success=false +fi + +if ! git diff-index --quiet HEAD --; then + git diff-index HEAD -- + echo "JSON schema drift detected!" + success=false +fi + +if ! $success; then + exit 1 +fi diff --git a/Makefile b/Makefile index d17deddf84e..2fdce6d4b0c 100644 --- a/Makefile +++ b/Makefile @@ -132,10 +132,7 @@ check-go-mod-tidy: check-json-schema-drift: $(call title,Ensure there is no drift between the JSON schema and the code) - @git diff-index --quiet HEAD -- || (echo "there are uncommitted changes, please commit them before running this check" && false) - @make generate-json-schema || (echo "$(RED)$(BOLD)JSON schema drift detected!$(RESET)" && false) - @git diff-index --quiet HEAD -- || (echo "$(RED)$(BOLD)JSON schema drift detected!$(RESET)" && false) - + @.github/scripts/json-schema-drift-check.sh ## Testing targets #################################