diff --git a/.github/stablilize_testdata_timestamps.sh b/.github/stablilize_testdata_timestamps.sh index 4b0379fcd6..87dba10351 100644 --- a/.github/stablilize_testdata_timestamps.sh +++ b/.github/stablilize_testdata_timestamps.sh @@ -1,4 +1,4 @@ -#!/bin/env bash +#!/usr/bin/env bash display_usage() { echo -e "Usage: $0 PATH_TO_REPOSITORY_ROOT\n" diff --git a/lint.sh b/lint.sh new file mode 100644 index 0000000000..b490315ead --- /dev/null +++ b/lint.sh @@ -0,0 +1,32 @@ +#/usr/bin/env bash + +set -ex + +# The script uses golangci-lint (github.com/golangci/golangci-lint) to run all +# linters defined by the configuration in .golangci.yml on every module in the +# repository. + +go version + +# loop all modules +ROOTPKG=$(go list) +ROOTPKGPATTERN=$(echo $ROOTPKG | sed 's,\\,\\\\,g' | sed 's,/,\\/,g') +MODPATHS=$(go list -m all | grep "^$ROOTPKGPATTERN" | cut -d' ' -f1) +for module in $MODPATHS; do + echo "==> lint ${module}" + + # determine module directory + MODNAME=$(echo $module | sed -E -e "s/^$ROOTPKGPATTERN//" \ + -e 's,^/,,' -e 's,/v[0-9]+$,,') + if [ -z "$MODNAME" ]; then + MODNAME=. + fi + + # run commands in the module directory as a subshell + ( + cd $MODNAME + + # run linters + golangci-lint run + ) +done diff --git a/run_tests.sh b/run_tests.sh index 93ad77c2b9..bb84ce6ffc 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -1,18 +1,10 @@ -#!/bin/sh +#!/usr/bin/env bash set -ex -# The script does automatic checking on a Go package and its sub-packages, -# including: -# 1. gofmt (https://golang.org/cmd/gofmt/) -# 2. gosimple (https://github.com/dominikh/go-simple) -# 3. unconvert (https://github.com/mdempsky/unconvert) -# 4. ineffassign (https://github.com/gordonklaus/ineffassign) -# 5. go vet (https://golang.org/cmd/vet) -# 6. misspell (https://github.com/client9/misspell) - -# golangci-lint (github.com/golangci/golangci-lint) is used to run each -# static checker. +# This script runs the tests for all packages in all Go modules in the +# repository and then runs the linters for all Go modules in the repository by +# invoking the separate linter script. go version @@ -21,27 +13,8 @@ echo "==> test all modules" ROOTPKG=$(go list) go test -short -tags rpctest $ROOTPKG/... -# loop all modules -ROOTPKGPATTERN=$(echo $ROOTPKG | sed 's,\\,\\\\,g' | sed 's,/,\\/,g') -MODPATHS=$(go list -m all | grep "^$ROOTPKGPATTERN" | cut -d' ' -f1) -for module in $MODPATHS; do - echo "==> lint ${module}" - - # determine module directory - MODNAME=$(echo $module | sed -E -e "s/^$ROOTPKGPATTERN//" \ - -e 's,^/,,' -e 's,/v[0-9]+$,,') - if [ -z "$MODNAME" ]; then - MODNAME=. - fi - - # run commands in the module directory as a subshell - ( - cd $MODNAME - - # run linters - golangci-lint run - ) -done +# run linters on all modules +source ./lint.sh echo "------------------------------------------" echo "Tests completed successfully!"