1SHELL := /bin/bash -eu -o pipefail
2
3GO_TEST_FLAGS  := -v
4
5PACKAGE_DIRS := $(shell go list ./... 2> /dev/null | grep -v /vendor/)
6SRC_FILES    := $(shell find . -name '*.go' -not -path './vendor/*')
7
8
9#  Tasks
10#-----------------------------------------------
11.PHONY: lint
12lint:
13	@gofmt -e -d -s $(SRC_FILES) | awk '{ e = 1; print $0 } END { if (e) exit(1) }'
14	@echo $(SRC_FILES) | xargs -n1 golint -set_exit_status
15	@go vet $(PACKAGE_DIRS)
16
17.PHONY: test
18test: lint
19	@go test $(GO_TEST_FLAGS) $(PACKAGE_DIRS)
20
21.PHONY: ci-test
22ci-test: lint
23	@echo > coverage.txt
24	@for d in $(PACKAGE_DIRS); do \
25		go test -coverprofile=profile.out -covermode=atomic -race -v $$d; \
26		if [ -f profile.out ]; then \
27			cat profile.out >> coverage.txt; \
28			rm profile.out; \
29		fi; \
30	done
31