From 5f4f3e98aa346a6e653198ef5515575b5bcd2256 Mon Sep 17 00:00:00 2001 From: Maria Ines Parnisari Date: Sat, 17 Feb 2024 16:31:53 -0300 Subject: [PATCH 1/4] add makefile, add linter rules, update github actions --- .github/workflows/go.yml | 26 +++++++++++--------------- .golangci.yaml | 35 +++++++++++++++++++++++++++++++++++ Makefile | 24 ++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 15 deletions(-) create mode 100644 .golangci.yaml create mode 100644 Makefile diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index afaaf37..c0ec50a 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -12,40 +12,36 @@ jobs: steps: - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v5 with: stable: 'false' go-version: '1.21' - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v4 with: fetch-depth: 1 - name: Cache Go modules - uses: actions/cache@v1 + uses: actions/cache@v4 with: - path: ~/go/pkg/mod + path: | + ~/.cache/go-build + ~/go/pkg/mod key: ${{ runner.os }}-build-${{ hashFiles('**/go.sum') }} restore-keys: | - ${{ runner.OS }}-build-${{ env.cache-name }}- ${{ runner.OS }}-build- - ${{ runner.OS }}- - name: Lint - uses: golangci/golangci-lint-action@v2 + uses: golangci/golangci-lint-action@v4 with: - version: v1.54.2 - args: --timeout 10m - - - name: Vet - if: matrix.os == 'ubuntu-latest' - run: go vet -v ./... + version: latest + args: -v -c .golangci.yaml - name: Build env: CGO_ENABLED: 0 - run: go build -ldflags "-s -w" ./... + run: make build - name: Test - run: go test -v -race ./... + run: make test diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..82f6391 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,35 @@ +run: + timeout: 10m + allow-parallel-runners: true + +linters: + enable: + - errname + - gofmt + - goimports + - stylecheck + - importas + - errcheck + - gosimple + - govet + - ineffassign + - mirror + - staticcheck + - tagalign + - testifylint + - typecheck + - unused + - unconvert + - wastedassign + - whitespace + - gocritic + - exhaustive + - noctx + - promlinter + +linters-settings: + govet: + enable-all: true + disable: + - shadow + - fieldalignment diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c73b582 --- /dev/null +++ b/Makefile @@ -0,0 +1,24 @@ +.DEFAULT_GOAL := help + +GO_BIN ?= $(shell go env GOPATH)/bin + +.PHONY: help +help: + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +$(GO_BIN)/golangci-lint: + @echo "==> Installing golangci-lint within "${GO_BIN}"" + @go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@latest + +.PHONY: lint +lint: $(GO_BIN)/golangci-lint ## Lint Go source files + @echo "==> Linting Go source files" + @golangci-lint run -v --fix -c .golangci.yaml ./... + +.PHONY: build +build: ## Build + go build -ldflags "-s -w" ./... + +.PHONY: test +test: ## Run unit tests + go test -v -race -count=1 ./... \ No newline at end of file From 03977482d7795cd62a406be9b021839b107afdd0 Mon Sep 17 00:00:00 2001 From: Maria Ines Parnisari Date: Sat, 17 Feb 2024 17:48:15 -0300 Subject: [PATCH 2/4] comment gofmt, remove stable --- .github/workflows/go.yml | 1 - .golangci.yaml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index c0ec50a..8b1a965 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -14,7 +14,6 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - stable: 'false' go-version: '1.21' - name: Checkout diff --git a/.golangci.yaml b/.golangci.yaml index 82f6391..32e6d30 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -5,7 +5,7 @@ run: linters: enable: - errname - - gofmt +# - gofmt - goimports - stylecheck - importas From b3019bed7b8cf3cd986f1c409dfa500e8f1284a2 Mon Sep 17 00:00:00 2001 From: Maria Ines Parnisari Date: Sat, 17 Feb 2024 17:59:30 -0300 Subject: [PATCH 3/4] also comment out goimports linter... --- .golangci.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 32e6d30..0c59097 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -5,8 +5,6 @@ run: linters: enable: - errname -# - gofmt - - goimports - stylecheck - importas - errcheck @@ -26,6 +24,9 @@ linters: - exhaustive - noctx - promlinter + # TODO these fail on windows + # - gofmt + # - goimports linters-settings: govet: From 945baf0f55e35a622374af000f3626804269eea8 Mon Sep 17 00:00:00 2001 From: Maria Ines Parnisari Date: Sun, 18 Feb 2024 21:23:12 -0300 Subject: [PATCH 4/4] remove makefile --- .github/workflows/go.yml | 4 ++-- Makefile | 24 ------------------------ 2 files changed, 2 insertions(+), 26 deletions(-) delete mode 100644 Makefile diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 8b1a965..c594fda 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -40,7 +40,7 @@ jobs: - name: Build env: CGO_ENABLED: 0 - run: make build + run: go build -ldflags "-s -w" ./... - name: Test - run: make test + run: go test -v -count=1 -race ./... diff --git a/Makefile b/Makefile deleted file mode 100644 index c73b582..0000000 --- a/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -.DEFAULT_GOAL := help - -GO_BIN ?= $(shell go env GOPATH)/bin - -.PHONY: help -help: - @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' - -$(GO_BIN)/golangci-lint: - @echo "==> Installing golangci-lint within "${GO_BIN}"" - @go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@latest - -.PHONY: lint -lint: $(GO_BIN)/golangci-lint ## Lint Go source files - @echo "==> Linting Go source files" - @golangci-lint run -v --fix -c .golangci.yaml ./... - -.PHONY: build -build: ## Build - go build -ldflags "-s -w" ./... - -.PHONY: test -test: ## Run unit tests - go test -v -race -count=1 ./... \ No newline at end of file