From a0ba435efb6686e945682bd5cae049c26cc0169a Mon Sep 17 00:00:00 2001 From: Tomas Kral Date: Wed, 7 Dec 2016 13:08:19 +0100 Subject: [PATCH] Add check-vendor script This checks vendor dir for nested vendors and if vendor has been cleaned by glide-vc --- .travis.yml | 3 ++ Makefile | 3 ++ script/check-vendor | 70 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100755 script/check-vendor diff --git a/.travis.yml b/.travis.yml index 3da98a63..b9134a52 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,11 +11,14 @@ go: before_install: - go get github.com/mattn/goveralls - go get github.com/modocache/gover + - go get github.com/Masterminds/glide + - go get github.com/sgotti/glide-vc install: - true script: + - make check-vendor - make validate - make test-unit-cover # gover collects all .coverprofile files and saves it to one file gover.coverprofile diff --git a/Makefile b/Makefile index 61cdd4c3..c5b7bab8 100644 --- a/Makefile +++ b/Makefile @@ -54,3 +54,6 @@ lint: ./script/make.sh validate-lint gofmt: ./script/make.sh validate-gofmt + +check-vendor: + ./script/make.sh check-vendor diff --git a/script/check-vendor b/script/check-vendor new file mode 100755 index 00000000..f4e4c6a0 --- /dev/null +++ b/script/check-vendor @@ -0,0 +1,70 @@ +#!/bin/bash + +# Copyright 2016 The Kubernetes Authors All rights reserved. +# +# 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. + + + +# Check if there are nested vendor dirs inside Kompose vendor. +# All dependencies should be flattened and there shouldn't be vendor in inside vendor. +function check_nested_vendor() { + echo "Checking if there are nested vendor dirs" + + # count all vendor directories inside Kompose vendor + NO_NESTED_VENDORS=$(find vendor/ -type d | sed 's/^[^/]*.//g' | grep -E "vendor$" | grep -v _vendor | wc -l) + + if [ $NO_NESTED_VENDORS -ne 0 ]; then + echo "ERROR" + echo " There are $NO_NESTED_VENDORS nested vendors in Kompose vendor directory" + echo " Please run 'glide update --strip-vendor'" + return 1 + else + echo "OK" + return 0 + fi +} + + +# Check if Kompose vendor directory was cleaned by glide-vc +function check_glide-vc() { + echo "Checking if vendor was cleaned using glide-vc." + + # dry run glide-vc and count how many could be deleted. + NO_DELETED_FILES=$($GOPATH/bin/glide-vc --only-code --no-tests --dryrun | wc -l) + + if [ $NO_DELETED_FILES -ne 0 ]; then + echo "ERROR" + echo " There are $NO_DELETED_FILES files that can be deleted by glide-vc." + echo " Please run 'glide-vc --only-code --no-tests'" + return 1 + else + echo "OK" + return 0 + fi +} + + +# Run both checks and exit report fail exit code if one of them failed. +check_nested_vendor +VENDOR_CHECK=$? + +check_glide-vc +VC_CHECK=$? + +if [ $VENDOR_CHECK -eq 0 ] && [ $VC_CHECK -eq 0 ]; then + exit 0 +else + exit 1 +fi +