From 81afb9cfdcad5bec5d951a1b56d3d69f8a1cc233 Mon Sep 17 00:00:00 2001 From: John Gardiner Myers Date: Fri, 3 Feb 2023 09:50:30 -0800 Subject: [PATCH] Verify generated files are up to date in merge check (#3007) --- Makefile | 7 ++++++- hack/verify-generate.sh | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100755 hack/verify-generate.sh diff --git a/Makefile b/Makefile index b0483b5b7..053aa090b 100644 --- a/Makefile +++ b/Makefile @@ -68,6 +68,7 @@ helm-lint: ${MAKEFILE_PATH}/test/helm/helm-lint.sh # Generate code +.PHONY: generate generate: aws-sdk-model-override controller-gen mockgen $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." MOCKGEN=$(MOCKGEN) ./scripts/gen_mocks.sh @@ -161,9 +162,13 @@ lint: echo "TODO" .PHONY: quick-ci -quick-ci: verify-versions +quick-ci: verify-versions verify-generate echo "Done!" +.PHONY: verify-generate +verify-generate: + hack/verify-generate.sh + .PHONY: verify-versions verify-versions: hack/verify-versions.sh diff --git a/hack/verify-generate.sh b/hack/verify-generate.sh new file mode 100755 index 000000000..ef9a2a069 --- /dev/null +++ b/hack/verify-generate.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +# Copyright 2023 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -o errexit +set -o nounset +set -o pipefail + +make generate + +changed_files=$(git status --porcelain --untracked-files=no || true) +if [ -n "${changed_files}" ]; then + echo "Detected that generated code is not up to date; run 'make generate'" + echo "changed files:" + printf "%s\n" "${changed_files}" + echo "git diff:" + git --no-pager diff + echo "To fix: run 'make generate'" + exit 1 +fi