2023-05-30 09:31:34 +00:00
|
|
|
#!/usr/bin/make -f
|
|
|
|
SHELL = bash
|
|
|
|
|
2024-01-31 12:06:10 +00:00
|
|
|
TRUECLOUDLAB_LINT_VERSION ?= 0.0.3
|
2023-11-02 09:22:15 +00:00
|
|
|
TMP_DIR := .cache
|
|
|
|
OUTPUT_LINT_DIR ?= $(shell pwd)/bin
|
2024-07-05 07:05:16 +00:00
|
|
|
LINT_VERSION ?= 1.59.1
|
2023-11-02 09:22:15 +00:00
|
|
|
LINT_DIR = $(OUTPUT_LINT_DIR)/golangci-lint-$(LINT_VERSION)-v$(TRUECLOUDLAB_LINT_VERSION)
|
|
|
|
|
|
|
|
# Run all code formatters
|
|
|
|
fmts: fmt imports
|
|
|
|
|
|
|
|
# Reformat code
|
|
|
|
fmt:
|
|
|
|
@echo "⇒ Processing gofmt check"
|
|
|
|
@gofumpt -s -w .
|
|
|
|
|
|
|
|
# Reformat imports
|
|
|
|
imports:
|
|
|
|
@echo "⇒ Processing goimports check"
|
|
|
|
@goimports -w .
|
|
|
|
|
2023-05-30 09:31:34 +00:00
|
|
|
# Run Unit Test with go test
|
2024-07-05 07:07:30 +00:00
|
|
|
test: GOFLAGS ?= "-count=1"
|
2023-05-30 09:31:34 +00:00
|
|
|
test:
|
2023-11-02 09:22:15 +00:00
|
|
|
@echo "⇒ Running go test"
|
2024-07-05 07:07:30 +00:00
|
|
|
@GOFLAGS="$(GOFLAGS)" go test ./...
|
2023-05-30 09:31:34 +00:00
|
|
|
|
2023-11-02 09:22:15 +00:00
|
|
|
# Activate pre-commit hooks
|
|
|
|
pre-commit:
|
|
|
|
pre-commit install -t pre-commit -t commit-msg
|
|
|
|
|
|
|
|
# Deactivate pre-commit hooks
|
|
|
|
unpre-commit:
|
|
|
|
pre-commit uninstall -t pre-commit -t commit-msg
|
|
|
|
|
|
|
|
pre-commit-run:
|
|
|
|
@pre-commit run -a --hook-stage manual
|
|
|
|
|
|
|
|
# Install linters
|
|
|
|
lint-install:
|
|
|
|
@mkdir -p $(TMP_DIR)
|
|
|
|
@rm -rf $(TMP_DIR)/linters
|
|
|
|
@git -c advice.detachedHead=false clone --branch v$(TRUECLOUDLAB_LINT_VERSION) https://git.frostfs.info/TrueCloudLab/linters.git $(TMP_DIR)/linters
|
|
|
|
@make -C $(TMP_DIR)/linters lib CGO_ENABLED=1 OUT_DIR=$(OUTPUT_LINT_DIR)
|
|
|
|
@rm -rf $(TMP_DIR)/linters
|
|
|
|
@rmdir $(TMP_DIR) 2>/dev/null || true
|
|
|
|
@CGO_ENABLED=1 GOBIN=$(LINT_DIR) go install github.com/golangci/golangci-lint/cmd/golangci-lint@v$(LINT_VERSION)
|
|
|
|
|
2023-05-30 09:31:34 +00:00
|
|
|
# Run linters
|
|
|
|
lint:
|
2023-11-02 09:22:15 +00:00
|
|
|
@if [ ! -d "$(LINT_DIR)" ]; then \
|
|
|
|
echo "Run make lint-install"; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
|
|
|
@$(LINT_DIR)/golangci-lint run
|
|
|
|
|
|
|
|
# Install staticcheck
|
|
|
|
staticcheck-install:
|
|
|
|
@go install honnef.co/go/tools/cmd/staticcheck@latest
|
2023-05-30 09:31:34 +00:00
|
|
|
|
|
|
|
# Run staticcheck
|
2023-11-02 09:22:15 +00:00
|
|
|
staticcheck-run:
|
|
|
|
@staticcheck ./...
|