From 9df07027aef23bf33b65b716be3a08362ba424eb Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Wed, 26 Jun 2019 19:29:41 -0500 Subject: [PATCH] TravisCI: Test and lint latest version modules. The current approach of the CI tests of specifying the path to the directory that contains the module only tests version 1 of the module despite there being newer version available. The same is true for the lints. This resolves the test portion by obtaining a list of all modules required by the root go.mod file and providing the entire module path, which includes the version, to the go test command instead of the directory. Unfortunately, the linter does not recognize full module paths, however it will lint the latest module version from within the module directory itself, so this resolves the linting case by stripping the full module path and version down to the directory and changing into the directory to perform the lint checks. --- run_tests.sh | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/run_tests.sh b/run_tests.sh index 3419c276..79852e53 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -41,23 +41,28 @@ testrepo () { cp "$REPO" "$GOPATH/bin/" # run tests on all modules - ROOTPATH=$($GO list -m -f {{.Dir}} 2>/dev/null) + ROOTPATH=$($GO list -m) ROOTPATHPATTERN=$(echo $ROOTPATH | sed 's/\\/\\\\/g' | sed 's/\//\\\//g') - MODPATHS=$($GO list -m -f {{.Dir}} all 2>/dev/null | grep "^$ROOTPATHPATTERN"\ - | sed -e "s/^$ROOTPATHPATTERN//" -e 's/^\\//' -e 's/^\///') - MODPATHS=". $MODPATHS" + MODPATHS=$($GO list -m all | grep "^$ROOTPATHPATTERN" | cut -d' ' -f1) for module in $MODPATHS; do echo "==> ${module}" - env CC=gcc $GO test -short -tags rpctest ./${module}/... + env CC=gcc $GO test -short -tags rpctest ${module}/... # check linters - golangci-lint run --build-tags rpctest --disable-all --deadline=10m \ - --enable=gofmt \ - --enable=gosimple \ - --enable=unconvert \ - --enable=ineffassign \ - --enable=govet \ - --enable=misspell ./${module}/... + MODNAME=$(echo $module | sed -e "s/^$ROOTPATHPATTERN//" \ + -e 's/^\///' -e 's/\/v[0-9]\+$//') + if [ -z "$MODNAME" ]; then + MODNAME=. + fi + (cd $MODNAME && \ + golangci-lint run --build-tags=rpctest --disable-all --deadline=10m \ + --enable=gofmt \ + --enable=gosimple \ + --enable=unconvert \ + --enable=ineffassign \ + --enable=govet \ + --enable=misspell \ + ) done echo "------------------------------------------"