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 test

ci:
	./ci.sh
.PHONY: ci

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

# 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
.PHONY: install-tools

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

# Run go tests with the race detector
test:
	go test -race ./...
.PHONY: test

# 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
