Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,31 @@ on:
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.18.x, 1.19.x, 1.20.x, 1.21.x, 1.22.x]
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
go-version: 1.25.x
- name: Checkout code
uses: actions/checkout@v2
- name: Go mod cache
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go${{ matrix.go-version }}
key: ${{ runner.os }}-go1.25.x
- name: Tools bin cache
uses: actions/cache@v4
with:
path: .bin
key: ${{ runner.os }}-go${{ matrix.go-version }}-${{ hashFiles('Makefile') }}
key: ${{ runner.os }}-go1.25.x-${{ hashFiles('Makefile') }}
- name: Check
run: make check
- name: Test
run: make ci
run: make test
- name: Coverage
run: make test-cov
- name: Generate coverage report in XML format
run: make test-xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ tools/vendor
go.work
go.work.sum

.envrc
.envrc
.claude/
159 changes: 103 additions & 56 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,76 +1,123 @@
version: "2"

linters:
disable-all: true
default: none
# This list of linters is not a recommendation (same thing for all this configuration file).
# We intentionally use a limited set of linters.
enable:
- errcheck
- staticcheck
- unused
- gosimple
- ineffassign
- stylecheck
- typecheck
- unconvert
- bodyclose
- copyloopvar
- dogsled
- dupl
- errcheck
- errorlint
- funlen
- gocheckcompilerdirectives
- gochecknoinits
- goconst
- gocritic
- gocyclo
- gofmt
- godox
- mnd
- goprintffuncname
- gosec
- govet
- intrange
- ineffassign
- lll
- misspell
- nakedret
- exportloopref
- funlen
- nestif
- nlreturn
- prealloc
- rowserrcheck
- noctx
- nolintlint
- revive
- staticcheck
- testifylint
- unconvert
- unparam
- unused
- whitespace
- wsl

settings:
govet:
enable-all: true
settings:
shadow:
strict: true
errcheck:
check-type-assertions: true
misspell:
locale: UK
ignore-words:
- initialized
funlen:
lines: 80
statements: 40
gci:
sections:
- standard
- default
- blank
- dot
- alias
custom-order: true
revive:
rules:
- name: package-comments
disabled: true
exclusions:
generated: lax
rules:
- path: _test\.go
linters:
- dupl
- gosec
- wsl
- lll
- funlen
- nlreturn
- unused
- path: _test\.go
text: "^Error return value is not checked$"
linters:
- errcheck
- text: "^SA1019:.* is deprecated:"
linters:
- staticcheck
- text: "declaration of \"(err|ctx)\" shadows declaration at"
linters:
- govet
- text: "return value of `tx.Rollback` is not checked"
linters:
- errcheck

formatters:
enable:
- gofmt
- gci

settings:
gofmt:
simplify: true
rewrite-rules:
- pattern: 'interface{}'
replacement: 'any'
- pattern: 'a[b:len(a)]'
replacement: 'a[b:]'
gci:
sections:
- standard
- default
- blank
- dot
- prefix(github.com/gojekfarm)
custom-order: true

run:
skip-dirs:
- bin
skip-files:
- .*mock.*\.go$
- version.go
- .*\_test\.go$
- .*_test\.go$
- generate.go
modules-download-mode: readonly
linters-settings:
govet:
check-shadowing: true
enable-all: true
disable:
- asmdecl
- assign
errcheck:
check-type-assertions: true
misspell:
locale: UK
ignore-words:
- initialized
funlen:
lines: 80
statements: 40

issues:
exclude-use-default: false
exclude:
- declaration of "(err|ctx)" shadows declaration at
exclude-rules:
- text: "^SA1019: .* is deprecated:"
linters:
- staticcheck
- path: _test\.go
linters:
- dupl
- gosec
- wsl
- lll
- funlen
- nlreturn
- unused
- path: _test\.go
text: ^Error return value is not checked$
linters:
- errcheck
49 changes: 11 additions & 38 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,48 +1,35 @@
ALL_GO_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | sort)
# extract go minor version from go version output
GO_MINOR_VERSION := $(shell go version | cut -d' ' -f3 | cut -d'.' -f2)

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

# set build directory based on go minor version
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)))
GO_BUILD_DIRS := $(ALL_GO_MOD_DIRS)

PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
BIN_DIR := $(PROJECT_DIR)/.bin

fmt:
@$(call run-go-mod-dir,go fmt ./...,"go fmt")

gofmt:
@$(call run-go-mod-dir,go fmt ./...,"gofmt -s -w")
fmt: golangci-lint
@$(call run-go-mod-dir,$(GOLANGCI_LINT) fmt,".bin/golangci-lint fmt")

vet:
@$(call run-go-mod-dir,go vet ./...,"go vet")

lint: golangci-lint
@$(call run-go-mod-dir,$(GOLANGCI_LINT) run --timeout=10m -v,".bin/golangci-lint")

.PHONY: ci
ci: test test-cov test-xml
$(GOLANGCI_LINT) run --timeout=10m -v

imports: gci
@$(call run-go-mod-dir,$(GCI) -w -local github.com/gojekfarm ./ | { grep -v -e 'skip file .*' || true; },".bin/gci")

.PHONY: gomod.tidy
gomod.tidy:
.PHONY: tidy
tidy:
@$(call run-go-mod-dir,go mod tidy,"go mod tidy")

.PHONY: go.generate
go.generate: mockery protoc
.PHONY: generate
generate: mockery protoc
@$(call run-go-mod-dir,go generate ./...,"go generate")

## test: Run all tests
.PHONY: test test-run test-cov test-xml

test: check test-run

test-run:
test:
@$(call run-go-mod-dir,go test -race -covermode=atomic -coverprofile=coverage.out ./...,"go test")

test-cov: gocov
Expand All @@ -59,28 +46,14 @@ test-html: test-cov gocov-html
@open coverage.html

.PHONY: check
check: fmt vet imports lint
check: fmt vet lint
@git diff --quiet || test $$(git diff --name-only | grep -v -e 'go.mod$$' -e 'go.sum$$' | wc -l) -eq 0 || ( echo "The following changes (result of code generators and code checks) have been detected:" && git --no-pager diff && false ) # fail if Git working tree is dirty

# ========= Helpers ===========

## Determine the golangci-lint version based on $(GO_MINOR_VERSION)
###################
GOLANGCI_LINT_V18 := v1.50.1
GOLANGCI_LINT_DEFAULT := v1.53.3

get-golangci-lint-version = $(or $(value GOLANGCI_LINT_V$(1)), $(GOLANGCI_LINT_DEFAULT))
GOLANGCI_LINT_VERSION := $(call get-golangci-lint-version,$(GO_MINOR_VERSION))

###################

GOLANGCI_LINT = $(BIN_DIR)/golangci-lint
golangci-lint:
$(call go-get-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION))

GCI = $(BIN_DIR)/gci
gci:
$(call go-get-tool,$(GCI),github.com/daixiang0/[email protected])
$(call go-get-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest)

GOCOV = $(BIN_DIR)/gocov
gocov:
Expand Down
2 changes: 1 addition & 1 deletion errors/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/gojekfarm/xtools/errors

go 1.21
go 1.25

require github.com/stretchr/testify v1.10.0

Expand Down
2 changes: 1 addition & 1 deletion examples/xkafka/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/gojekfarm/xtools/examples/xkafka

go 1.21
go 1.25

replace (
github.com/gojekfarm/xtools => ../../
Expand Down
2 changes: 1 addition & 1 deletion examples/xload/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/gojekfarm/xtools/examples/xload

go 1.20
go 1.25

replace (
github.com/gojekfarm/xtools/xload => ../../xload
Expand Down
8 changes: 8 additions & 0 deletions examples/xload/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,33 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/gotidy/ptr v1.4.0 h1:7++suUs+HNHMnyz6/AW3SE+4EnBhupPSQTSI7QNijVc=
github.com/gotidy/ptr v1.4.0/go.mod h1:MjRBG6/IETiiZGWI8LrRtISXEji+8b/jigmj2q0mEyM=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA=
github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 1 addition & 1 deletion examples/xload/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func main() {
_ = f.Close()
}

func prettyPrint(v interface{}) {
func prettyPrint(v any) {
out, _ := json.MarshalIndent(v, "", " ")
println(string(out))
}
Expand Down
2 changes: 1 addition & 1 deletion generic/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/gojekfarm/xtools/generic

go 1.18
go 1.25

require github.com/stretchr/testify v1.7.0

Expand Down
Loading