forked from golang/dep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate-vendor.bash
executable file
·62 lines (53 loc) · 1.82 KB
/
validate-vendor.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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.
set -e -o pipefail
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"
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
if [ ${#files[@]} -gt 0 ]; then
# This will delete memo section from Gopkg.lock
# See https://github.com/golang/dep/issues/645 for more info
# This should go away after -vendor-only flag will be implemented
# sed -i not used because it works different on MacOS and Linux
TMP_FILE=`mktemp /tmp/Gopkg.lock.XXXXXXXXXX`
sed '/memo = \S*/d' Gopkg.lock > $TMP_FILE
mv $TMP_FILE Gopkg.lock
# We run ensure to and see if we have a diff afterwards
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)"
if [ "$diffs" ]; then
{
echo 'The result of ensure differs'
echo
echo "$diffs"
echo
echo 'Please vendor your package with github.com/golang/dep.'
echo
} >&2
false
else
echo 'Congratulations! All vendoring changes are done the right way.'
fi
else
echo 'No vendor changes in diff.'
fi