Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
add script to check if changes to vendor are valid
Browse files Browse the repository at this point in the history
Signed-off-by: Jess Frazelle <[email protected]>
  • Loading branch information
jessfraz committed Jan 19, 2017
1 parent bcadbf3 commit 06cb0c1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 48 additions & 0 deletions hack/validate-vendor.bash
Original file line number Diff line number Diff line change
@@ -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='[email protected]: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

0 comments on commit 06cb0c1

Please sign in to comment.