[lbry] ci: add golangci-lint action
This commit is contained in:
parent
44869b8b01
commit
38a9f69d1e
4 changed files with 245 additions and 90 deletions
55
.github/workflows/go.yml
vendored
55
.github/workflows/go.yml
vendored
|
@ -1,64 +1,29 @@
|
||||||
name: Build and Test
|
name: Build and Test
|
||||||
on: [push, pull_request]
|
on: [push, pull_request]
|
||||||
|
|
||||||
env:
|
|
||||||
# go needs absolute directories, using the $HOME variable doesn't work here.
|
|
||||||
GOCACHE: /home/runner/work/go/pkg/build
|
|
||||||
GOPATH: /home/runner/work/go
|
|
||||||
GO_VERSION: 1.16.8
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
name: Build
|
name: Go CI
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
go: [1.17]
|
||||||
steps:
|
steps:
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: ${{ env.GO_VERSION }}
|
go-version: ${{ matrix.go }}
|
||||||
|
|
||||||
- name: Check out source
|
- name: Check out source
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: make build
|
run: go build ./...
|
||||||
|
|
||||||
test-cover:
|
|
||||||
name: Unit coverage
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Set up Go
|
|
||||||
uses: actions/setup-go@v2
|
|
||||||
with:
|
|
||||||
go-version: ${{ env.GO_VERSION }}
|
|
||||||
|
|
||||||
- name: Check out source
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
run: make unit-cover
|
run: |
|
||||||
|
sh ./goclean.sh
|
||||||
|
|
||||||
- name: Send btcutil coverage
|
- name: Send lbcutil coverage
|
||||||
uses: shogo82148/actions-goveralls@v1
|
uses: shogo82148/actions-goveralls@v1
|
||||||
with:
|
with:
|
||||||
path-to-profile: coverage.txt
|
path-to-profile: profile.cov
|
||||||
|
|
||||||
- name: Send btcutil coverage for psbt package
|
|
||||||
uses: shogo82148/actions-goveralls@v1
|
|
||||||
with:
|
|
||||||
path-to-profile: psbt/coverage.txt
|
|
||||||
|
|
||||||
test-race:
|
|
||||||
name: Unit race
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Set up Go
|
|
||||||
uses: actions/setup-go@v2
|
|
||||||
with:
|
|
||||||
go-version: ${{ env.GO_VERSION }}
|
|
||||||
|
|
||||||
- name: Check out source
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Test
|
|
||||||
run: make unit-race
|
|
||||||
|
|
57
.github/workflows/golangci-lint.yml
vendored
Normal file
57
.github/workflows/golangci-lint.yml
vendored
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
name: golangci-lint
|
||||||
|
|
||||||
|
env:
|
||||||
|
# go needs absolute directories, using the $HOME variable doesn't work here.
|
||||||
|
GOCACHE: /home/runner/work/go/pkg/build
|
||||||
|
GOPATH: /home/runner/work/go
|
||||||
|
GO_VERSION: '^1.17.0'
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- v*
|
||||||
|
branches:
|
||||||
|
- "*"
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- "*"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
golangci:
|
||||||
|
name: lint
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: setup go ${{ env.GO_VERSION }}
|
||||||
|
uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: '${{ env.GO_VERSION }}'
|
||||||
|
|
||||||
|
- name: checkout source
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: compile code
|
||||||
|
run: go install -v ./...
|
||||||
|
|
||||||
|
- name: golangci-lint
|
||||||
|
uses: golangci/golangci-lint-action@v2
|
||||||
|
with:
|
||||||
|
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
|
||||||
|
version: latest
|
||||||
|
|
||||||
|
# Optional: working directory, useful for monorepos
|
||||||
|
# working-directory: somedir
|
||||||
|
|
||||||
|
# Optional: golangci-lint command line arguments.
|
||||||
|
# args: --issues-exit-code=0
|
||||||
|
|
||||||
|
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
||||||
|
# only-new-issues: true
|
||||||
|
|
||||||
|
# Optional: if set to true then the action will use pre-installed Go.
|
||||||
|
skip-go-installation: true
|
||||||
|
|
||||||
|
# Optional: if set to true then the action don't cache or restore ~/go/pkg.
|
||||||
|
# skip-pkg-cache: true
|
||||||
|
|
||||||
|
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
|
||||||
|
# skip-build-cache: true
|
188
.golangci.yml
188
.golangci.yml
|
@ -1,54 +1,152 @@
|
||||||
run:
|
|
||||||
# timeout for analysis
|
|
||||||
deadline: 10m
|
|
||||||
|
|
||||||
linters-settings:
|
linters-settings:
|
||||||
|
depguard:
|
||||||
|
list-type: blacklist
|
||||||
|
packages:
|
||||||
|
# logging is allowed only by logutils.Log, logrus
|
||||||
|
# is allowed to use only in logutils package
|
||||||
|
- github.com/sirupsen/logrus
|
||||||
|
packages-with-error-message:
|
||||||
|
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
|
||||||
|
dupl:
|
||||||
|
threshold: 100
|
||||||
|
funlen:
|
||||||
|
lines: 100
|
||||||
|
statements: 50
|
||||||
|
gci:
|
||||||
|
local-prefixes: github.com/golangci/golangci-lint
|
||||||
|
goconst:
|
||||||
|
min-len: 2
|
||||||
|
min-occurrences: 2
|
||||||
|
gocritic:
|
||||||
|
enabled-tags:
|
||||||
|
- diagnostic
|
||||||
|
- experimental
|
||||||
|
- opinionated
|
||||||
|
- performance
|
||||||
|
- style
|
||||||
|
disabled-checks:
|
||||||
|
- dupImport # https://github.com/go-critic/go-critic/issues/845
|
||||||
|
- ifElseChain
|
||||||
|
- octalLiteral
|
||||||
|
- whyNoLint
|
||||||
|
- wrapperFunc
|
||||||
|
gocyclo:
|
||||||
|
min-complexity: 15
|
||||||
|
goimports:
|
||||||
|
local-prefixes: github.com/golangci/golangci-lint
|
||||||
|
gomnd:
|
||||||
|
settings:
|
||||||
|
mnd:
|
||||||
|
# don't include the "operation" and "assign"
|
||||||
|
checks:
|
||||||
|
- argument
|
||||||
|
- case
|
||||||
|
- condition
|
||||||
|
- return
|
||||||
govet:
|
govet:
|
||||||
# Don't report about shadowed variables
|
check-shadowing: true
|
||||||
check-shadowing: false
|
settings:
|
||||||
gofmt:
|
printf:
|
||||||
# simplify code: gofmt with `-s` option, true by default
|
funcs:
|
||||||
simplify: true
|
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
|
||||||
|
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
|
||||||
|
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
|
||||||
|
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
|
||||||
|
lll:
|
||||||
|
line-length: 140
|
||||||
|
maligned:
|
||||||
|
suggest-new: true
|
||||||
|
misspell:
|
||||||
|
locale: US
|
||||||
|
nolintlint:
|
||||||
|
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
|
||||||
|
allow-unused: false # report any unused nolint directives
|
||||||
|
require-explanation: false # don't require an explanation for nolint directives
|
||||||
|
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
|
||||||
|
|
||||||
linters:
|
linters:
|
||||||
enable-all: true
|
disable-all: true
|
||||||
disable:
|
enable:
|
||||||
# Global variables are used in many places throughout the code base.
|
- asciicheck
|
||||||
- gochecknoglobals
|
- bodyclose
|
||||||
|
# - deadcode
|
||||||
# Some lines are over 80 characters on purpose and we don't want to make them
|
- depguard
|
||||||
# even longer by marking them as 'nolint'.
|
# - dogsled
|
||||||
- lll
|
# - dupl
|
||||||
|
# - errcheck
|
||||||
# We don't care (enough) about misaligned structs to lint that.
|
# - exhaustive
|
||||||
- maligned
|
- exportloopref
|
||||||
|
# - funlen
|
||||||
# We have long functions, especially in tests. Moving or renaming those would
|
# - gochecknoglobals
|
||||||
# trigger funlen problems that we may not want to solve at that time.
|
# - gochecknoinits
|
||||||
- funlen
|
# - gocognit
|
||||||
|
# - goconst
|
||||||
# Disable for now as we haven't yet tuned the sensitivity to our codebase
|
# - gocritic
|
||||||
# yet. Enabling by default for example, would also force new contributors to
|
# - gocyclo
|
||||||
# potentially extensively refactor code, when they want to smaller change to
|
# - godot
|
||||||
# land.
|
# - godox
|
||||||
- gocyclo
|
# - goerr113
|
||||||
|
- gofmt
|
||||||
# Instances of table driven tests that don't pre-allocate shouldn't trigger
|
- goimports
|
||||||
# the linter.
|
# - gomnd
|
||||||
- prealloc
|
- goprintffuncname
|
||||||
|
# - gosec
|
||||||
# Init functions are used by loggers throughout the codebase.
|
# - gosimple
|
||||||
- gochecknoinits
|
# - govet
|
||||||
|
# - ineffassign
|
||||||
# Explicit types are okay.
|
# - interfacer
|
||||||
- interfacer
|
# - lll
|
||||||
|
# - maligned
|
||||||
|
# - misspell
|
||||||
|
- nakedret
|
||||||
|
# - nestif
|
||||||
|
# - noctx
|
||||||
|
# - nolintlint
|
||||||
|
# - prealloc
|
||||||
|
- rowserrcheck
|
||||||
|
# - revive
|
||||||
|
# - scopelint
|
||||||
|
# - staticcheck
|
||||||
|
# - structcheck
|
||||||
|
# - stylecheck
|
||||||
|
# - testpackage
|
||||||
|
# - typecheck
|
||||||
|
- unconvert
|
||||||
|
# - unparam
|
||||||
|
# - unused
|
||||||
|
# - varcheck
|
||||||
|
# - whitespace
|
||||||
|
# - wsl
|
||||||
|
|
||||||
issues:
|
issues:
|
||||||
|
# Excluding configuration per-path, per-linter, per-text and per-source
|
||||||
exclude-rules:
|
exclude-rules:
|
||||||
# Exclude gosec from running for tests so that tests with weak randomness
|
|
||||||
# (math/rand) will pass the linter.
|
|
||||||
- path: _test\.go
|
- path: _test\.go
|
||||||
linters:
|
linters:
|
||||||
- gosec
|
- gomnd
|
||||||
#- errcheck
|
|
||||||
- dupl
|
- path: pkg/golinters/errcheck.go
|
||||||
|
text: "SA1019: errCfg.Exclude is deprecated: use ExcludeFunctions instead"
|
||||||
|
- path: pkg/commands/run.go
|
||||||
|
text: "SA1019: lsc.Errcheck.Exclude is deprecated: use ExcludeFunctions instead"
|
||||||
|
|
||||||
|
# TODO must be removed after the release of the next version (v1.41.0)
|
||||||
|
- path: pkg/commands/run.go
|
||||||
|
linters:
|
||||||
|
- gomnd
|
||||||
|
# TODO must be removed after the release of the next version (v1.41.0)
|
||||||
|
- path: pkg/golinters/nolintlint/nolintlint.go
|
||||||
|
linters:
|
||||||
|
- gomnd
|
||||||
|
# TODO must be removed after the release of the next version (v1.41.0)
|
||||||
|
- path: pkg/printers/tab.go
|
||||||
|
linters:
|
||||||
|
- gomnd
|
||||||
|
|
||||||
|
|
||||||
|
run:
|
||||||
|
skip-dirs:
|
||||||
|
- test/testdata_etc
|
||||||
|
- internal/cache
|
||||||
|
- internal/renameio
|
||||||
|
- internal/robustio
|
||||||
|
|
35
goclean.sh
Executable file
35
goclean.sh
Executable file
|
@ -0,0 +1,35 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# The script does automatic checking on a Go package and its sub-packages, including:
|
||||||
|
# 1. gofmt (http://golang.org/cmd/gofmt/)
|
||||||
|
# 2. goimports (https://github.com/bradfitz/goimports)
|
||||||
|
# 3. golint (https://github.com/golang/lint)
|
||||||
|
# 4. go vet (http://golang.org/cmd/vet)
|
||||||
|
# 5. gosimple (https://github.com/dominikh/go-simple)
|
||||||
|
# 6. unconvert (https://github.com/mdempsky/unconvert)
|
||||||
|
# 7. race detector (http://blog.golang.org/race-detector)
|
||||||
|
# 8. test coverage (http://blog.golang.org/cover)
|
||||||
|
#
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
# Automatic checks
|
||||||
|
for i in $(find . -name go.mod -type f -print); do
|
||||||
|
module=$(dirname ${i})
|
||||||
|
echo "==> ${module}"
|
||||||
|
|
||||||
|
MODNAME=$(echo $module | sed -E -e "s/^$ROOTPATHPATTERN//" \
|
||||||
|
-e 's,^/,,' -e 's,/v[0-9]+$,,')
|
||||||
|
if [ -z "$MODNAME" ]; then
|
||||||
|
MODNAME=.
|
||||||
|
fi
|
||||||
|
|
||||||
|
# run tests
|
||||||
|
(cd $MODNAME &&
|
||||||
|
echo "mode: atomic" > profile.cov && \
|
||||||
|
env GORACE=halt_on_error=1 go test -race -covermode=atomic -coverprofile=profile.tmp ./... && \
|
||||||
|
cat profile.tmp | tail -n +2 >> profile.cov && \
|
||||||
|
rm profile.tmp && \
|
||||||
|
go tool cover -func profile.cov
|
||||||
|
)
|
||||||
|
|
||||||
|
done
|
Loading…
Reference in a new issue