Browse code

Change go version detection logic

Maciej Szulik authored on 2016/07/29 18:05:48
Showing 5 changed files
... ...
@@ -9,7 +9,7 @@ install:
9 9
   - make install-travis
10 10
 
11 11
 script:
12
-  - make verify
12
+  - PERMISSIVE_GO=y make verify
13 13
 
14 14
 notifications:
15 15
   irc: "chat.freenode.net#openshift-dev"
16 16
new file mode 100644
... ...
@@ -0,0 +1,37 @@
0
+#!/bin/bash
1
+#
2
+# This library holds golang related utility functions.
3
+
4
+# os::golang::verify_go_version ensure the go tool exists and is a viable version.
5
+function os::golang::verify_go_version() {
6
+	if ! which go &>/dev/null; then
7
+		os::log::error "Can't find 'go' in PATH, please fix and retry."
8
+		os::log::error "See http://golang.org/doc/install for installation instructions."
9
+		return 1
10
+	fi
11
+
12
+	local go_version
13
+	go_version=($(go version))
14
+	if [[ "${go_version[2]}" != go1.6* ]]; then
15
+		os::log::info "Detected go version: ${go_version[*]}."
16
+		if [[ -z "${PERMISSIVE_GO:-}" ]]; then
17
+			os::log::error "Please install Go version 1.6 or use PERMISSIVE_GO=y to bypass this check."
18
+			return 1
19
+		else
20
+			os::log::warn "Detected golang version doesn't match preferred Go version for Origin."
21
+			os::log::warn "This version mismatch could lead to differences in execution between this run and the Origin CI systems."
22
+			return 0
23
+		fi
24
+	fi
25
+}
26
+readonly -f os::golang::verify_go_version
27
+
28
+# os::golang::verify_golint_version ensure the golint tool exists.
29
+function os::golang::verify_golint_version() {
30
+	if ! which golint &>/dev/null; then
31
+		os::log::error "Unable to detect 'golint' package."
32
+		os::log::error "To install it, run: 'go get github.com/golang/lint/golint'."
33
+		return 1
34
+	fi
35
+}
36
+readonly -f os::golang::verify_golint_version
... ...
@@ -6,23 +6,18 @@ set -o errexit
6 6
 set -o nounset
7 7
 set -o pipefail
8 8
 
9
-GO_VERSION=($(go version))
10
-
11
-if [[ -z $(echo "${GO_VERSION[2]}" | grep -E 'go1.6') && -z "${FORCE_VERIFY-}"  ]]; then
12
-  echo "Unknown go version '${GO_VERSION}', skipping gofmt." >&2
13
-  exit 0
14
-fi
15
-
16 9
 OS_ROOT=$(dirname "${BASH_SOURCE}")/..
17 10
 source "${OS_ROOT}/hack/lib/init.sh"
18 11
 
12
+os::golang::verify_go_version
13
+
19 14
 cd "${OS_ROOT}"
20 15
 
21 16
 bad_files=$(find_files | xargs gofmt -s -l)
22 17
 if [[ -n "${bad_files}" ]]; then
23
-  echo "!!! gofmt needs to be run on the following files: " >&2
24
-  echo "${bad_files}"
25
-  echo "Try running 'gofmt -s -d [path]'" >&2
26
-  echo "Or autocorrect with 'hack/verify-gofmt.sh | xargs -n 1 gofmt -s -w'" >&2
27
-  exit 1
18
+	echo "!!! gofmt needs to be run on the following files: " >&2
19
+	echo "${bad_files}"
20
+	echo "Try running 'gofmt -s -d [path]'" >&2
21
+	echo "Or autocorrect with 'hack/verify-gofmt.sh | xargs -n 1 gofmt -s -w'" >&2
22
+	exit 1
28 23
 fi
... ...
@@ -3,49 +3,39 @@
3 3
 set -o errexit
4 4
 set -o pipefail
5 5
 
6
-if ! which golint &>/dev/null; then
7
-  echo "Unable to detect 'golint' package"
8
-  echo "To install it, run: 'go get github.com/golang/lint/golint'"
9
-  exit 1
10
-fi
11
-
12
-GO_VERSION=($(go version))
13
-
14
-if [[ -z $(echo "${GO_VERSION[2]}" | grep -E 'go1.6') && -z "${FORCE_VERIFY-}"  ]]; then
15
-  echo "Unknown go version '${GO_VERSION}', skipping golint."
16
-  exit 0
17
-fi
18
-
19 6
 OS_ROOT=$(dirname "${BASH_SOURCE}")/..
20 7
 source "${OS_ROOT}/hack/lib/init.sh"
21 8
 
9
+os::golang::verify_go_version
10
+os::golang::verify_golint_version
11
+
22 12
 cd "${OS_ROOT}"
23 13
 
24 14
 arg="${1:-""}"
25 15
 bad_files=""
26 16
 
27 17
 if [ "$arg" == "-m" ]; then
28
-  head=$(git rev-parse --short HEAD | xargs echo -n)
29
-  set +e
30
-  modified_files=$(git diff-tree --no-commit-id --name-only -r master..$head | \
31
-    grep "^pkg" | grep ".go$" | grep -v "bindata.go$" | grep -v "Godeps" | \
32
-    grep -v "third_party")
33
-  if [ -n "${modified_files}" ]; then
34
-    echo -e "Checking modified files: ${modified_files}\n"
35
-    for f in $modified_files; do golint $f; done
36
-    echo
37
-  fi
38
-  set -e
18
+	head=$(git rev-parse --short HEAD | xargs echo -n)
19
+	set +e
20
+	modified_files=$(git diff-tree --no-commit-id --name-only -r master..$head | \
21
+		grep "^pkg" | grep ".go$" | grep -v "bindata.go$" | grep -v "Godeps" | \
22
+		grep -v "third_party")
23
+	if [ -n "${modified_files}" ]; then
24
+		echo -e "Checking modified files: ${modified_files}\n"
25
+		for f in $modified_files; do golint $f; done
26
+		echo
27
+	fi
28
+	set -e
39 29
 else
40
-  bad_files=$(find_files |
41
-                sort -u |
42
-                sed 's/^.{2}//' |
43
-                xargs -n1 printf "${GOPATH}/src/${OS_GO_PACKAGE}/%s\n" |
44
-                xargs -n1 golint)
30
+	bad_files=$(find_files | \
31
+		sort -u | \
32
+		sed 's/^.{2}//' | \
33
+		xargs -n1 printf "${GOPATH}/src/${OS_GO_PACKAGE}/%s\n" | \
34
+		xargs -n1 golint)
45 35
 fi
46 36
 
47 37
 if [[ -n "${bad_files}" ]]; then
48
-  echo "golint detected following problems:"
49
-  echo "${bad_files}"
50
-  exit 1
38
+	echo "golint detected following problems:"
39
+	echo "${bad_files}"
40
+	exit 1
51 41
 fi
... ...
@@ -3,30 +3,43 @@
3 3
 set -o nounset
4 4
 set -o pipefail
5 5
 
6
-GO_VERSION=($(go version))
7
-
8
-if [[ -z $(echo "${GO_VERSION[2]}" | grep -E 'go1.[6]') && -z "${FORCE_VERIFY-}" ]]; then
9
-  echo "Unknown go version '${GO_VERSION}', skipping go vet."
10
-  exit 0
11
-fi
12
-
13 6
 OS_ROOT=$(dirname "${BASH_SOURCE}")/..
14 7
 source "${OS_ROOT}/hack/lib/init.sh"
15 8
 
9
+os::golang::verify_go_version
10
+
16 11
 cd "${OS_ROOT}"
17 12
 mkdir -p _output/govet
18 13
 
19 14
 os::build::setup_env
20 15
 
21
-FAILURE=false
22
-test_dirs=$(find_files | cut -d '/' -f 1-2 | sort -u)
23
-for test_dir in $test_dirs
24
-do
25
-  go tool vet -shadow=false $test_dir
26
-  if [ "$?" -ne 0 ]
27
-  then
28
-    FAILURE=true
29
-  fi
16
+govet_blacklist=(
17
+	"pkg/auth/ldaputil/client.go:[0-9]+: assignment copies lock value to c: crypto/tls.Config contains sync.Once contains sync.Mutex"
18
+	"pkg/.*/client/clientset_generated/internalclientset/fake/clientset_generated.go:[0-9]+: literal copies lock value from fakePtr: github.com/openshift/origin/vendor/k8s.io/kubernetes/pkg/client/testing/core.Fake"
19
+	"pkg/.*/client/clientset_generated/release_1_3/fake/clientset_generated.go:30: literal copies lock value from fakePtr: github.com/openshift/origin/vendor/k8s.io/kubernetes/pkg/client/testing/core.Fake"
20
+)
21
+
22
+function govet_blacklist_contains() {
23
+	local text=$1
24
+	for blacklist_entry in "${govet_blacklist[@]}"; do
25
+		if grep -Eqx "${blacklist_entry}" <<<"${text}"; then
26
+			# the text we got matches this blacklist entry
27
+			return 0
28
+		fi
29
+	done
30
+	return 1
31
+}
32
+
33
+test_dirs="$(find_files | cut -d '/' -f 1-2 | sort -u)"
34
+for test_dir in ${test_dirs}; do
35
+	if ! result="$(go tool vet -shadow=false "${test_dir}" 2>&1)"; then
36
+		while read -r line; do
37
+			if ! govet_blacklist_contains "${line}"; then
38
+				echo "${line}"
39
+				FAILURE=true
40
+			fi
41
+		done <<<"${result}"
42
+	fi
30 43
 done
31 44
 
32 45
 # For the sake of slowly white-listing `shadow` checks, we need to keep track of which
... ...
@@ -74,11 +87,10 @@ done
74 74
 
75 75
 # We don't want to exit on the first failure of go vet, so just keep track of
76 76
 # whether a failure occurred or not.
77
-if $FAILURE
78
-then
79
-  echo "FAILURE: go vet failed!"
80
-  exit 1
77
+if [[ -n "${FAILURE:-}" ]]; then
78
+	echo "FAILURE: go vet failed!"
79
+	exit 1
81 80
 else
82
-  echo "SUCCESS: go vet succeded!"
83
-  exit 0
81
+	echo "SUCCESS: go vet succeded!"
82
+	exit 0
84 83
 fi