Update test script, config and workflow

This commit is contained in:
Daniel
2022-02-02 12:48:29 +01:00
parent e1093d1da0
commit f2fcad4d11
3 changed files with 71 additions and 56 deletions

View File

@@ -44,7 +44,7 @@ jobs:
- name: Run golangci-lint - name: Run golangci-lint
uses: golangci/golangci-lint-action@v2 uses: golangci/golangci-lint-action@v2
with: with:
version: v1.29 version: v1.44
only-new-issues: true only-new-issues: true
args: -c ./.golangci.yml args: -c ./.golangci.yml
skip-go-installation: true skip-go-installation: true
@@ -70,14 +70,16 @@ jobs:
- name: Run go vet - name: Run go vet
run: go vet ./... run: go vet ./...
- name: Install golint # golint is run (sufficiently; with excludes) as a part of golangci-lint.
run: bash -c "GOBIN=$(pwd) go get -u golang.org/x/lint/golint" # - name: Install golint
# run: bash -c "GOBIN=$(pwd) go get -u golang.org/x/lint/golint"
- name: Run golint #
run: ./golint -set_exit_status -min_confidence 1.0 ./... # - name: Run golint
# run: ./golint -set_exit_status -min_confidence 1.0 ./...
- name: Run gofmt # gofmt is run (sufficiently; with excludes) as a part of golangci-lint.
run: bash -c "test -z $(gofmt -s -l .)" # - name: Run gofmt
# run: bash -c 'test -z "$(gofmt -s -l .)"'
test: test:
name: Test name: Test

View File

@@ -1,20 +1,65 @@
# Docs:
# https://golangci-lint.run/usage/linters/
linters: linters:
enable-all: true enable-all: true
disable: disable:
- lll - containedctx
- gochecknoinits - contextcheck
- gochecknoglobals - cyclop
- exhaustivestruct
- forbidigo
- funlen - funlen
- whitespace - gochecknoglobals
- wsl - gochecknoinits
- gocognit
- gocyclo
- goerr113
- gomnd - gomnd
- gomodguard - ifshort
- goerr113 - interfacer
- ireturn
- lll
- nestif
- nilnil
- nlreturn
- noctx
- revive
- tagliatelle
- testpackage - testpackage
- varnamelen
- whitespace
- wrapcheck
- wsl
linters-settings: linters-settings:
revive:
# See https://github.com/mgechev/revive#available-rules for details.
enable-all-rules: true
gci:
# put imports beginning with prefix after 3rd-party packages;
# only support one prefix
# if not set, use goimports.local-prefixes
local-prefixes: github.com/safing
godox: godox:
# report any comments starting with keywords, this is useful for TODO or FIXME comments that # report any comments starting with keywords, this is useful for TODO or FIXME comments that
# might be left in the code accidentally and should be resolved before merging # might be left in the code accidentally and should be resolved before merging
keywords: keywords:
- FIXME - FIXME
gosec:
# To specify a set of rules to explicitly exclude.
# Available rules: https://github.com/securego/gosec#available-rules
excludes:
- G204 # Variables in commands.
- G304 # Variables in file paths.
- G505 # We need crypto/sha1 for non-security stuff. Using `nolint:` triggers another linter.
issues:
exclude-use-default: false
exclude-rules:
- text: "a blank import .*"
linters:
- golint
- text: "ST1000: at least one file in a package should have a package comment.*"
linters:
- stylecheck

50
test
View File

@@ -17,9 +17,9 @@ function help {
echo " install install deps for running tests" echo " install install deps for running tests"
echo "" echo ""
echo "options:" echo "options:"
echo " --scripted dont jump console lines (still use colors)" echo " --scripted don't jump console lines (still use colors)"
echo " --test-only don run linters only tests" echo " --test-only run tests only, no linters"
echo " [package] run tests only on this package" echo " [package] run only on this package"
} }
function run { function run {
@@ -62,22 +62,6 @@ function run {
rm -f $tmpfile rm -f $tmpfile
} }
function checkformat {
if [[ $scripted -eq 0 ]]; then
echo "[......] gofmt $1"
fi
output=$(gofmt -l $GOPATH/src/$1/*.go)
if [[ $output == "" ]]; then
echo -e "${goUp}[\e[01;32m OK \e[00m] gofmt $*"
else
echo -e "${goUp}[\e[01;31m FAIL \e[00m] gofmt $*"
echo "The following files do not conform to gofmt:"
gofmt -l $GOPATH/src/$1/*.go # keeps format
errors=$((errors+1))
fi
}
# get and switch to script dir # get and switch to script dir
baseDir="$( cd "$(dirname "$0")" && pwd )" baseDir="$( cd "$(dirname "$0")" && pwd )"
cd "$baseDir" cd "$baseDir"
@@ -120,11 +104,9 @@ fi
# install # install
if [[ $install -eq 1 ]]; then if [[ $install -eq 1 ]]; then
echo "installing dependencies..." echo "installing dependencies..."
echo "$ go get -u golang.org/x/lint/golint"
go get -u golang.org/x/lint/golint
# TODO: update golangci-lint version regularly # TODO: update golangci-lint version regularly
echo "$ curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.24.0" echo "$ curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.44.0"
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.24.0 curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.44.0
exit 0 exit 0
fi fi
@@ -138,12 +120,6 @@ if [[ $testonly -eq 0 ]]; then
echo "gofmt command not found" echo "gofmt command not found"
exit 1 exit 1
fi fi
if [[ $(which golint) == "" ]]; then
echo "golint command not found"
echo "install with: go get -u golang.org/x/lint/golint"
echo "or run: ./test install"
exit 1
fi
if [[ $(which golangci-lint) == "" ]]; then if [[ $(which golangci-lint) == "" ]]; then
echo "golangci-lint command not found" echo "golangci-lint command not found"
echo "install with: curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin vX.Y.Z" echo "install with: curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin vX.Y.Z"
@@ -158,15 +134,10 @@ fi
# target selection # target selection
if [[ "$1" == "" ]]; then if [[ "$1" == "" ]]; then
# get all packages # get all packages
packages=$(go list ./...) packages=$(go list -e ./...)
else else
# single package testing # single package testing
packages=$(go list -e)/$1 packages=$(go list -e)/$1
if [[ ! -d "$GOPATH/src/$packages" ]]; then
echo "go package $packages does not exist"
help
exit 1
fi
echo "note: only running tests for package $packages" echo "note: only running tests for package $packages"
fi fi
@@ -176,16 +147,13 @@ echo "running tests for ${platformInfo//$'\n'/ }:"
# run vet/test on packages # run vet/test on packages
for package in $packages; do for package in $packages; do
package=${package#github.com/safing/portmaster} packagename=${package#github.com/safing/portmaster} #TODO: could be queried with `go list .`
package=${package#/} packagename=${packagename#/}
package=$PWD/$package
echo "" echo ""
echo $package echo $package
if [[ $testonly -eq 0 ]]; then if [[ $testonly -eq 0 ]]; then
checkformat $package
run golint -set_exit_status -min_confidence 1.0 $package
run go vet $package run go vet $package
run golangci-lint run $package run golangci-lint run $packagename
fi fi
run go test -cover $fullTestFlags $package run go test -cover $fullTestFlags $package
done done