novendor = $(shell go list ./... | grep -v vendor/ | grep -v integration_test)
integration = $(shell go list ./... | grep integration_test)
TOOL_DIR=$(CURDIR)/_tools/bin
RETOOL=$(TOOL_DIR)/retool
export PATH := $(TOOL_DIR):$(PATH)

all: release

# Runs all tasks that need to be done as part of a release. Think 'bb release"...
release: dep fmt lint test install

# Run all static checks
lint:
	go vet $(novendor)
	retool do golint $(novendor)

# Run auto-formatting
fmt:
	go fmt $(novendor)
	retool do goimports -w /dev/null api backend dynamo sns metrics middleware decorators promotion_string

# Run tests
.PHONY: test
test: dep
	go test -race -v $(novendor)

test-coverage: dep
	go get github.com/axw/gocov/gocov
	go get github.com/t-yuki/gocov-xml
	gocov test -race -v $(novendor) | gocov-xml > coverage.xml

integration: dep
	go test -race -v $(integration)

# Build the executable
install:
	go build -o bin/gateway

# Starts the go server - think 'bb server'...
server:
	go run main.go

dep:
	retool do dep ensure

migrate:
	mv -f bin/gateway .

prune:
	find . -mindepth 1 -maxdepth 1 -not -name bin -not -name config -not -name courier -not -name campaign -exec rm -rf {} \;

manta: test install prune migrate
