sigs.k8s.io/prow@v0.0.0-20240503223140-c5e374dc7eb1/hack/make-rules/verify/codegen.sh (about) 1 #!/usr/bin/env bash 2 # Copyright 2021 The Kubernetes Authors. 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 16 set -o errexit 17 set -o nounset 18 set -o pipefail 19 20 REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd -P)" 21 cd $REPO_ROOT 22 23 # place to stick temp binaries 24 BINDIR="${REPO_ROOT}/_bin" 25 if [[ ! -d "${BINDIR}" ]]; then 26 mkdir "${BINDIR}" 27 fi 28 29 DIFFROOT="${REPO_ROOT}" 30 TMP_DIFFROOT="$(TMPDIR="${BINDIR}" mktemp -d "${BINDIR}/verify-codegen.XXXXX")" 31 32 mkdir -p "${TMP_DIFFROOT}/prow" 33 cp -a "${DIFFROOT}"/pkg/{apis,client,config,gangway,plugins} "${TMP_DIFFROOT}/prow" 34 mkdir -p "${TMP_DIFFROOT}/config/prow/cluster/prowjob-crd" 35 cp -a "${DIFFROOT}/config/prow/cluster/prowjob-crd/prowjob_customresourcedefinition.yaml" "${TMP_DIFFROOT}/config/prow/cluster/prowjob-crd/prowjob_customresourcedefinition.yaml" 36 37 "${REPO_ROOT}/hack/make-rules/update/codegen.sh" 38 39 echo "diffing ${DIFFROOT} against freshly generated codegen" 40 ret=0 41 diff -Naupr "${DIFFROOT}/pkg/apis" "${TMP_DIFFROOT}/prow/apis" || ret=$? 42 diff -Naupr "${DIFFROOT}/pkg/client" "${TMP_DIFFROOT}/prow/client" || ret=$? 43 diff -Naupr "${DIFFROOT}/pkg/config" "${TMP_DIFFROOT}/prow/config" || ret=$? 44 diff -Naupr "${DIFFROOT}/pkg/gangway" "${TMP_DIFFROOT}/prow/gangway" || ret=$? 45 diff -Naupr "${DIFFROOT}/config/prow/cluster/prowjob-crd/prowjob_customresourcedefinition.yaml" "${TMP_DIFFROOT}/config/prow/cluster/prowjob-crd/prowjob_customresourcedefinition.yaml" || ret=$? 46 # Restore so that verify codegen doesn't modify workspace 47 cp -a "${TMP_DIFFROOT}/prow"/{apis,client,config} "${DIFFROOT}"/pkg 48 cp -a "${TMP_DIFFROOT}/config/prow/cluster/prowjob-crd/prowjob_customresourcedefinition.yaml" "${DIFFROOT}/config/prow/cluster/prowjob-crd/prowjob_customresourcedefinition.yaml" 49 50 # Clean up 51 rm -rf "${TMP_DIFFROOT}" 52 53 if [[ ${ret} -eq 0 ]]; then 54 echo "${DIFFROOT} up to date." 55 exit 0 56 fi 57 echo "ERROR: out of date codegen files. Fix with make update-codegen" >&2 58 exit 1