add script to check if changes to vendor are valid

Signed-off-by: Jess Frazelle <acidburn@google.com>
This commit is contained in:
Jess Frazelle 2017-01-17 10:47:53 -08:00 коммит произвёл Jess Frazelle
Родитель bcadbf32ff
Коммит 06cb0c1701
2 изменённых файлов: 49 добавлений и 0 удалений

Просмотреть файл

@ -20,3 +20,4 @@
- go test $(go list ./... | grep -v vendor)
- go build ./hack/licenseok
- find . -path ./vendor -prune -o -type f -name "*.go" -printf '%P\n' | xargs ./licenseok
- ./hack/validate-vendor.bash

48
hack/validate-vendor.bash Executable file
Просмотреть файл

@ -0,0 +1,48 @@
#!/bin/bash
# Copyright 2017 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
#
# This script checks if we changed anything with regard to dependency management
# for our repo and makes sure that it was done in a valid way.
set -e -o pipefail
# TRAVIS_BRANCH is the name of the branch targeted by the pull request.
# but we won't have that set if running locally
if [ -z "$TRAVIS_BRANCH" ]; then
VALIDATE_REPO='git@github.com:golang/nest.git'
VALIDATE_BRANCH='master'
git fetch -q "$VALIDATE_REPO" "refs/heads/$VALIDATE_BRANCH"
TRAVIS_BRANCH="$(git rev-parse --verify FETCH_HEAD)"
fi
VALIDATE_HEAD="$(git rev-parse --verify HEAD)"
IFS=$'\n'
files=( $(git diff "$TRAVIS_BRANCH...$VALIDATE_HEAD" --diff-filter=ACMR --name-only -- 'manifest.json' 'lock.json' 'vendor/' || true) )
unset IFS
if [ ${#files[@]} -gt 0 ]; then
# We run ensure to and see if we have a diff afterwards
go build
./dep ensure
# Let see if the working directory is clean
diffs="$(git status --porcelain -- vendor manifest.json lock.json 2>/dev/null)"
if [ "$diffs" ]; then
{
echo 'The result of ensure differs'
echo
echo "$diffs"
echo
echo 'Please vendor your package with github.com/golang/nest.'
echo
} >&2
false
else
echo 'Congratulations! All vendoring changes are done the right way.'
fi
else
echo 'No vendor changes in diff.'
fi