Skip to content

Commit 81afb9c

Browse files
johngmyersTimothy-Dougherty
authored andcommitted
Verify generated files are up to date in merge check (kubernetes-sigs#3007)
1 parent d48b683 commit 81afb9c

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ helm-lint:
6868
${MAKEFILE_PATH}/test/helm/helm-lint.sh
6969

7070
# Generate code
71+
.PHONY: generate
7172
generate: aws-sdk-model-override controller-gen mockgen
7273
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
7374
MOCKGEN=$(MOCKGEN) ./scripts/gen_mocks.sh
@@ -161,9 +162,13 @@ lint:
161162
echo "TODO"
162163

163164
.PHONY: quick-ci
164-
quick-ci: verify-versions
165+
quick-ci: verify-versions verify-generate
165166
echo "Done!"
166167

168+
.PHONY: verify-generate
169+
verify-generate:
170+
hack/verify-generate.sh
171+
167172
.PHONY: verify-versions
168173
verify-versions:
169174
hack/verify-versions.sh

hack/verify-generate.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2023 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
make generate
22+
23+
changed_files=$(git status --porcelain --untracked-files=no || true)
24+
if [ -n "${changed_files}" ]; then
25+
echo "Detected that generated code is not up to date; run 'make generate'"
26+
echo "changed files:"
27+
printf "%s\n" "${changed_files}"
28+
echo "git diff:"
29+
git --no-pager diff
30+
echo "To fix: run 'make generate'"
31+
exit 1
32+
fi

0 commit comments

Comments
 (0)