Add Makefile (#5)

Replaces ci.sh, provides add'l static analysis (which isn't yet enabled in CI since the code doesn't yet pass them all)
This commit is contained in:
Peter Edge 2018-02-18 00:15:13 +01:00 committed by Joshua Humphries
parent cdea962127
commit 9f7485fd04
3 changed files with 66 additions and 12 deletions

View File

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

64
Makefile Normal file
View File

@ -0,0 +1,64 @@
SRCS := $(shell find . -name '*.go')
PKGS := $(shell go list ./...)
.PHONY: all
all: deps lint test
.PHONY: deps
deps:
go get -d -v -t $(PKGS)
.PHONY: updatedeps
updatedeps:
go get -d -v -t -u -f $(PKGS)
.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 ./...