Skip to content

Commit

Permalink
test: misc: Update golangci-lint test to run only in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ginywiny committed Aug 13, 2021
1 parent 9d05a93 commit 62407e2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ linters:
enable:
- goimports
- revive # using revive instead of golint as it runs more quickly
- misspell
- misspell
9 changes: 7 additions & 2 deletions misc/make-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,18 @@ go get golang.org/x/lint/golint # for `golint`-ing
go get golang.org/x/tools/cmd/goimports # for fmt
go get github.com/kevinburke/go-bindata/go-bindata # for compiling in non golang files
go get github.com/dvyukov/go-fuzz/go-fuzz # for fuzzing the mcl lang bits
# heavily recommended to use curl to install instead of go get under https://golangci-lint.run/usage/install/
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.41.1

if in_ci; then
go get -u gopkg.in/alecthomas/gometalinter.v1 && \
mv "$(dirname $(command -v gometalinter.v1))/gometalinter.v1" "$(dirname $(command -v gometalinter.v1))/gometalinter" && \
gometalinter --install # bonus

# heavily recommended to use curl to install instead of go get under https://golangci-lint.run/usage/install/
glc_version = "v1.41.1"
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh > $(go env GOPATH)/bin
# heavily recommended to install specific version of golangci-lint as per https://golangci-lint.run/usage/install/
# used to avoid breaking builds when new linter errors are introduced from a new release (minor or major)
sh -s -- -b $(go env GOPATH)/bin $glc_version
fi
fold_end "Install golang tools"

Expand Down
5 changes: 4 additions & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ if label-block "basic"; then
run-testsuite ./test/test-examples.sh
run-testsuite ./test/test-gotest.sh
run-testsuite ./test/test-gometalinter.sh
run-testsuite ./test/test-golangci-lint.sh
run-testsuite ./test/test-golint.sh # test last, because this test is somewhat arbitrary
# FIXME: this now fails everywhere :(
skip-testsuite ./test/test-reproducible.sh
Expand All @@ -85,6 +84,9 @@ if in_ci; then
run-testsuite ./test/test-gotest.sh --race
run-testsuite ./test/test-integration.sh --race
fi
if label-block "basic"; then
run-testsuite ./test/test-golangci-lint.sh
fi

# XXX: fix and enable these on travis (sudo: go: command not found)
#run-testsuite ./test/test-gotest.sh --root
Expand All @@ -96,6 +98,7 @@ else
REASON="CI server only test" skip-testsuite ./test/test-gotest.sh --race
REASON="CI server only test" skip-testsuite ./test/test-integration.sh
REASON="CI server only test" skip-testsuite ./test/test-integration.sh --race
REASON="CI server only test" skip-testsuite ./test/test-golangci-test.sh

REASON="CI server only test" skip-testsuite ./test/test-gotest.sh --root
REASON="CI server only test" skip-testsuite ./test/test-gotest.sh --root --race
Expand Down
9 changes: 4 additions & 5 deletions test/test-golangci-lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ command -v golangci-lint >/dev/null 2>&1 || { echo >&2 "golangci-lint not found"

# configure settings for test scripts
ROOT=$(dirname "${BASH_SOURCE}")/..
cd "${ROOT}" # Enter mgmt root
cd "${ROOT}" # enter mgmt root
. test/util.sh

failures=''
Expand All @@ -17,7 +17,7 @@ function run-test()
}

# using .golangci.yml config file settings in ROOT
gcl='golangci-lint run'
glc='golangci-lint run'

# commented out from gometalinter linter test
# aligncheck, dupl, errcheck, gas, goconst, gocyclo, gotype, unconvert
Expand All @@ -27,15 +27,14 @@ gcl='golangci-lint run'
# safesql, staticcheck, structcheck, unparam, unused, varcheck

for dir in `find * -maxdepth 9 -type d -not -path 'old/*' -not -path 'old' -not -path 'tmp/*' -not -path 'tmp' -not -path 'vendor/*' -not -path 'examples/*' -not -path 'test/*' -not -path 'interpolate/*'`; do

# doesn't acquire files individually, but treats them as a set of * files
match="$dir/*.go"

if ! ls $match &>/dev/null; then
continue # no *.go files found
fi

run-test $gcl "$dir" || fail_test "golangci-lint did not pass"
run-test $glc "$dir" || fail_test "golangci-lint did not pass"
done

if [[ -n "$failures" ]]; then
Expand All @@ -45,4 +44,4 @@ if [[ -n "$failures" ]]; then
echo
exit 1
fi
echo 'PASS'
echo 'PASS'

0 comments on commit 62407e2

Please sign in to comment.