PACKAGES=`find ./pkg -mindepth 1 -maxdepth 1 -type d`
BINARIES=`find ./cmd -mindepth 1 -maxdepth 1 -type d`
ENV=stg

clean:
	rm -rf bin

build: clean
	GOOS=linux go build -o ./bin/turnip-api -ldflags "-w -s" ./cmd/api/lambda/main.go
	rm -f ./bin/turnip-api.zip && zip -r ./bin/turnip-api.zip ./bin/turnip-api

proto:
	protoc --proto_path=$(GOPATH)/src:. --twirp_out=. --go_out=. ./pkg/rpc/turnip.proto

lint:
	goimports -l $(PACKAGES) $(BINARIES)
	gofmt -l $(PACKAGES) $(BINARIES)
	errcheck $(PACKAGES) $(BINARIES)
	golint $(PACKAGES) $(BINARIES)
	go vet $(PACKAGES) $(BINARIES)

test: lint
	for p in $(PACKAGES) $(BINARIES); do go test -race -covermode=atomic $${p}; done

testcov: lint
	go get github.com/axw/gocov/gocov
	go get github.com/t-yuki/gocov-xml
	gocov test $(PACKAGES) $(BINARIES) > test_coverage.json
	gocov-xml < test_coverage.json > test_coverage.xml
