Skip to content

Commit

Permalink
Merge pull request #248 from nspcc-dev/org-wide-linter
Browse files Browse the repository at this point in the history
Org-wide linter
  • Loading branch information
roman-khimov authored Sep 13, 2024
2 parents e5a94a4 + 02e0776 commit 23424c7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 90 deletions.
15 changes: 1 addition & 14 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,7 @@ on:
jobs:
lint:
name: Lint
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Go from go.mod
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
uses: nspcc-dev/.github/.github/workflows/go-linter.yml@master

cover:
name: Coverage
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ temp

coverage.txt
coverage.html

.golangci.yml
54 changes: 0 additions & 54 deletions .golangci.yml

This file was deleted.

28 changes: 7 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ VERSION ?= "$(shell git describe --tags --match "v*" --dirty --always --abbrev=8
BUILD_OS ?= linux
BUILD_ARCH ?= amd64
GO_VERSION ?= 1.22
LINT_VERSION ?= v1.59.0

HUB_IMAGE ?= nspccdev/neofs-rest-gw
HUB_TAG ?= "$(shell echo ${VERSION} | sed 's/^v//')"
Expand All @@ -26,12 +25,12 @@ BINDIR = bin
DIRS = "$(BINDIR)"
BINS = "$(BINDIR)/neofs-rest-gw"

.PHONY: help all dep clean format test cover lint docker/lint
.PHONY: help all clean format test cover lint docker/lint

# Make all binaries
all: generate-server $(BINS)

$(BINS): $(DIRS) dep
$(BINS): $(DIRS)
@echo "⇒ Build $@"
CGO_ENABLED=0 \
GOOS=$(BUILD_OS) \
Expand All @@ -44,15 +43,6 @@ $(DIRS):
@echo "⇒ Ensure dir: $@"
@mkdir -p $@

# Pull go dependencies
dep:
@printf "⇒ Download requirements: "
@CGO_ENABLED=0 \
go mod download && echo OK
@printf "⇒ Tidy requirements: "
@CGO_ENABLED=0 \
go mod tidy -v && echo OK

# Install generator
install-generator:
@go install github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen@v2.1.0
Expand Down Expand Up @@ -102,8 +92,12 @@ image-dirty:
-f Dockerfile.dirty \
-t $(HUB_IMAGE)-dirty:$(HUB_TAG) .

# Fetch linter configuration.
.golangci.yml:
wget -O $@ https://github.com/nspcc-dev/.github/raw/master/.golangci.yml

# Run linters
lint:
lint: .golangci.yml
@golangci-lint --timeout=5m run

# Make all binaries in clean docker environment
Expand All @@ -118,14 +112,6 @@ docker/all:
--env BUILD_ARCH=$(BUILD_ARCH) \
golang:$(GO_VERSION) make all

# Run linters in Docker
docker/lint:
docker run --rm -it \
-v `pwd`:/src \
-u `stat -c "%u:%g" .` \
--env HOME=/src \
golangci/golangci-lint:$(LINT_VERSION) bash -c 'cd /src/ && make lint'

# Print version
version:
@echo $(VERSION)
Expand Down
3 changes: 2 additions & 1 deletion metrics/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package metrics

import (
"context"
"errors"
"net/http"

"go.uber.org/zap"
Expand All @@ -26,7 +27,7 @@ func (ms *Service) Start() {
if ms.enabled {
ms.log.Info("service is running", zap.String("endpoint", ms.Addr))
err := ms.ListenAndServe()
if err != nil && err != http.ErrServerClosed {
if err != nil && !errors.Is(err, http.ErrServerClosed) {
ms.log.Warn("service couldn't start on configured port")
}
} else {
Expand Down

0 comments on commit 23424c7

Please sign in to comment.