Skip to content

Commit

Permalink
Merge pull request #123261 from skitt/allow-codegen-verification
Browse files Browse the repository at this point in the history
codegen: don't nuke files if only verifying
  • Loading branch information
k8s-ci-robot committed Feb 17, 2024
2 parents 99a15e0 + 1b1b902 commit 1dce896
Showing 1 changed file with 85 additions and 63 deletions.
148 changes: 85 additions & 63 deletions staging/src/k8s.io/code-generator/generate-internal-groups.sh
Expand Up @@ -55,6 +55,12 @@ echo "WARNING: $(basename "$0") is deprecated."
echo "WARNING: Please use k8s.io/code-generator/kube_codegen.sh instead."
echo

# If verification only is requested, avoid deleting files
verify_only=""
for ((i = 1; i <= $#; i++)); do
if [ "${!i}" = --verify-only ]; then verify_only=1; fi
done

if [ "${GENS}" = "all" ] || grep -qw "all" <<<"${GENS}"; then
ALL="client,conversion,deepcopy,defaulter,informer,lister,openapi"
echo "WARNING: Specifying \"all\" as a generator is deprecated."
Expand Down Expand Up @@ -124,12 +130,14 @@ CLIENTSET_PKG="${CLIENTSET_PKG_NAME:-clientset}"
CLIENTSET_NAME="${CLIENTSET_NAME_VERSIONED:-versioned}"

if grep -qw "deepcopy" <<<"${GENS}"; then
# Nuke existing files
for dir in $(GO111MODULE=on go list -f '{{.Dir}}' "${ALL_FQ_APIS[@]}"); do
pushd "${dir}" >/dev/null
git_find -z ':(glob)**'/zz_generated.deepcopy.go | xargs -0 rm -f
popd >/dev/null
done
if [ ! "$verify_only" ]; then
# Nuke existing files
for dir in $(GO111MODULE=on go list -f '{{.Dir}}' "${ALL_FQ_APIS[@]}"); do
pushd "${dir}" >/dev/null
git_find -z ':(glob)**'/zz_generated.deepcopy.go | xargs -0 rm -f
popd >/dev/null
done
fi

echo "Generating deepcopy funcs"
"${gobin}/deepcopy-gen" \
Expand All @@ -139,12 +147,14 @@ if grep -qw "deepcopy" <<<"${GENS}"; then
fi

if grep -qw "defaulter" <<<"${GENS}"; then
# Nuke existing files
for dir in $(GO111MODULE=on go list -f '{{.Dir}}' "${ALL_FQ_APIS[@]}"); do
pushd "${dir}" >/dev/null
git_find -z ':(glob)**'/zz_generated.defaults.go | xargs -0 rm -f
popd >/dev/null
done
if [ ! "$verify_only" ]; then
# Nuke existing files
for dir in $(GO111MODULE=on go list -f '{{.Dir}}' "${ALL_FQ_APIS[@]}"); do
pushd "${dir}" >/dev/null
git_find -z ':(glob)**'/zz_generated.defaults.go | xargs -0 rm -f
popd >/dev/null
done
fi

echo "Generating defaulters"
"${gobin}/defaulter-gen" \
Expand All @@ -154,12 +164,14 @@ if grep -qw "defaulter" <<<"${GENS}"; then
fi

if grep -qw "conversion" <<<"${GENS}"; then
# Nuke existing files
for dir in $(GO111MODULE=on go list -f '{{.Dir}}' "${ALL_FQ_APIS[@]}"); do
pushd "${dir}" >/dev/null
git_find -z ':(glob)**'/zz_generated.conversion.go | xargs -0 rm -f
popd >/dev/null
done
if [ ! "$verify_only" ]; then
# Nuke existing files
for dir in $(GO111MODULE=on go list -f '{{.Dir}}' "${ALL_FQ_APIS[@]}"); do
pushd "${dir}" >/dev/null
git_find -z ':(glob)**'/zz_generated.conversion.go | xargs -0 rm -f
popd >/dev/null
done
fi

echo "Generating conversions"
"${gobin}/conversion-gen" \
Expand All @@ -171,15 +183,17 @@ fi
if grep -qw "applyconfiguration" <<<"${GENS}"; then
APPLY_CONFIGURATION_PACKAGE="${OUTPUT_PKG}/${APPLYCONFIGURATION_PKG_NAME:-applyconfiguration}"

# Nuke existing files
root="$(GO111MODULE=on go list -f '{{.Dir}}' "${APPLY_CONFIGURATION_PACKAGE}" 2>/dev/null || true)"
if [ -n "${root}" ]; then
pushd "${root}" >/dev/null
git_grep -l --null \
-e '^// Code generated by applyconfiguration-gen. DO NOT EDIT.$' \
':(glob)**/*.go' \
| xargs -0 rm -f
popd >/dev/null
if [ ! "$verify_only" ]; then
# Nuke existing files
root="$(GO111MODULE=on go list -f '{{.Dir}}' "${APPLY_CONFIGURATION_PACKAGE}" 2>/dev/null || true)"
if [ -n "${root}" ]; then
pushd "${root}" >/dev/null
git_grep -l --null \
-e '^// Code generated by applyconfiguration-gen. DO NOT EDIT.$' \
':(glob)**/*.go' \
| xargs -0 rm -f
popd >/dev/null
fi
fi

echo "Generating apply configuration for ${GROUPS_WITH_VERSIONS} at ${APPLY_CONFIGURATION_PACKAGE}"
Expand All @@ -190,15 +204,17 @@ if grep -qw "applyconfiguration" <<<"${GENS}"; then
fi

if grep -qw "client" <<<"${GENS}"; then
# Nuke existing files
root="$(GO111MODULE=on go list -f '{{.Dir}}' "${OUTPUT_PKG}/${CLIENTSET_PKG}/${CLIENTSET_NAME}" 2>/dev/null || true)"
if [ -n "${root}" ]; then
pushd "${root}" >/dev/null
git_grep -l --null \
-e '^// Code generated by client-gen. DO NOT EDIT.$' \
':(glob)**/*.go' \
| xargs -0 rm -f
popd >/dev/null
if [ ! "$verify_only" ]; then
# Nuke existing files
root="$(GO111MODULE=on go list -f '{{.Dir}}' "${OUTPUT_PKG}/${CLIENTSET_PKG}/${CLIENTSET_NAME}" 2>/dev/null || true)"
if [ -n "${root}" ]; then
pushd "${root}" >/dev/null
git_grep -l --null \
-e '^// Code generated by client-gen. DO NOT EDIT.$' \
':(glob)**/*.go' \
| xargs -0 rm -f
popd >/dev/null
fi
fi

echo "Generating clientset for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/${CLIENTSET_PKG}"
Expand All @@ -212,18 +228,20 @@ if grep -qw "client" <<<"${GENS}"; then
fi

if grep -qw "lister" <<<"${GENS}"; then
# Nuke existing files
for gv in "${GROUP_VERSIONS[@]}"; do
root="$(GO111MODULE=on go list -f '{{.Dir}}' "${OUTPUT_PKG}/listers/${gv}" 2>/dev/null || true)"
if [ -n "${root}" ]; then
pushd "${root}" >/dev/null
git_grep -l --null \
-e '^// Code generated by lister-gen. DO NOT EDIT.$' \
':(glob)**/*.go' \
| xargs -0 rm -f
popd >/dev/null
fi
done
if [ ! "$verify_only" ]; then
# Nuke existing files
for gv in "${GROUP_VERSIONS[@]}"; do
root="$(GO111MODULE=on go list -f '{{.Dir}}' "${OUTPUT_PKG}/listers/${gv}" 2>/dev/null || true)"
if [ -n "${root}" ]; then
pushd "${root}" >/dev/null
git_grep -l --null \
-e '^// Code generated by lister-gen. DO NOT EDIT.$' \
':(glob)**/*.go' \
| xargs -0 rm -f
popd >/dev/null
fi
done
fi

echo "Generating listers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/listers"
"${gobin}/lister-gen" \
Expand All @@ -233,15 +251,17 @@ if grep -qw "lister" <<<"${GENS}"; then
fi

if grep -qw "informer" <<<"${GENS}"; then
# Nuke existing files
root="$(GO111MODULE=on go list -f '{{.Dir}}' "${OUTPUT_PKG}/informers/externalversions" 2>/dev/null || true)"
if [ -n "${root}" ]; then
pushd "${root}" >/dev/null
git_grep -l --null \
-e '^// Code generated by informer-gen. DO NOT EDIT.$' \
':(glob)**/*.go' \
| xargs -0 rm -f
popd >/dev/null
if [ ! "$verify_only" ]; then
# Nuke existing files
root="$(GO111MODULE=on go list -f '{{.Dir}}' "${OUTPUT_PKG}/informers/externalversions" 2>/dev/null || true)"
if [ -n "${root}" ]; then
pushd "${root}" >/dev/null
git_grep -l --null \
-e '^// Code generated by informer-gen. DO NOT EDIT.$' \
':(glob)**/*.go' \
| xargs -0 rm -f
popd >/dev/null
fi
fi

echo "Generating informers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/informers"
Expand All @@ -254,12 +274,14 @@ if grep -qw "informer" <<<"${GENS}"; then
fi

if grep -qw "openapi" <<<"${GENS}"; then
# Nuke existing files
for dir in $(GO111MODULE=on go list -f '{{.Dir}}' "${FQ_APIS[@]}"); do
pushd "${dir}" >/dev/null
git_find -z ':(glob)**'/zz_generated.openapi.go | xargs -0 rm -f
popd >/dev/null
done
if [ ! "$verify_only" ]; then
# Nuke existing files
for dir in $(GO111MODULE=on go list -f '{{.Dir}}' "${FQ_APIS[@]}"); do
pushd "${dir}" >/dev/null
git_find -z ':(glob)**'/zz_generated.openapi.go | xargs -0 rm -f
popd >/dev/null
done
fi

echo "Generating OpenAPI definitions for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/openapi"
declare -a OPENAPI_EXTRA_PACKAGES
Expand Down

0 comments on commit 1dce896

Please sign in to comment.