Skip to content

Commit

Permalink
feat: add presubmit validation for generated types
Browse files Browse the repository at this point in the history
  • Loading branch information
jingyih committed Dec 16, 2024
1 parent 1f733cb commit b3c5a12
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
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
15 changes: 15 additions & 0 deletions scripts/validate-prereqs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b3c5a12

Please sign in to comment.