Add basic build when merged to master

Add basic CI compliance and linting

Signed-off-by: jolheiser <john.olheiser@gmail.com>

Co-authored-by: jolheiser <john.olheiser@gmail.com>
Reviewed-on: https://gitea.com/jolheiser/gitea-vet/pulls/1
This commit is contained in:
John Olheiser 2020-04-04 21:12:39 +00:00
parent 6c7b81d401
commit 0185062ee4
6 changed files with 93 additions and 14 deletions

45
.drone.yml Normal file
View File

@ -0,0 +1,45 @@
---
kind: pipeline
name: compliance
platform:
os: linux
arch: arm64
trigger:
event:
- pull_request
steps:
- name: check
pull: always
image: golang:1.14
environment:
GOPROXY: https://goproxy.cn
commands:
- make build
- make lint
- make vet
---
kind: pipeline
name: build-master
platform:
os: linux
arch: amd64
trigger:
branch:
- master
event:
- push
steps:
- name: build
pull: always
image: techknowlogick/xgo:latest
environment:
GOPROXY: https://goproxy.cn
commands:
- make build

23
.golangci.yml Normal file
View File

@ -0,0 +1,23 @@
linters:
enable:
- deadcode
- dogsled
- dupl
- errcheck
- gocognit
- goconst
- gocritic
- gocyclo
- gofmt
- golint
- gosimple
- govet
- maligned
- misspell
- prealloc
- staticcheck
- structcheck
- typecheck
- unparam
- unused
- varcheck

View File

@ -1,7 +1,22 @@
GO ?= go
.PHONY: build
build:
go build
$(GO) build
.PHONY: fmt
fmt:
go fmt ./...
$(GO) fmt ./...
.PHONY: vet
vet: build
$(GO) vet ./...
$(GO) vet -vettool=gitea-vet ./...
.PHONY: lint
lint:
@hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
export BINARY="golangci-lint"; \
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(shell $(GO) env GOPATH)/bin v1.24.0; \
fi
golangci-lint run --timeout 5m

View File

@ -1,4 +1,7 @@
# gitea-vet
[![Build Status](https://drone.gitea.com/api/badges/jolheiser/gitea-vet/status.svg)](https://drone.gitea.com/jolheiser/gitea-vet)
`go vet` tool for Gitea
| Analyzer | Description |

View File

@ -22,11 +22,12 @@ func runImports(pass *analysis.Pass) (interface{}, error) {
for _, im := range file.Imports {
var lvl int
val := im.Path.Value
if importHasPrefix(val, "code.gitea.io") {
switch {
case importHasPrefix(val, "code.gitea.io"):
lvl = 2
} else if strings.Contains(val, ".") {
case strings.Contains(val, "."):
lvl = 3
} else {
default:
lvl = 1
}
@ -43,12 +44,3 @@ func runImports(pass *analysis.Pass) (interface{}, error) {
func importHasPrefix(s, p string) bool {
return strings.HasPrefix(s, "\""+p)
}
func sliceHasPrefix(s string, prefixes ...string) bool {
for _, p := range prefixes {
if importHasPrefix(s, p) {
return true
}
}
return false
}

View File

@ -6,6 +6,7 @@ package main
import (
"gitea.com/jolheiser/gitea-vet/checks"
"golang.org/x/tools/go/analysis/unitchecker"
)