feat(test): Add Drone + golangci
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
27cedaf857
commit
25ce5323a4
95
.drone.yml
Normal file
95
.drone.yml
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
|
name: test-pipeline
|
||||||
|
|
||||||
|
platform:
|
||||||
|
os: linux
|
||||||
|
arch: amd64
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: environment
|
||||||
|
image: golang:1.19
|
||||||
|
commands:
|
||||||
|
- go version
|
||||||
|
- go env
|
||||||
|
volumes:
|
||||||
|
- name: gopath
|
||||||
|
path: /go
|
||||||
|
|
||||||
|
- name: tools
|
||||||
|
image: golang:1.19
|
||||||
|
commands:
|
||||||
|
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.50.1
|
||||||
|
- go install github.com/tebeka/go2xunit@latest
|
||||||
|
- go install github.com/t-yuki/gocover-cobertura@latest
|
||||||
|
volumes:
|
||||||
|
- name: gopath
|
||||||
|
path: /go
|
||||||
|
depends_on:
|
||||||
|
- environment
|
||||||
|
|
||||||
|
- name: tidy
|
||||||
|
image: golang:1.19
|
||||||
|
commands:
|
||||||
|
- go mod tidy
|
||||||
|
- git diff --exit-code -- go.mod go.sum
|
||||||
|
volumes:
|
||||||
|
- name: gopath
|
||||||
|
path: /go
|
||||||
|
depends_on:
|
||||||
|
- tools
|
||||||
|
|
||||||
|
- name: lint
|
||||||
|
image: golang:1.19
|
||||||
|
commands:
|
||||||
|
- echo 'Running linting'
|
||||||
|
- golangci-lint run
|
||||||
|
volumes:
|
||||||
|
- name: gopath
|
||||||
|
path: /go
|
||||||
|
depends_on:
|
||||||
|
- tools
|
||||||
|
|
||||||
|
- name: test
|
||||||
|
image: golang:1.19
|
||||||
|
commands:
|
||||||
|
- go test -cover -v ./...
|
||||||
|
volumes:
|
||||||
|
- name: gopath
|
||||||
|
path: /go
|
||||||
|
depends_on:
|
||||||
|
- tools
|
||||||
|
|
||||||
|
- name: send telegram notification
|
||||||
|
image: appleboy/drone-telegram
|
||||||
|
settings:
|
||||||
|
token:
|
||||||
|
from_secret: telegram_token
|
||||||
|
to:
|
||||||
|
from_secret: telegram_chat_id
|
||||||
|
message: >
|
||||||
|
{{#success build.status}}
|
||||||
|
✅ Build *#{{build.number}}* of *{{repo.name}}* succeeded.
|
||||||
|
{{else}}
|
||||||
|
❌ Build *#{{build.number}}* of *{{repo.name}}* failed.
|
||||||
|
{{/success}}
|
||||||
|
|
||||||
|
📝 Commit on *{{commit.branch}}*:
|
||||||
|
|
||||||
|
``` {{commit.message}} ```
|
||||||
|
|
||||||
|
🌐 {{ build.link }}
|
||||||
|
format: markdown
|
||||||
|
when:
|
||||||
|
status:
|
||||||
|
- failure
|
||||||
|
- success
|
||||||
|
depends_on:
|
||||||
|
- test
|
||||||
|
- lint
|
||||||
|
- tidy
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- name: gopath
|
||||||
|
temp: {}
|
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
/.vscode/
|
||||||
|
/gouick*
|
||||||
|
|
||||||
|
.DS_Store
|
||||||
|
.idea
|
||||||
|
*.i*
|
209
.golangci.yml
Normal file
209
.golangci.yml
Normal file
@ -0,0 +1,209 @@
|
|||||||
|
---
|
||||||
|
# options for analysis running
|
||||||
|
run:
|
||||||
|
# timeout for analysis, e.g. 30s, 5m, default is 1m
|
||||||
|
timeout: 2m
|
||||||
|
|
||||||
|
issues:
|
||||||
|
exclude:
|
||||||
|
- ST1000
|
||||||
|
- ST1003
|
||||||
|
- var-naming
|
||||||
|
- package-comments
|
||||||
|
# Excluding configuration per-path, per-linter, per-text and per-source
|
||||||
|
exclude-rules:
|
||||||
|
# Exclude some linters from running on tests files.
|
||||||
|
- path: _test\.go
|
||||||
|
linters:
|
||||||
|
- gocyclo
|
||||||
|
- errcheck
|
||||||
|
- dupl
|
||||||
|
- gosec
|
||||||
|
# Exclude known linters from partially hard-vendored code,
|
||||||
|
# which is impossible to exclude via `nolint` comments.
|
||||||
|
- path: internal/hmac/
|
||||||
|
text: "weak cryptographic primitive"
|
||||||
|
linters:
|
||||||
|
- gosec
|
||||||
|
# Exclude `lll` issues for long lines with `go:generate`.
|
||||||
|
- linters:
|
||||||
|
- lll
|
||||||
|
source: "^//go:generate "
|
||||||
|
|
||||||
|
exclude-use-default: false
|
||||||
|
|
||||||
|
# Maximum count of issues with the same text.
|
||||||
|
# Set to 0 to disable.
|
||||||
|
# Default: 3
|
||||||
|
max-same-issues: 3
|
||||||
|
# Maximum issues count per one linter.
|
||||||
|
# Set to 0 to disable.
|
||||||
|
# Default: 50
|
||||||
|
max-issues-per-linter: 50
|
||||||
|
|
||||||
|
fix: false
|
||||||
|
|
||||||
|
output:
|
||||||
|
sort-results: true
|
||||||
|
|
||||||
|
# Uncomment and add a path if needed to exclude
|
||||||
|
# skip-dirs:
|
||||||
|
# - some/path
|
||||||
|
# skip-files:
|
||||||
|
# - ".*\\.my\\.go$"
|
||||||
|
# - lib/bad.go
|
||||||
|
|
||||||
|
# Find the whole list here https://golangci-lint.run/usage/linters/
|
||||||
|
linters:
|
||||||
|
disable-all: true
|
||||||
|
enable:
|
||||||
|
- asciicheck # simple linter to check that your code does not contain non-ASCII identifiers
|
||||||
|
- bidichk
|
||||||
|
- bodyclose # checks whether HTTP response body is closed successfully
|
||||||
|
- containedctx
|
||||||
|
- decorder
|
||||||
|
- depguard
|
||||||
|
- dupl # tool for code clone detection
|
||||||
|
- durationcheck # check for two durations multiplied together
|
||||||
|
- errcheck # checking for unchecked errors in go programs
|
||||||
|
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
|
||||||
|
- execinquery
|
||||||
|
- exhaustive
|
||||||
|
- exportloopref # checks for pointers to enclosing loop variables
|
||||||
|
- goconst # finds repeated strings that could be replaced by a constant
|
||||||
|
- godot
|
||||||
|
- godox # tool for detection of FIXME, TODO and other comment keywords
|
||||||
|
- gofmt
|
||||||
|
- goimports # Goimports does everything that gofmt does. Additionally it checks unused imports
|
||||||
|
- gomoddirectives # manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
|
||||||
|
- gomodguard # check for blocked dependencies
|
||||||
|
- gosec # inspects source code for security problems
|
||||||
|
- gosimple # linter for Go source code that specializes in simplifying a code
|
||||||
|
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
|
||||||
|
- importas # enforces consistent import aliases
|
||||||
|
- ineffassign # detects when assignments to existing variables are not used
|
||||||
|
- makezero
|
||||||
|
- misspell # finds commonly misspelled English words in comments
|
||||||
|
- nakedret # finds naked returns in functions greater than a specified function length
|
||||||
|
- nilerr # finds the code that returns nil even if it checks that the error is not nil.
|
||||||
|
- nilnil
|
||||||
|
- noctx # noctx finds sending http request without context.Context
|
||||||
|
- nolintlint # reports ill-formed or insufficient nolint directives
|
||||||
|
- nonamedreturns
|
||||||
|
- prealloc # finds slice declarations that could potentially be preallocated
|
||||||
|
- revive
|
||||||
|
# Disable because of generic - sqlclosecheck
|
||||||
|
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
|
||||||
|
- stylecheck # a replacement for golint
|
||||||
|
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
|
||||||
|
- unconvert # Remove unnecessary type conversions
|
||||||
|
- unparam # reports unused function parameters
|
||||||
|
- unused # checks Go code for unused constants, variables, functions and types
|
||||||
|
# Disable because of generic - wastedassign # wastedassign finds wasted assignment statements.
|
||||||
|
|
||||||
|
# all available settings of specific linters
|
||||||
|
linters-settings:
|
||||||
|
errcheck:
|
||||||
|
# report about not checking of errors in type assertions: `a := b.(MyStruct)`;
|
||||||
|
# default is false: such cases aren't reported by default.
|
||||||
|
check-type-assertions: true
|
||||||
|
|
||||||
|
errorlint:
|
||||||
|
# Check whether fmt.Errorf uses the %w verb for formatting errors. See the readme for caveats
|
||||||
|
errorf: true
|
||||||
|
# Check for plain type assertions and type switches
|
||||||
|
asserts: true
|
||||||
|
# Check for plain error comparisons
|
||||||
|
comparison: true
|
||||||
|
|
||||||
|
goconst:
|
||||||
|
# minimal length of string constant, 3 by default
|
||||||
|
min-len: 3
|
||||||
|
# minimal occurrences count to trigger, 3 by default
|
||||||
|
min-occurrences: 5
|
||||||
|
|
||||||
|
dupl:
|
||||||
|
# tokens count to trigger issue, 150 by default
|
||||||
|
threshold: 150
|
||||||
|
|
||||||
|
gomoddirectives:
|
||||||
|
# Allow local `replace` directives. Default is false.
|
||||||
|
replace-local: false
|
||||||
|
|
||||||
|
goimports:
|
||||||
|
local-prefixes: github.com/elastic
|
||||||
|
|
||||||
|
gomodguard:
|
||||||
|
blocked:
|
||||||
|
# List of blocked modules.
|
||||||
|
modules:
|
||||||
|
# Blocked module.
|
||||||
|
- github.com/pkg/errors:
|
||||||
|
# Recommended modules that should be used instead. (Optional)
|
||||||
|
recommendations:
|
||||||
|
- errors
|
||||||
|
- fmt
|
||||||
|
reason: "This package is deprecated, use `fmt.Errorf` with `%w` instead"
|
||||||
|
depguard:
|
||||||
|
list-type:: denylist
|
||||||
|
# Check the list against standard lib.
|
||||||
|
include-go-root: true
|
||||||
|
packages-with-error-message:
|
||||||
|
- io/ioutil: "The package is deprecated, use `io` or `so` instead."
|
||||||
|
|
||||||
|
gosimple:
|
||||||
|
# Select the Go version to target. The default is '1.13'.
|
||||||
|
go: "1.18.5"
|
||||||
|
|
||||||
|
misspell:
|
||||||
|
# Correct spellings using locale preferences for US or UK.
|
||||||
|
# Default is to use a neutral variety of English.
|
||||||
|
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
|
||||||
|
# locale: US
|
||||||
|
# ignore-words:
|
||||||
|
# - IdP
|
||||||
|
|
||||||
|
nakedret:
|
||||||
|
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
|
||||||
|
max-func-lines: 0
|
||||||
|
|
||||||
|
prealloc:
|
||||||
|
# Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them.
|
||||||
|
# True by default.
|
||||||
|
simple: true
|
||||||
|
range-loops: true # Report preallocation suggestions on range loops, true by default
|
||||||
|
for-loops: false # Report preallocation suggestions on for loops, false by default
|
||||||
|
|
||||||
|
nolintlint:
|
||||||
|
# Enable to ensure that nolint directives are all used. Default is true.
|
||||||
|
allow-unused: false
|
||||||
|
# Disable to ensure that nolint directives don't have a leading space. Default is true.
|
||||||
|
allow-leading-space: false
|
||||||
|
# Exclude following linters from requiring an explanation. Default is [].
|
||||||
|
allow-no-explanation: []
|
||||||
|
# Enable to require an explanation of nonzero length after each nolint directive. Default is false.
|
||||||
|
require-explanation: true
|
||||||
|
# Enable to require nolint directives to mention the specific linter being suppressed. Default is false.
|
||||||
|
require-specific: true
|
||||||
|
|
||||||
|
staticcheck:
|
||||||
|
# Select the Go version to target. The default is '1.13'.
|
||||||
|
go: "1.18.5"
|
||||||
|
# https://staticcheck.io/docs/options#checks
|
||||||
|
checks: ["all"]
|
||||||
|
|
||||||
|
stylecheck:
|
||||||
|
# Select the Go version to target. The default is '1.13'.
|
||||||
|
go: "1.18.5"
|
||||||
|
checks: ["all"]
|
||||||
|
|
||||||
|
unparam:
|
||||||
|
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
|
||||||
|
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
|
||||||
|
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
|
||||||
|
# with golangci-lint call it on a directory with the changed file.
|
||||||
|
check-exported: false
|
||||||
|
|
||||||
|
unused:
|
||||||
|
# Select the Go version to target. The default is '1.13'.
|
||||||
|
go: "1.18.5"
|
Loading…
Reference in New Issue
Block a user