Add Makefile

This commit is contained in:
Peter Edge 2018-02-17 21:58:32 +01:00
parent 7d304729b4
commit 28b31068cd
3 changed files with 58 additions and 12 deletions

View File

@ -10,4 +10,5 @@ matrix:
- go: tip - go: tip
script: script:
- ./ci.sh # TODO: change to "make" when golint, errcheck, staticcheck pass
- make checkgofmt vet unused test

56
Makefile Normal file
View File

@ -0,0 +1,56 @@
SRCS := $(shell find . -name '*.go')
PKGS := $(shell go list ./...)
.PHONY: all
all: lint test
.PHONY: install
install:
go install $(PKGS)
.PHONY: golint
golint:
go get github.com/golang/lint/golint
for file in $(SRCS); do \
golint $${file}; \
if [ -n "$$(golint $${file})" ]; then \
exit 1; \
fi; \
done
.PHONY: checkgofmt
checkgofmt:
gofmt -s -l $(SRCS)
if [ -n "$$(gofmt -s -l $(SRCS))" ]; then \
exit 1; \
fi
.PHONY: vet
vet:
go vet $(PKGS)
.PHONY:
errcheck:
go get github.com/kisielk/errcheck
errcheck $(PKGS)
.PHONY: staticcheck
staticcheck:
@go get honnef.co/go/tools/cmd/staticcheck
staticcheck $(PKGS)
.PHONY: unused
unused:
@go get honnef.co/go/tools/cmd/unused
unused $(PKGS)
.PHONY: lint
lint: golint checkgofmt vet errcheck staticcheck unused
.PHONY: test
test:
go test -race $(PKGS)
.PHONY: clean
clean:
go clean -i $(PKGS)

11
ci.sh
View File

@ -1,11 +0,0 @@
#!/usr/bin/env bash
set -e
fmtdiff="$(gofmt -s -l ./)"
if [[ -n "$fmtdiff" ]]; then
gofmt -s -l ./ >&2
echo "Run gofmt on the above files!" >&2
exit 1
fi
go test -v -race ./...