Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Commit

Permalink
Re-add verify codegen script to the CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Jan 23, 2020
1 parent 8b60823 commit 98867b8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ dependency-reduced-pom.xml
velocity.log
velocity.log.*

# Local gopath
/go/
# Local go binary directory
/go-bin/

# Openshift local cluster files
**/openshift.local.clusterup/
Expand Down
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,12 @@ $(GO_DIRS):
ifeq ($(SKIP_TESTS),true)
test_go:
else
test_go: test_go_vet test_go_run
test_go: test_go_vet test_go_codegen test_go_run
endif

test_go_codegen:
GO111MODULE=on ./hack/verify-codegen.sh

test_go_vet:
GO111MODULE=on go vet $(GOOPTS) ./cmd/... ./pkg/...

Expand Down Expand Up @@ -100,9 +103,12 @@ clean_java:
template_clean:
$(MAKE) -C templates clean

clean: clean_java docu_clean template_clean
clean: clean_java clean_go docu_clean template_clean
rm -rf build

clean_go:
rm -Rf go-bin

coverage: java_coverage
$(MAKE) FULL_BUILD=$(FULL_BUILD) -C $@ coverage

Expand Down
15 changes: 9 additions & 6 deletions hack/generate-groups.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ shift 4

SCRIPTPATH="$(cd "$(dirname "$0")" && pwd -P)"
GENERATOR_BASE=${SCRIPTPATH}/../vendor/k8s.io/code-generator
GOBIN="${SCRIPTPATH}/../go-bin"

(
# To support running this script from anywhere, we have to first cd into this directory
# so we can install the tools.
cd "${GENERATOR_BASE}"
go install ./cmd/{defaulter-gen,client-gen,lister-gen,informer-gen,deepcopy-gen}
cd "${SCRIPTPATH}"

mkdir -p "${GOBIN}"
GOBIN="$GOBIN" GO111MODULE=on go install -mod=vendor ${GENERATOR_BASE}/cmd/{defaulter-gen,client-gen,lister-gen,informer-gen,deepcopy-gen}
)

function codegen::join() { local IFS="$1"; shift; echo "$*"; }
Expand All @@ -71,22 +74,22 @@ done

if [ "${GENS}" = "all" ] || grep -qw "deepcopy" <<<"${GENS}"; then
echo "Generating deepcopy funcs"
"${GOPATH}/bin/deepcopy-gen" --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" -O zz_generated.deepcopy --bounding-dirs "${APIS_PKG}" "$@"
"${GOBIN}/deepcopy-gen" --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" -O zz_generated.deepcopy --bounding-dirs "${APIS_PKG}" "$@"
fi

if [ "${GENS}" = "all" ] || grep -qw "client" <<<"${GENS}"; then
echo "Generating clientset for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}"
"${GOPATH}/bin/client-gen" --clientset-name "${CLIENTSET_NAME_VERSIONED:-versioned}" --input-base "" --input "$(codegen::join , "${FQ_APIS[@]}")" --output-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" "$@"
"${GOBIN}/client-gen" --clientset-name "${CLIENTSET_NAME_VERSIONED:-versioned}" --input-base "" --input "$(codegen::join , "${FQ_APIS[@]}")" --output-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" "$@"
fi

if [ "${GENS}" = "all" ] || grep -qw "lister" <<<"${GENS}"; then
echo "Generating listers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/listers"
"${GOPATH}/bin/lister-gen" --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" --output-package "${OUTPUT_PKG}/listers" "$@"
"${GOBIN}/lister-gen" --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" --output-package "${OUTPUT_PKG}/listers" "$@"
fi

if [ "${GENS}" = "all" ] || grep -qw "informer" <<<"${GENS}"; then
echo "Generating informers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/informers"
"${GOPATH}/bin/informer-gen" \
"${GOBIN}/informer-gen" \
--input-dirs "$(codegen::join , "${FQ_APIS[@]}")" \
--versioned-clientset-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}/${CLIENTSET_NAME_VERSIONED:-versioned}" \
--listers-package "${OUTPUT_PKG}/listers" \
Expand Down
4 changes: 2 additions & 2 deletions hack/verify-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ echo "Using tmp base: $TMPBASE"
trap "cleanup" EXIT SIGINT

mkdir -p "$TMPPROJ"
cp -a "$SCRIPTPATH/../" "$TMPPROJ"
cp -dR "$SCRIPTPATH/../" "$TMPPROJ"

"$SCRIPTPATH/update-codegen.sh" --output-base "$TMPBASE"

echo "Comparing existing generated code with temporarily generated code"
if diff -Nur --no-dereference "$SCRIPTPATH/.." "$TMPPROJ"; then
if diff -Nur --no-dereference "$SCRIPTPATH/.." "$TMPPROJ" -x "go-bin"; then
echo "No changes detected in generated code"
else
echo "Generated code is out of date. Run hack/update-codegen.sh and commit the changes."
Expand Down

0 comments on commit 98867b8

Please sign in to comment.