From c2b8944af6bb2626999b35a04d313c5133ad757c Mon Sep 17 00:00:00 2001 From: Ekaterina Lebedeva Date: Wed, 2 Oct 2024 16:07:10 +0300 Subject: [PATCH] [#171] Makefile: add target to install `golangci-lint` Signed-off-by: Ekaterina Lebedeva --- .forgejo/workflows/tests.yml | 9 +++++---- Makefile | 24 ++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/.forgejo/workflows/tests.yml b/.forgejo/workflows/tests.yml index e47f3f3..42fe353 100644 --- a/.forgejo/workflows/tests.yml +++ b/.forgejo/workflows/tests.yml @@ -14,10 +14,11 @@ jobs: go-version: '1.23' cache: true - - name: golangci-lint - uses: https://github.com/golangci/golangci-lint-action@v3 - with: - version: latest + - name: Install linters + run: make lint-install + + - name: Run linters + run: make lint tests: name: Tests diff --git a/Makefile b/Makefile index f1e76cb..b834155 100644 --- a/Makefile +++ b/Makefile @@ -4,9 +4,14 @@ REPO ?= $(shell go list -m) VERSION ?= $(shell git describe --tags --dirty --match "v*" --always --abbrev=8 2>/dev/null || cat VERSION 2>/dev/null || echo "develop") GO_VERSION ?= 1.22 -LINT_VERSION ?= 1.60.1 +LINT_VERSION ?= 1.60.3 +TRUECLOUDLAB_LINT_VERSION ?= 0.0.7 BINDIR = bin +OUTPUT_LINT_DIR ?= $(abspath $(BINDIR))/linters +LINT_DIR = $(OUTPUT_LINT_DIR)/golangci-lint-$(LINT_VERSION)-v$(TRUECLOUDLAB_LINT_VERSION) +TMP_DIR := .cache + # Binaries to build CMDS = $(addprefix frostfs-, $(notdir $(wildcard cmd/*))) BINS = $(addprefix $(BINDIR)/, $(CMDS)) @@ -64,7 +69,22 @@ format: # Run linters lint: - @golangci-lint --timeout=5m run + @if [ ! -d "$(LINT_DIR)" ]; then \ + make lint-install; \ + fi + $(LINT_DIR)/golangci-lint run --timeout=5m + +# Install linters +lint-install: + @rm -rf $(OUTPUT_LINT_DIR) + @mkdir -p $(OUTPUT_LINT_DIR) + @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 -trimpath github.com/golangci/golangci-lint/cmd/golangci-lint@v$(LINT_VERSION) # Run linters in Docker docker/lint: