Skip to content

Commit ae381b1

Browse files
author
Ravi Atluri
committed
Refactor GitHub Actions and Makefile for improved testing and linting workflow; add coverage reporting and update golangci-lint versioning
1 parent 07679d7 commit ae381b1

File tree

3 files changed

+114
-79
lines changed

3 files changed

+114
-79
lines changed

.github/workflows/test.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,14 @@ jobs:
2626
with:
2727
path: .bin
2828
key: ${{ runner.os }}-go1.25.x-${{ hashFiles('Makefile') }}
29+
- name: Check
30+
run: make check
2931
- name: Test
30-
run: make ci
32+
run: make test
33+
- name: Coverage
34+
run: make test-cov
35+
- name: Generate coverage report in XML format
36+
run: make test-xml
3137
- name: Upload coverage to Codecov
3238
uses: codecov/codecov-action@v2
3339
with:

.golangci.yml

Lines changed: 103 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,123 @@
1+
version: "2"
2+
13
linters:
2-
disable-all: true
4+
default: none
5+
# This list of linters is not a recommendation (same thing for all this configuration file).
6+
# We intentionally use a limited set of linters.
37
enable:
4-
- errcheck
5-
- staticcheck
6-
- unused
7-
- gosimple
8-
- ineffassign
9-
- stylecheck
10-
- typecheck
11-
- unconvert
128
- bodyclose
9+
- copyloopvar
10+
- dogsled
1311
- dupl
12+
- errcheck
13+
- errorlint
14+
- funlen
15+
- gocheckcompilerdirectives
16+
- gochecknoinits
1417
- goconst
18+
- gocritic
1519
- gocyclo
16-
- gofmt
20+
- godox
21+
- mnd
22+
- goprintffuncname
23+
- gosec
24+
- govet
25+
- intrange
26+
- ineffassign
1727
- lll
1828
- misspell
1929
- nakedret
20-
- exportloopref
21-
- funlen
22-
- nestif
23-
- nlreturn
24-
- prealloc
25-
- rowserrcheck
30+
- noctx
31+
- nolintlint
32+
- revive
33+
- staticcheck
34+
- testifylint
2635
- unconvert
2736
- unparam
37+
- unused
2838
- whitespace
29-
- wsl
39+
40+
settings:
41+
govet:
42+
enable-all: true
43+
settings:
44+
shadow:
45+
strict: true
46+
errcheck:
47+
check-type-assertions: true
48+
misspell:
49+
locale: UK
50+
ignore-words:
51+
- initialized
52+
funlen:
53+
lines: 80
54+
statements: 40
55+
gci:
56+
sections:
57+
- standard
58+
- default
59+
- blank
60+
- dot
61+
- alias
62+
custom-order: true
63+
revive:
64+
rules:
65+
- name: package-comments
66+
disabled: true
67+
exclusions:
68+
generated: lax
69+
rules:
70+
- path: _test\.go
71+
linters:
72+
- dupl
73+
- gosec
74+
- wsl
75+
- lll
76+
- funlen
77+
- nlreturn
78+
- unused
79+
- path: _test\.go
80+
text: "^Error return value is not checked$"
81+
linters:
82+
- errcheck
83+
- text: "^SA1019:.* is deprecated:"
84+
linters:
85+
- staticcheck
86+
- text: "declaration of \"(err|ctx)\" shadows declaration at"
87+
linters:
88+
- govet
89+
- text: "return value of `tx.Rollback` is not checked"
90+
linters:
91+
- errcheck
92+
93+
formatters:
94+
enable:
95+
- gofmt
96+
- gci
97+
98+
settings:
99+
gofmt:
100+
simplify: true
101+
rewrite-rules:
102+
- pattern: 'interface{}'
103+
replacement: 'any'
104+
- pattern: 'a[b:len(a)]'
105+
replacement: 'a[b:]'
106+
gci:
107+
sections:
108+
- standard
109+
- default
110+
- blank
111+
- dot
112+
- alias
113+
custom-order: true
114+
30115
run:
31116
skip-dirs:
32117
- bin
33118
skip-files:
34119
- .*mock.*\.go$
35120
- version.go
36-
- .*\_test\.go$
121+
- .*_test\.go$
37122
- generate.go
38123
modules-download-mode: readonly
39-
linters-settings:
40-
govet:
41-
check-shadowing: true
42-
enable-all: true
43-
disable:
44-
- asmdecl
45-
- assign
46-
errcheck:
47-
check-type-assertions: true
48-
misspell:
49-
locale: UK
50-
ignore-words:
51-
- initialized
52-
funlen:
53-
lines: 80
54-
statements: 40
55-
56-
issues:
57-
exclude-use-default: false
58-
exclude:
59-
- declaration of "(err|ctx)" shadows declaration at
60-
exclude-rules:
61-
- text: "^SA1019: .* is deprecated:"
62-
linters:
63-
- staticcheck
64-
- path: _test\.go
65-
linters:
66-
- dupl
67-
- gosec
68-
- wsl
69-
- lll
70-
- funlen
71-
- nlreturn
72-
- unused
73-
- path: _test\.go
74-
text: ^Error return value is not checked$
75-
linters:
76-
- errcheck

Makefile

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
ALL_GO_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | sort)
2-
# extract go minor version from go version output
3-
GO_MINOR_VERSION := $(shell go version | cut -d' ' -f3 | cut -d'.' -f2)
42

53
EXCLUDE_DIRS := ./examples
64
EXCLUDE_GO_MOD_DIRS := $(shell find $(EXCLUDE_DIRS) -type f -name 'go.mod' -exec dirname {} \; | sort)
75

8-
# set build directory based on go minor version
9-
GO_BUILD_DIRS := $(foreach dir,$(ALL_GO_MOD_DIRS),$(shell GO_MOD_VERSION=$$(grep "go 1.[0-9]*" $(dir)/go.mod | cut -d' ' -f2 | cut -d'.' -f2) && [ -n "$$GO_MOD_VERSION" ] && [ $(GO_MINOR_VERSION) -ge $$GO_MOD_VERSION ] && echo $(dir)))
6+
GO_BUILD_DIRS := $(ALL_GO_MOD_DIRS)
107

118
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
129
BIN_DIR := $(PROJECT_DIR)/.bin
@@ -21,10 +18,7 @@ vet:
2118
@$(call run-go-mod-dir,go vet ./...,"go vet")
2219

2320
lint: golangci-lint
24-
@$(call run-go-mod-dir,$(GOLANGCI_LINT) run --timeout=10m -v,".bin/golangci-lint")
25-
26-
.PHONY: ci
27-
ci: test test-cov test-xml
21+
$(GOLANGCI_LINT) run --timeout=10m -v
2822

2923
imports: gci
3024
@$(call run-go-mod-dir,$(GCI) -w -local github.com/gojekfarm ./ | { grep -v -e 'skip file .*' || true; },".bin/gci")
@@ -40,9 +34,7 @@ generate: mockery protoc
4034
## test: Run all tests
4135
.PHONY: test test-run test-cov test-xml
4236

43-
test: check test-run
44-
45-
test-run:
37+
test:
4638
@$(call run-go-mod-dir,go test -race -covermode=atomic -coverprofile=coverage.out ./...,"go test")
4739

4840
test-cov: gocov
@@ -64,19 +56,9 @@ check: fmt vet imports lint
6456

6557
# ========= Helpers ===========
6658

67-
## Determine the golangci-lint version based on $(GO_MINOR_VERSION)
68-
###################
69-
GOLANGCI_LINT_V18 := v1.50.1
70-
GOLANGCI_LINT_DEFAULT := v1.53.3
71-
72-
get-golangci-lint-version = $(or $(value GOLANGCI_LINT_V$(1)), $(GOLANGCI_LINT_DEFAULT))
73-
GOLANGCI_LINT_VERSION := $(call get-golangci-lint-version,$(GO_MINOR_VERSION))
74-
75-
###################
76-
7759
GOLANGCI_LINT = $(BIN_DIR)/golangci-lint
7860
golangci-lint:
79-
$(call go-get-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION))
61+
$(call go-get-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest)
8062

8163
GCI = $(BIN_DIR)/gci
8264
gci:

0 commit comments

Comments
 (0)