From 6ecbc8544838e6727f2d67109b844ca7e57727ee Mon Sep 17 00:00:00 2001 From: Mike Dame Date: Fri, 3 Apr 2020 12:01:37 -0400 Subject: [PATCH] Add hack/{update,verify}-vendor.sh scripts --- .gitignore | 2 + .travis.yml | 1 + hack/update-vendor.sh | 21 +++++++++++ hack/verify-vendor.sh | 88 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 112 insertions(+) create mode 100755 hack/update-vendor.sh create mode 100755 hack/verify-vendor.sh diff --git a/.gitignore b/.gitignore index 88ddcdf4d..eb94dbb3e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ _output/ +_tmp/ +vendordiff.patch diff --git a/.travis.yml b/.travis.yml index c473ce657..ccaddd2c7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,6 +25,7 @@ script: - mkdir -p ~/gopath/src/sigs.k8s.io/ - mv ~/gopath/src/github.com/kubernetes-sigs/descheduler ~/gopath/src/sigs.k8s.io/. - hack/verify-gofmt.sh +- hack/verify-vendor.sh - make lint - make build - make test-unit diff --git a/hack/update-vendor.sh b/hack/update-vendor.sh new file mode 100755 index 000000000..71d512354 --- /dev/null +++ b/hack/update-vendor.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# Copyright 2020 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +source "$(dirname "${BASH_SOURCE}")/lib/init.sh" + +go mod tidy +go mod vendor diff --git a/hack/verify-vendor.sh b/hack/verify-vendor.sh new file mode 100755 index 000000000..918c6385b --- /dev/null +++ b/hack/verify-vendor.sh @@ -0,0 +1,88 @@ +#!/bin/bash + +# Copyright 2020 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This is mostly copied from the hack/verify-vendor.sh script located in k8s.io/kubernetes + +set -o errexit +set -o nounset +set -o pipefail + +source "$(dirname "${BASH_SOURCE}")/lib/init.sh" + +DESCHEDULER_ROOT=$(dirname "${BASH_SOURCE}")/.. + +mkdir -p "${DESCHEDULER_ROOT}/_tmp" +_tmpdir="$(mktemp -d "${DESCHEDULER_ROOT}/_tmp/kube-vendor.XXXXXX")" + +if [[ -z ${KEEP_TMP:-} ]]; then + KEEP_TMP=false +fi + +function cleanup { + # make go module dirs writeable + chmod -R +w "${_tmpdir}" + if [ "${KEEP_TMP}" == "true" ]; then + echo "Leaving ${_tmpdir} for you to examine or copy. Please delete it manually when finished. (rm -rf ${_tmpdir})" + else + echo "Removing ${_tmpdir}" + rm -rf "${_tmpdir}" + fi +} +trap "cleanup" EXIT + +_deschedulertmp="${_tmpdir}" +mkdir -p "${_deschedulertmp}" + +git archive --format=tar --prefix=descheduler/ "$(git write-tree)" | (cd "${_deschedulertmp}" && tar xf -) +_deschedulertmp="${_deschedulertmp}/descheduler" + +pushd "${_deschedulertmp}" > /dev/null 2>&1 + # Destroy deps in the copy of the kube tree + rm -rf ./vendor + + # Recreate the vendor tree using the nice clean set we just downloaded + hack/update-vendor.sh +popd > /dev/null 2>&1 + +ret=0 + +pushd "${DESCHEDULER_ROOT}" > /dev/null 2>&1 + # Test for diffs + if ! _out="$(diff -Naupr --ignore-matching-lines='^\s*\"GoVersion\":' go.mod "${_deschedulertmp}/go.mod")"; then + echo "Your go.mod file is different:" >&2 + echo "${_out}" >&2 + echo "Vendor Verify failed." >&2 + echo "If you're seeing this locally, run the below command to fix your go.mod:" >&2 + echo "hack/update-vendor.sh" >&2 + ret=1 + fi + + if ! _out="$(diff -Naupr -x "BUILD" -x "AUTHORS*" -x "CONTRIBUTORS*" vendor "${_deschedulertmp}/vendor")"; then + echo "Your vendored results are different:" >&2 + echo "${_out}" >&2 + echo "Vendor Verify failed." >&2 + echo "${_out}" > vendordiff.patch + echo "If you're seeing this locally, run the below command to fix your directories:" >&2 + echo "hack/update-vendor.sh" >&2 + ret=1 + fi +popd > /dev/null 2>&1 + +if [[ ${ret} -gt 0 ]]; then + exit ${ret} +fi + +echo "Vendor Verified."