From 71335489ae68bbbbc480e2941fa4bb9c009c9476 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Mon, 23 Oct 2023 18:05:03 +0300 Subject: [PATCH] [#183] forgejo: Make linter great again Signed-off-by: Dmitrii Stepanov --- .forgejo/workflows/tests.yml | 15 +++++++++++---- .gitignore | 4 ++++ Makefile | 21 ++++++++++++++++++++- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/.forgejo/workflows/tests.yml b/.forgejo/workflows/tests.yml index 664767b..946e685 100644 --- a/.forgejo/workflows/tests.yml +++ b/.forgejo/workflows/tests.yml @@ -8,17 +8,24 @@ jobs: steps: - uses: actions/checkout@v3 - - name: golangci-lint - uses: https://github.com/golangci/golangci-lint-action@v2 + - name: Set up Go + uses: actions/setup-go@v3 with: - version: latest + go-version: '1.21' + cache: true + + - name: Install linters + run: make lint-install + + - name: Run linters + run: make lint tests: name: Tests runs-on: ubuntu-latest strategy: matrix: - go_versions: [ '1.19', '1.20' ] + go_versions: [ '1.20', '1.21' ] fail-fast: false steps: - uses: actions/checkout@v3 diff --git a/.gitignore b/.gitignore index 701012c..5659307 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,7 @@ antlr-*.jar # tempfiles .cache + +# binary +bin/ +release/ diff --git a/Makefile b/Makefile index e454dc2..17bed62 100755 --- a/Makefile +++ b/Makefile @@ -1,6 +1,11 @@ #!/usr/bin/make -f ANTLR_VERSION="4.13.0" +TMP_DIR := .cache +LINT_VERSION ?= 1.55.0 +TRUECLOUDLAB_LINT_VERSION ?= 0.0.2 +OUTPUT_LINT_DIR ?= $(shell pwd)/bin +LINT_DIR = $(OUTPUT_LINT_DIR)/golangci-lint-$(LINT_VERSION)-v$(TRUECLOUDLAB_LINT_VERSION) # Run tests test: @@ -15,9 +20,23 @@ dep: @CGO_ENABLED=0 \ go mod tidy -v && echo OK +# 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) + # Run linters lint: - @golangci-lint --timeout=5m run + @if [ ! -d "$(LINT_DIR)" ]; then \ + echo "Run make lint-install"; \ + exit 1; \ + fi + $(LINT_DIR)/golangci-lint run # Run tests with race detection and produce coverage output cover: