From 7a4e4053b75cc0f05158e46084c6a3d7f81d4e39 Mon Sep 17 00:00:00 2001 From: Jess Frazelle Date: Mon, 10 Apr 2017 17:47:45 +0000 Subject: [PATCH] hack/validate-vendor.bash: fix build dep & script without TRAVIS_BRANCH Signed-off-by: Jess Frazelle --- hack/validate-vendor.bash | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/hack/validate-vendor.bash b/hack/validate-vendor.bash index 5c605239b7..770e44563a 100755 --- a/hack/validate-vendor.bash +++ b/hack/validate-vendor.bash @@ -1,4 +1,4 @@ -#!/bin/bash +#!/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. @@ -8,25 +8,31 @@ 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/dep.git' +if [ -z "$VALIDATE_UPSTREAM" ]; then + VALIDATE_REPO='https://github.com/golang/dep.git' VALIDATE_BRANCH='master' + VALIDATE_HEAD="$(git rev-parse --verify HEAD)" + git fetch -q "$VALIDATE_REPO" "refs/heads/$VALIDATE_BRANCH" - TRAVIS_BRANCH="$(git rev-parse --verify FETCH_HEAD)" -fi + VALIDATE_UPSTREAM="$(git rev-parse --verify FETCH_HEAD)" -VALIDATE_HEAD="$(git rev-parse --verify 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=( $(git diff "$TRAVIS_BRANCH...$VALIDATE_HEAD" --diff-filter=ACMR --name-only -- 'Gopkg.toml' 'Gopkg.lock' 'vendor/' || true) ) +files=( $(validate_diff --diff-filter=ACMR --name-only -- 'Gopkg.toml' 'Gopkg.lock' 'vendor/' || true) ) unset IFS if [ ${#files[@]} -gt 0 ]; then # We run ensure to and see if we have a diff afterwards - go build + go build ./cmd/dep ./dep ensure # Let see if the working directory is clean diffs="$(git status --porcelain -- vendor Gopkg.toml Gopkg.lock 2>/dev/null)"