From aa0ea79450a1c7549133aab46f5b916efa2364ab Mon Sep 17 00:00:00 2001 From: Zbynek Roubalik <726523+zroubalik@users.noreply.github.com> Date: Sat, 9 Jan 2021 21:39:24 +0100 Subject: [PATCH] fix codegen generation on GH Actions (#1487) Signed-off-by: Zbynek Roubalik --- hack/update-codegen.sh | 18 ++++++++++++------ hack/verify-codegen.sh | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index c1820ccf796..fc585c6674f 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -7,6 +7,12 @@ set -o pipefail SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)} +# At some environments (eg. GitHub Actions), due to $GOPATH setting, the codegen output might not be at the expected path +# in the project repo, therefore we should force the output to the specific directory (see --output-base) +# we need to handle (move) the generated files to the correct location in the repo then +CODEGEN_OUTPUT_BASE="${SCRIPT_ROOT}"/output +CODEGEN_OUTPUT_GENERATED="${CODEGEN_OUTPUT_BASE}"/github.com/kedacore/keda/v2/pkg/generated + # generate the code with: # --output-base because this script should also be able to run inside the vendor dir of # k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir @@ -16,14 +22,14 @@ CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code- bash "${CODEGEN_PKG}"/generate-groups.sh "client,informer,lister" \ github.com/kedacore/keda/v2/pkg/generated github.com/kedacore/keda/v2/api \ keda:v1alpha1 \ - --go-header-file "${SCRIPT_ROOT}"/hack/boilerplate.go.txt + --go-header-file "${SCRIPT_ROOT}"/hack/boilerplate.go.txt --output-base "${CODEGEN_OUTPUT_BASE}" # (Zbynek): If v2 is specified in go.mod, codegen unfortunately outputs to 'v2/pkg/generated' instead of 'pkg/generated', -# therefore we need to move the generated code around the repo a bit -if [ -d v2/pkg/generated ]; then - rm -rf pkg/generated - mv v2/pkg/generated pkg/ - rm -rf v2 +# and since we are using a specific ouput for codegen, we need to move the generated code around the repo a bit +if [ -d "${CODEGEN_OUTPUT_GENERATED}" ]; then + rm -rf "${SCRIPT_ROOT}"/pkg/generated + mv "${CODEGEN_OUTPUT_GENERATED}" "${SCRIPT_ROOT}"/pkg/ + rm -rf "${SCRIPT_ROOT}"/output fi # (Zbynek): Kubebuilder project layout has api under 'api/v1alpha1' diff --git a/hack/verify-codegen.sh b/hack/verify-codegen.sh index b2c49767f2a..1a2473b7bc9 100755 --- a/hack/verify-codegen.sh +++ b/hack/verify-codegen.sh @@ -37,6 +37,6 @@ if [[ $ret -eq 0 ]] then echo "${DIFFROOT} up to date." else - echo "${DIFFROOT} is out of date. Please run make clientset-generate" + echo "${DIFFROOT} is out of date. Please run 'make clientset-generate'" exit 1 fi