Skip to content

Commit

Permalink
add codegen validation
Browse files Browse the repository at this point in the history
Add a check validating that generated code is up to date. This would
fail on travis in case a contributor forget to run `make generate-api`.

Signed-off-by: Petr Horacek <phoracek@redhat.com>
  • Loading branch information
phoracek committed Jun 2, 2019
1 parent 6c9fc87 commit fbdcdc5
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Makefile
Expand Up @@ -20,7 +20,7 @@ goimports:
whitespace:
./hack/whitespace.sh --fix

check: whitespace-check vet goimports-check test
check: whitespace-check vet goimports-check generate-api-check test

whitespace-check:
./hack/whitespace.sh
Expand Down Expand Up @@ -77,11 +77,14 @@ generate-manifests:
SRIOV_DP_IMAGE=$(SRIOV_DP_IMAGE) \
SRIOV_CNI_IMAGE=$(SRIOV_CNI_IMAGE) \
KUBEMACPOOL_IMAGE=$(KUBEMACPOOL_IMAGE) \
./hack/build-manifests.sh
./hack/generated-manifests.sh

generate-api:
operator-sdk generate k8s

generate-api-check:
./hack/verify-codegen.sh

.PHONY:
all \
check \
Expand Down
File renamed without changes.
33 changes: 33 additions & 0 deletions hack/verify-codegen.sh
@@ -0,0 +1,33 @@
#!/bin/bash

set -o errexit
set -o nounset
set -o pipefail

SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")/..
DIFFROOT="${SCRIPT_ROOT}/pkg"
TMP_DIFFROOT="${SCRIPT_ROOT}/_tmp/pkg"
_tmp="${SCRIPT_ROOT}/_tmp"

cleanup() {
rm -rf "${_tmp}"
}
trap "cleanup" EXIT SIGINT

cleanup

mkdir -p "${TMP_DIFFROOT}"
cp -a "${DIFFROOT}"/* "${TMP_DIFFROOT}"

make generate-api
echo "diffing ${DIFFROOT} against freshly generated codegen"
ret=0
diff -Naupr "${DIFFROOT}" "${TMP_DIFFROOT}" || ret=$?
cp -a "${TMP_DIFFROOT}"/* "${DIFFROOT}"
if [[ $ret -eq 0 ]]
then
echo "${DIFFROOT} up to date."
else
echo "${DIFFROOT} is out of date. Please run `make generate-api`"
exit 1
fi
16 changes: 16 additions & 0 deletions pkg/apis/networkaddonsoperator/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions pkg/apis/networkaddonsoperator/v1alpha1/zz_generated.defaults.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fbdcdc5

Please sign in to comment.