GO ?= $(shell go env GOROOT)/bin/go

GENERATOR_DIRS=ping runner

BUF_PACKAGE=github.com/bufbuild/buf/cmd/buf@v1.8.0 # renovate: datasource=go
GRPCURL_PACKAGE=github.com/fullstorydev/grpcurl/cmd/grpcurl@v1.8.7 # renovate: datasource=go
PROTOC_GEN_GO_PACKAGE=google.golang.org/protobuf/cmd/protoc-gen-go@v1.28 # renovate: datasource=go
PROTOC_GEN_GO_GRPC_PACKAGE=google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2 # renovate: datasource=go
PROTOC_GEN_CONNECT_GO_PACKAGE=connectrpc.com/connect/cmd/protoc-gen-connect-go@v1.15.0 # renovate: datasource=go

.PHONY: install
install:
	$(GO) install $(BUF_PACKAGE)
	$(GO) install $(GRPCURL_PACKAGE)
	$(GO) install $(PROTOC_GEN_GO_PACKAGE)
	$(GO) install $(PROTOC_GEN_GO_GRPC_PACKAGE)
	$(GO) install $(PROTOC_GEN_CONNECT_GO_PACKAGE)

.PHONY: lint
lint:
	buf lint
	buf format --diff --exit-code

.PHONY: format
format:
	buf format --diff -w

.PHONY: generator-check
generator-check:
	@rm -fr $(GENERATOR_DIRS)
	@buf generate
	@git diff --exit-code --color=always --cached $(GENERATOR_DIRS) \
	|| (code=$$?; echo "Please run 'make generator' and commit the result"; exit $${code})

.PHONY: generator
generator:
	buf generate
