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

hack/validate-vendor.bash: fix build dep & script without TRAVIS_BRANCH #369

Merged
merged 1 commit into from
Apr 16, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions hack/validate-vendor.bash
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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)"
Expand Down