Skip to content

Commit f8ae6d9

Browse files
author
OpenShift Bot
committed
Merge pull request #277 from soltysh/govet
Merged by openshift-bot
2 parents 7b4665f + 276652b commit f8ae6d9

File tree

7 files changed

+115
-22
lines changed

7 files changed

+115
-22
lines changed

.travis.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ go:
55
- 1.5
66

77
install:
8-
- go get golang.org/x/tools/cmd/cover
9-
- go get -u github.com/golang/lint/golint
10-
- ./hack/verify-gofmt.sh
11-
- ./hack/verify-golint.sh || true
12-
- ./hack/build-go.sh
8+
- make install-travis
139

1410
script:
15-
- STI_RACE="-race" STI_COVER="-cover -covermode=atomic" ./hack/test-go.sh "" -p=4
11+
- make check TESTFLAGS="-p=4" TESTS="''" # empty quotes are because hack/test-go.sh requires 2 args
1612

1713
notifications:
1814
irc: "chat.freenode.net#openshift-dev"
15+
16+
sudo: false

Makefile

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@ all build:
2424
hack/build-go.sh
2525
.PHONY: all build
2626

27+
28+
# Verify code is properly organized.
29+
#
30+
# Example:
31+
# make verify
32+
verify: build
33+
hack/verify-gofmt.sh
34+
hack/verify-golint.sh || true
35+
hack/verify-govet.sh || true
36+
.PHONY: verify
37+
38+
39+
# Install travis dependencies
40+
#
41+
# Example:
42+
# make install-travis
43+
install-travis:
44+
hack/install-tools.sh
45+
.PHONY: install-travis
46+
2747
# Build and run tests.
2848
#
2949
# Args:
@@ -36,8 +56,8 @@ all build:
3656
# make check
3757
# make test
3858
# make check WHAT=pkg/build GOFLAGS=-v
39-
check test:
40-
hack/test-go.sh $(WHAT) $(TESTS)
59+
check test: verify
60+
STI_COVER="-cover -covermode=atomic" STI_RACE="-race" hack/test-go.sh $(WHAT) $(TESTS)
4161
.PHONY: check test
4262

4363
# Remove all build artifacts.

hack/common.sh

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,20 @@ STI_GIT_MINOR='${STI_GIT_MINOR-}'
386386
EOF
387387
}
388388

389+
# golang 1.5 wants `-X key=val`, but golang 1.4- REQUIRES `-X key val`
390+
sti::build::ldflag() {
391+
local key=${1}
392+
local val=${2}
393+
394+
GO_VERSION=($(go version))
395+
396+
if [[ -z $(echo "${GO_VERSION[2]}" | grep -E 'go1.5') ]]; then
397+
echo "-X ${STI_GO_PACKAGE}/pkg/version.${key} ${val}"
398+
else
399+
echo "-X ${STI_GO_PACKAGE}/pkg/version.${key}=${val}"
400+
fi
401+
}
402+
389403
# sti::build::ldflags calculates the -ldflags argument for building STI
390404
sti::build::ldflags() {
391405
(
@@ -399,19 +413,11 @@ sti::build::ldflags() {
399413
sti::build::get_version_vars
400414

401415
declare -a ldflags=()
402-
GO_VERSION=($(go version))
403-
404-
if [[ "${GO_VERSION[2]}" =~ ^go1.4.*$ ]]; then
405-
ldflags+=(-X "${STI_GO_PACKAGE}/pkg/version.majorFromGit" "${STI_GIT_MAJOR}")
406-
ldflags+=(-X "${STI_GO_PACKAGE}/pkg/version.minorFromGit" "${STI_GIT_MINOR}")
407-
ldflags+=(-X "${STI_GO_PACKAGE}/pkg/version.versionFromGit" "${STI_GIT_VERSION}")
408-
ldflags+=(-X "${STI_GO_PACKAGE}/pkg/version.commitFromGit" "${STI_GIT_COMMIT}")
409-
else
410-
ldflags+=(-X "${STI_GO_PACKAGE}/pkg/version.majorFromGit=${STI_GIT_MAJOR}")
411-
ldflags+=(-X "${STI_GO_PACKAGE}/pkg/version.minorFromGit=${STI_GIT_MINOR}")
412-
ldflags+=(-X "${STI_GO_PACKAGE}/pkg/version.versionFromGit=${STI_GIT_VERSION}")
413-
ldflags+=(-X "${STI_GO_PACKAGE}/pkg/version.commitFromGit=${STI_GIT_COMMIT}")
414-
fi
416+
ldflags+=($(sti::build::ldflag "majorFromGit" "${STI_GIT_MAJOR}"))
417+
ldflags+=($(sti::build::ldflag "minorFromGit" "${STI_GIT_MINOR}"))
418+
ldflags+=($(sti::build::ldflag "versionFromGit" "${STI_GIT_VERSION}"))
419+
ldflags+=($(sti::build::ldflag "commitFromGit" "${STI_GIT_COMMIT}"))
420+
415421
# The -ldflags parameter takes a single string, so join the output.
416422
echo "${ldflags[*]-}"
417423
)

hack/install-tools.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
STI_ROOT=$(dirname "${BASH_SOURCE}")/..
6+
source "${STI_ROOT}/hack/common.sh"
7+
8+
GO_VERSION=($(go version))
9+
echo "Detected go version: $(go version)"
10+
11+
go get golang.org/x/tools/cmd/cover github.com/golang/lint/golint golang.org/x/tools/cmd/vet

hack/test-go.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ if [ -z ${STI_RACE+x} ]; then
4646
STI_RACE=""
4747
fi
4848

49-
STI_TIMEOUT=${STI_TIMEOUT:--timeout 30s}
49+
STI_TIMEOUT=${STI_TIMEOUT:--timeout 60s}
5050

5151
if [ "${1-}" != "" ]; then
5252
test_packages="$STI_GO_PACKAGE/$1"

hack/util.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
# Provides simple utility functions
4+
5+
find_files() {
6+
find . -not \( \
7+
\( \
8+
-wholename './_output' \
9+
-o -wholename './_tools' \
10+
-o -wholename './.*' \
11+
-o -wholename './pkg/assets/bindata.go' \
12+
-o -wholename './pkg/assets/*/bindata.go' \
13+
-o -wholename './openshift.local.*' \
14+
-o -wholename '*/Godeps/*' \
15+
\) -prune \
16+
\) -name '*.go' | sort -u
17+
}

hack/verify-govet.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
set -o nounset
4+
set -o pipefail
5+
6+
GO_VERSION=($(go version))
7+
8+
if [[ -z $(echo "${GO_VERSION[2]}" | grep -E 'go1.4|go1.5') ]]; then
9+
echo "Unknown go version '${GO_VERSION}', skipping go vet."
10+
exit 0
11+
fi
12+
13+
STI_ROOT=$(dirname "${BASH_SOURCE}")/..
14+
source "${STI_ROOT}/hack/common.sh"
15+
source "${STI_ROOT}/hack/util.sh"
16+
17+
cd "${STI_ROOT}"
18+
mkdir -p _output/govet
19+
20+
FAILURE=false
21+
test_dirs=$(find_files | cut -d '/' -f 1-2 | sort -u)
22+
for test_dir in $test_dirs
23+
do
24+
go tool vet -shadow=false \
25+
$test_dir
26+
if [ "$?" -ne 0 ]
27+
then
28+
FAILURE=true
29+
fi
30+
done
31+
32+
# We don't want to exit on the first failure of go vet, so just keep track of
33+
# whether a failure occured or not.
34+
if $FAILURE
35+
then
36+
echo "FAILURE: go vet failed!"
37+
exit 1
38+
else
39+
echo "SUCCESS: go vet succeded!"
40+
exit 0
41+
fi

0 commit comments

Comments
 (0)