knative.dev/pkg@v0.0.0-20260602142205-ac97e43f6622/hack/verify-codegen.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # Copyright 2018 The Knative Authors
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #     http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  
    17  set -o errexit
    18  set -o nounset
    19  set -o pipefail
    20  
    21  source $(dirname $0)/../vendor/knative.dev/hack/library.sh
    22  
    23  readonly TMP_DIFFROOT="$(mktemp -d ${REPO_ROOT_DIR}/tmpdiffroot.XXXXXX)"
    24  
    25  cleanup() {
    26    rm -rf "${TMP_DIFFROOT}"
    27  }
    28  
    29  trap "cleanup" EXIT SIGINT
    30  
    31  cleanup
    32  
    33  # Save working tree state
    34  mkdir -p "${TMP_DIFFROOT}"
    35  
    36  cp -aR \
    37    "${REPO_ROOT_DIR}/go.sum" \
    38    "${REPO_ROOT_DIR}/apis" \
    39    "${REPO_ROOT_DIR}/logging" \
    40    "${REPO_ROOT_DIR}/testing" \
    41    "${REPO_ROOT_DIR}/vendor" \
    42    "${TMP_DIFFROOT}"
    43  
    44  "${REPO_ROOT_DIR}/hack/update-codegen.sh"
    45  echo "Diffing ${REPO_ROOT_DIR} against freshly generated codegen"
    46  ret=0
    47  
    48  diff -Naupr --no-dereference \
    49    "${REPO_ROOT_DIR}/go.sum" "${TMP_DIFFROOT}/go.sum" || ret=1
    50  
    51  diff -Naupr --no-dereference \
    52    "${REPO_ROOT_DIR}/apis" "${TMP_DIFFROOT}/apis" || ret=1
    53  
    54  diff -Naupr --no-dereference \
    55    "${REPO_ROOT_DIR}/logging" "${TMP_DIFFROOT}/logging" || ret=1
    56  
    57  diff -Naupr --no-dereference \
    58    "${REPO_ROOT_DIR}/testing" "${TMP_DIFFROOT}/testing" || ret=1
    59  
    60  diff -Naupr --no-dereference \
    61    "${REPO_ROOT_DIR}/vendor" "${TMP_DIFFROOT}/vendor" || ret=1
    62  
    63  # Restore working tree state
    64  rm -fr \
    65    "${REPO_ROOT_DIR}/go.sum" \
    66    "${REPO_ROOT_DIR}/apis" \
    67    "${REPO_ROOT_DIR}/logging" \
    68    "${REPO_ROOT_DIR}/testing" \
    69    "${REPO_ROOT_DIR}/vendor"
    70  
    71  cp -aR "${TMP_DIFFROOT}"/* "${REPO_ROOT_DIR}"
    72  
    73  if [[ $ret -eq 0 ]]
    74  then
    75    echo "${REPO_ROOT_DIR} up to date."
    76   else
    77    echo "${REPO_ROOT_DIR} is out of date. Please run hack/update-codegen.sh"
    78    exit 1
    79  fi