feat: migrate from drone to woodpecker
ci/woodpecker/push/test Pipeline failed Details

This commit is contained in:
Dawid Wysokiński 2023-08-20 07:17:36 +02:00
parent 38e4720367
commit 78893a70a2
Signed by: Kichiyaki
GPG Key ID: B5445E357FB8B892
4 changed files with 169 additions and 43 deletions

View File

@ -1,36 +0,0 @@
---
kind: pipeline
type: docker
name: test
steps:
- name: test
image: golang:1.20
commands:
- go test -race -coverprofile=coverage.txt -covermode=atomic ./...
trigger:
event:
- push
- pull_request
branch:
- master
---
kind: pipeline
type: docker
name: check-go-mod
steps:
- name: check go.mod
image: golang:1.20
commands:
- go mod tidy
- git diff --exit-code go.mod
trigger:
event:
- push
- pull_request
branch:
- master

124
.golangci.yml Normal file
View File

@ -0,0 +1,124 @@
run:
tests: true
timeout: 5m
linters:
disable-all: true
enable:
- asasalint
- asciicheck
- bodyclose
- bidichk
- exportloopref
- depguard
- errcheck
- gocritic
- gosec
- gofmt
- goimports
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- prealloc
- staticcheck
- typecheck
- unconvert
- unused
- lll
- nestif
- thelper
- nonamedreturns
- gocyclo
- gomnd
- tenv
- testpackage
- noctx
- tparallel
- usestdlibvars
- unconvert
- makezero
- grouper
- errname
- exhaustive
- tagliatelle
- contextcheck
- gocheckcompilerdirectives
- errname
- forcetypeassert
- durationcheck
- predeclared
- promlinter
- wastedassign
linters-settings:
lll:
line-length: 150
gocyclo:
min-complexity: 10
depguard:
rules:
main:
files:
- "$all"
deny:
- pkg: reflect
desc: Please don't use reflect package
- pkg: github.com/pkg/errors
desc: Should be replaced by standard lib errors package
govet:
enable:
- asmdecl
- assign
- atomic
- atomicalign
- bools
- buildtag
- cgocall
- composites
- copylocks
- deepequalerrors
- errorsas
- findcall
- framepointer
- httpresponse
- ifaceassert
- loopclosure
- lostcancel
- nilfunc
- nilness
- printf
- reflectvaluecompare
- shadow
- shift
- sigchanyzer
- sortslice
- stdmethods
- stringintconv
- structtag
- testinggoroutine
- tests
- unmarshal
- unreachable
- unsafeptr
- unusedresult
- unusedwrite
gomnd:
ignored-functions:
- strconv.FormatInt
- strconv.ParseInt
issues:
exclude-rules:
# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- dupl
- gocyclo
- linters:
- lll
source: "^//go:generate "
- linters:
- lll
source: "^// @Param"

31
.woodpecker/test.yml Normal file
View File

@ -0,0 +1,31 @@
when:
- event: [pull_request]
- event: push
branch:
- ${CI_REPO_DEFAULT_BRANCH}
variables:
- &go_image 'go:1.21'
steps:
test:
image: *go_image
group: test
pull: true
commands:
- go test -race -coverprofile=coverage.txt -covermode=atomic ./...
lint:
image: golangci/golangci-lint:v1.54
pull: true
group: test
commands:
- golangci-lint run
check-go-mod:
image: *go_image
group: test
pull: true
commands:
- go mod tidy
- git diff --exit-code go.mod

View File

@ -7,6 +7,7 @@ import (
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
// Logger returns a go-chi middleware that logs requests using go.uber.org/zap.
@ -49,13 +50,19 @@ func Logger(logger *zap.Logger, opts ...Option) func(next http.Handler) http.Han
fields = append(fields, f(r)...)
}
if statusCode >= http.StatusInternalServerError {
logger.Error(path, fields...)
} else if statusCode >= http.StatusBadRequest {
logger.Warn(path, fields...)
} else {
logger.Info(path, fields...)
}
logger.Log(statusCodeToLogLvl(statusCode), path, fields...)
})
}
}
func statusCodeToLogLvl(statusCode int) zapcore.Level {
if statusCode >= http.StatusInternalServerError {
return zap.ErrorLevel
}
if statusCode >= http.StatusBadRequest {
return zap.WarnLevel
}
return zap.InfoLevel
}