ROOT := $(shell pwd)
OUTPUT := $(ROOT)/output
OUTPUT_BIN := $(OUTPUT)/bin
GO_MODULE := github.com/tidbcloud/escalation-base/support-autoshift

.PHONY: build
build: build-autoshift-server

.PHONY: build-autoshift-server
build-autoshift-server: OUTPUT_DIR ?= ./bin
build-autoshift-server: BUILD_NAME ?= autoshift-server
build-autoshift-server: BUILD_DIR ?= cmd/$(BUILD_NAME)
build-autoshift-server:
	CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(OUTPUT_DIR)/$(BUILD_NAME) -ldflags "-s -w" github.com/tidbcloud/escalation-base/support-autoshift/$(BUILD_DIR)

.PHONY: test
test: test-migrate
	go test -v -race -cover ./...
test-migrate:
	ENABLE_MIGRATE=1 go test -v -race -cover -count=1 ./migrate -run TestMigrate


.PHONY: lint
lint: LINTER ?= $(OUTPUT_BIN)/golangci-lint
lint: install-lint
	go mod tidy

	$(LINTER) run ./...

.PHONY: install
install: install-lint

install-lint:
	GOBIN=$(OUTPUT_BIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.52.2