...

Text file src/k8s.io/kubernetes/hack/verify-vendor.sh

Documentation: k8s.io/kubernetes/hack

     1#!/usr/bin/env bash
     2
     3# Copyright 2015 The Kubernetes 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# This script checks whether fixing of vendor directory or go.mod is needed or
    18# not. We should run `hack/update-vendor.sh` if actually fixes them.
    19# Usage: `hack/verify-vendor.sh`.
    20
    21set -o errexit
    22set -o nounset
    23set -o pipefail
    24
    25KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
    26source "${KUBE_ROOT}/hack/lib/init.sh"
    27
    28kube::golang::setup_env
    29
    30# create a nice clean place to put our new vendor tree
    31_tmpdir="$(kube::realpath "$(mktemp -d -t "$(basename "$0").XXXXXX")")"
    32
    33if [[ -z ${KEEP_TMP:-} ]]; then
    34    KEEP_TMP=false
    35fi
    36
    37function cleanup {
    38  # make go module dirs writeable
    39  chmod -R +w "${_tmpdir}"
    40  if [ "${KEEP_TMP}" == "true" ]; then
    41    echo "Leaving ${_tmpdir} for you to examine or copy. Please delete it manually when finished. (rm -rf ${_tmpdir})"
    42  else
    43    echo "Removing ${_tmpdir}"
    44    rm -rf "${_tmpdir}"
    45  fi
    46}
    47kube::util::trap_add cleanup EXIT
    48
    49# Copy the contents of the kube directory into the nice clean place (which is NOT shaped like a GOPATH)
    50_kubetmp="${_tmpdir}/kubernetes"
    51mkdir -p "${_kubetmp}"
    52tar --exclude=.git --exclude="./_*" -c . | (cd "${_kubetmp}" && tar xf -)
    53
    54pushd "${_kubetmp}" > /dev/null 2>&1
    55  # Destroy deps in the copy of the kube tree
    56  rm -rf ./vendor ./LICENSES
    57
    58  # Recreate the vendor tree using the nice clean set we just downloaded
    59  hack/update-vendor.sh
    60popd > /dev/null 2>&1
    61
    62ret=0
    63
    64pushd "${KUBE_ROOT}" > /dev/null 2>&1
    65  # Test for diffs
    66  if ! _out="$(diff -Naupr --ignore-matching-lines='^\s*\"GoVersion\":' go.mod "${_kubetmp}/go.mod")"; then
    67    echo "Your go.mod file is different:" >&2
    68    echo "${_out}" >&2
    69    echo "Vendor Verify failed." >&2
    70    echo "If you're seeing this locally, run the below command to fix your go.mod:" >&2
    71    echo "hack/update-vendor.sh" >&2
    72    ret=1
    73  fi
    74
    75  if ! _out="$(diff -Naupr -x "AUTHORS*" -x "CONTRIBUTORS*" vendor "${_kubetmp}/vendor")"; then
    76    echo "Your vendored results are different:" >&2
    77    echo "${_out}" >&2
    78    echo "Vendor Verify failed." >&2
    79    echo "${_out}" > vendordiff.patch
    80    echo "If you're seeing this locally, run the below command to fix your directories:" >&2
    81    echo "hack/update-vendor.sh" >&2
    82    ret=1
    83  fi
    84
    85  # Verify we are pinned to matching levels
    86  hack/lint-dependencies.sh >&2
    87popd > /dev/null 2>&1
    88
    89if [[ ${ret} -gt 0 ]]; then
    90  exit ${ret}
    91fi
    92
    93# Ensure we can tidy every repo using only its recorded versions
    94for repo in $(kube::util::list_staging_repos); do
    95  pushd "${_kubetmp}/staging/src/k8s.io/${repo}" >/dev/null 2>&1
    96    echo "Tidying k8s.io/${repo}..."
    97    GODEBUG=gocacheverify=1 go mod tidy
    98  popd >/dev/null 2>&1
    99done
   100pushd "${_kubetmp}" >/dev/null 2>&1
   101  echo "Tidying k8s.io/kubernetes..."
   102  GODEBUG=gocacheverify=1 go mod tidy
   103popd >/dev/null 2>&1
   104
   105echo "Vendor Verified."
   106# ex: ts=2 sw=2 et filetype=sh

View as plain text