Update test script, config and workflow
This commit is contained in:
18
.github/workflows/go.yml
vendored
18
.github/workflows/go.yml
vendored
@@ -44,7 +44,7 @@ jobs:
|
||||
- name: Run golangci-lint
|
||||
uses: golangci/golangci-lint-action@v2
|
||||
with:
|
||||
version: v1.29
|
||||
version: v1.44
|
||||
only-new-issues: true
|
||||
args: -c ./.golangci.yml
|
||||
skip-go-installation: true
|
||||
@@ -70,14 +70,16 @@ jobs:
|
||||
- name: Run go vet
|
||||
run: go vet ./...
|
||||
|
||||
- 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 ./...
|
||||
# golint is run (sufficiently; with excludes) as a part of golangci-lint.
|
||||
# - 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 gofmt
|
||||
run: bash -c "test -z $(gofmt -s -l .)"
|
||||
# gofmt is run (sufficiently; with excludes) as a part of golangci-lint.
|
||||
# - name: Run gofmt
|
||||
# run: bash -c 'test -z "$(gofmt -s -l .)"'
|
||||
|
||||
test:
|
||||
name: Test
|
||||
|
||||
@@ -1,20 +1,65 @@
|
||||
# Docs:
|
||||
# https://golangci-lint.run/usage/linters/
|
||||
|
||||
linters:
|
||||
enable-all: true
|
||||
disable:
|
||||
- lll
|
||||
- gochecknoinits
|
||||
- gochecknoglobals
|
||||
- containedctx
|
||||
- contextcheck
|
||||
- cyclop
|
||||
- exhaustivestruct
|
||||
- forbidigo
|
||||
- funlen
|
||||
- whitespace
|
||||
- wsl
|
||||
- gochecknoglobals
|
||||
- gochecknoinits
|
||||
- gocognit
|
||||
- gocyclo
|
||||
- goerr113
|
||||
- gomnd
|
||||
- gomodguard
|
||||
- goerr113
|
||||
- ifshort
|
||||
- interfacer
|
||||
- ireturn
|
||||
- lll
|
||||
- nestif
|
||||
- nilnil
|
||||
- nlreturn
|
||||
- noctx
|
||||
- revive
|
||||
- tagliatelle
|
||||
- testpackage
|
||||
- varnamelen
|
||||
- whitespace
|
||||
- wrapcheck
|
||||
- wsl
|
||||
|
||||
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:
|
||||
# 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
|
||||
keywords:
|
||||
- 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
50
test
@@ -17,9 +17,9 @@ function help {
|
||||
echo " install install deps for running tests"
|
||||
echo ""
|
||||
echo "options:"
|
||||
echo " --scripted dont jump console lines (still use colors)"
|
||||
echo " --test-only don run linters only tests"
|
||||
echo " [package] run tests only on this package"
|
||||
echo " --scripted don't jump console lines (still use colors)"
|
||||
echo " --test-only run tests only, no linters"
|
||||
echo " [package] run only on this package"
|
||||
}
|
||||
|
||||
function run {
|
||||
@@ -62,22 +62,6 @@ function run {
|
||||
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
|
||||
baseDir="$( cd "$(dirname "$0")" && pwd )"
|
||||
cd "$baseDir"
|
||||
@@ -120,11 +104,9 @@ fi
|
||||
# install
|
||||
if [[ $install -eq 1 ]]; then
|
||||
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
|
||||
echo "$ 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.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.44.0
|
||||
exit 0
|
||||
fi
|
||||
|
||||
@@ -138,12 +120,6 @@ if [[ $testonly -eq 0 ]]; then
|
||||
echo "gofmt command not found"
|
||||
exit 1
|
||||
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
|
||||
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"
|
||||
@@ -158,15 +134,10 @@ fi
|
||||
# target selection
|
||||
if [[ "$1" == "" ]]; then
|
||||
# get all packages
|
||||
packages=$(go list ./...)
|
||||
packages=$(go list -e ./...)
|
||||
else
|
||||
# single package testing
|
||||
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"
|
||||
fi
|
||||
|
||||
@@ -176,16 +147,13 @@ echo "running tests for ${platformInfo//$'\n'/ }:"
|
||||
|
||||
# run vet/test on packages
|
||||
for package in $packages; do
|
||||
package=${package#github.com/safing/portmaster}
|
||||
package=${package#/}
|
||||
package=$PWD/$package
|
||||
packagename=${package#github.com/safing/portmaster} #TODO: could be queried with `go list .`
|
||||
packagename=${packagename#/}
|
||||
echo ""
|
||||
echo $package
|
||||
if [[ $testonly -eq 0 ]]; then
|
||||
checkformat $package
|
||||
run golint -set_exit_status -min_confidence 1.0 $package
|
||||
run go vet $package
|
||||
run golangci-lint run $package
|
||||
run golangci-lint run $packagename
|
||||
fi
|
||||
run go test -cover $fullTestFlags $package
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user