diff --git a/Makefile b/Makefile index e424106a39..9e83ff48d2 100644 --- a/Makefile +++ b/Makefile @@ -391,4 +391,14 @@ BILLING_ACCOUNT ?= 010E8D-490B6B-088E1C operator-e2e-tests: export TEST_ORG_ID=${ORG_ID} export TEST_BILLING_ACCOUNT_ID=${BILLING_ACCOUNT} - cd operator/tests/e2e/ && go test --project-id=${PROJECT_ID} \ No newline at end of file + cd operator/tests/e2e/ && go test --project-id=${PROJECT_ID} + +# Generate Go types for direct resources specified in the config files located under `dev/tools/controllerbuilder/config`. +.PHONY: generate-types +generate-types: + cd dev/tools/controllerbuilder && \ + ./generate-proto.sh && \ + for config in config/*.yaml; do \ + go run . generate-types --config $$config; \ + done + dev/tasks/fix-gofmt diff --git a/scripts/validate-prereqs.sh b/scripts/validate-prereqs.sh index 445b332342..3704b25a05 100755 --- a/scripts/validate-prereqs.sh +++ b/scripts/validate-prereqs.sh @@ -93,3 +93,18 @@ if [[ "${changed_file_count}" != "0" ]] || [[ "${added_reference_doc_file_count} git ls-files --others --exclude-standard scripts/generate-google3-docs/resource-reference/generated/ exit 1 fi + +### This check ensures that the generated Go types for direct resources are not manually modified by accident. +### Ensures that the code generation tools can be safely re-run. +make generate-types +changed_file_count=$(git diff --name-only | wc -l) +if [[ "${changed_file_count}" != "0" ]]; then + echo "Full diff:" + git diff + echo "ERROR: The generated types are outdated. Run 'make generate-types' to update them." + echo "If you need to modify any types, first move them out of the generated file." + echo "Then run 'make generate-types' again to ensure the generated file remains unchanged." + echo "Affected files:" + git diff --name-only + exit 1 +fi \ No newline at end of file