Add vendor-check script, Makefile target and CI step (#581)

This commit is contained in:
Azer Koçulu 2018-02-02 01:14:51 +08:00 committed by Igor Mandrigin
parent b41c4895fe
commit 8b56060e21
3 changed files with 72 additions and 0 deletions

View File

@ -9,10 +9,13 @@ install:
- go get golang.org/x/tools/cmd/cover
- make mock-install
- make lint-install
- make dep-install
jobs:
include:
- stage: Lint
script: make lint
- stage: Vendor Check
script: make vendor-check
- stage: Test unit and integration
script: make test-unit-coverage
- stage: Test e2e on private network

View File

@ -151,3 +151,10 @@ clean: ##@other Cleanup
deep-clean: clean
rm -Rdf .ethereumtest/StatusChain
vendor-check:
@dep ensure
./ci/validate-vendor.sh
dep-install:
go get -u github.com/golang/dep/cmd/dep

62
ci/validate-vendor.sh Executable file
View File

@ -0,0 +1,62 @@
#!/usr/bin/env 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.
#
# This file is a copy of https://github.com/golang/dep/blob/master/hack/validate-vendor.bash
# with some comments added.
set -e -o pipefail
# Is validate upstream empty ?
if [ -z "$VALIDATE_UPSTREAM" ]; then
VALIDATE_REPO='https://github.com/status-im/status-go'
if [ -z "$VALIDATE_BRANCH" ]; then
VALIDATE_BRANCH='develop'
fi
VALIDATE_HEAD="$(git rev-parse --verify HEAD)"
git fetch -q "$VALIDATE_REPO" "refs/heads/$VALIDATE_BRANCH"
VALIDATE_UPSTREAM="$(git rev-parse --verify FETCH_HEAD)"
VALIDATE_COMMIT_DIFF="$VALIDATE_UPSTREAM...$VALIDATE_HEAD"
validate_diff() {
if [ "$VALIDATE_UPSTREAM" != "$VALIDATE_HEAD" ]; then
git diff "$VALIDATE_COMMIT_DIFF" "$@"
fi
}
fi
IFS=$'\n'
files=( $(validate_diff --diff-filter=ACMR --name-only -- 'Gopkg.toml' 'Gopkg.lock' 'vendor/' || true) )
unset IFS
# `files[@]` splits the content of files by whitespace and returns a list.
# `#` returns the number of the lines.
if [ ${#files[@]} -gt 0 ]; then
dep ensure -vendor-only
# Let see if the working directory is clean
diffs="$(git status --porcelain -- vendor Gopkg.toml Gopkg.lock 2>/dev/null)"
if [ "$diffs" ]; then
{
echo 'The contents of vendor differ after "dep ensure":'
echo
echo "$diffs"
echo
echo 'Make sure these commands have been run before committing.'
echo
} >&2
false
else
echo 'Congratulations! All vendoring changes are done the right way.'
fi
else
echo 'No vendor changes in diff.'
fi