export SHELL := /bin/bash
export PATH := $(PWD)/bin:$(PWD):$(PATH)
export GOBIN := $(PWD)/bin

# Default to not using any 3P proxies
export GOPROXY := direct
export GOPRIVATE := *

default: build lint check-gen test

ci:
	./ci.sh
.PHONY: ci

# Verify dependencies and test code building
build:
	go mod verify
	go build -mod=readonly ./...
.PHONY: build

# Run lints
lint: install-tools
	go vet ./...
	golint -set_exit_status ./...
	errcheck -asserts -blank ./...
	staticcheck ./...
.PHONY: lint

# Install lint tools into GOBIN
install-tools:
	@mkdir -p bin
	go install github.com/kisielk/errcheck
	go install honnef.co/go/tools/cmd/staticcheck
	go install golang.org/x/lint/golint
	go install github.com/maxbrunsfeld/counterfeiter/v6
.PHONY: install-tools

# Run go test target for development
test:
	go test -race ./...
.PHONY: test

# Run integration tests
integration_test:
	go test -count=1 -tags integration -run "Integration" -race ./...
.PHONY: integration_test

# Run code generation
gen:
	go generate ./...
.PHONY: gen

# Check that code-generation does not produce any differences
check-gen: gen
	@((git diff --quiet HEAD -- *.gen.go **/*.gen.go) || \
	(echo "Generated code difference detected! Please run 'make gen' and commit the changes"; false))
.PHONY: check-gen

bench:
	go test -bench . -run=$$^ -benchmem ./bench
.PHONY: bench

# Run this one time to add lint dependencies to go.mod
add-lint-dependencies:
	go get golang.org/x/lint/golint@959b441ac422379a43da2230f62be024250818b0
	go get github.com/kisielk/errcheck@v1.2.0
	go get honnef.co/go/tools/cmd/staticcheck@2019.2.3
.PHONY: add-lint-dependencies
