From 8b56060e21f0b8a5d29108b4fd0a512b0daa035c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Azer=20Ko=C3=A7ulu?= Date: Fri, 2 Feb 2018 01:14:51 +0800 Subject: [PATCH] Add vendor-check script, Makefile target and CI step (#581) --- .travis.yml | 3 +++ Makefile | 7 +++++ ci/validate-vendor.sh | 62 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100755 ci/validate-vendor.sh diff --git a/.travis.yml b/.travis.yml index 3da5d95c7..65646ebe2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/Makefile b/Makefile index c78235eb8..6a42d6547 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/ci/validate-vendor.sh b/ci/validate-vendor.sh new file mode 100755 index 000000000..75cbde15d --- /dev/null +++ b/ci/validate-vendor.sh @@ -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