Skip to content

Commit 73d2a72

Browse files
author
Alex Toker
committed
Bump go and linter to 1.23
1 parent 30f5740 commit 73d2a72

File tree

21 files changed

+349
-182
lines changed

21 files changed

+349
-182
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ jobs:
3131
name: Lint
3232
runs-on: ubuntu-latest
3333
steps:
34-
- uses: actions/checkout@v3
35-
- uses: actions/setup-go@v3
34+
- uses: actions/checkout@v4
35+
- uses: actions/setup-go@v5
3636
with:
3737
cache: true
3838
go-version-file: "go.mod"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
branches: [main, development]
5+
pull_request:
6+
branches: [main, development]
7+
8+
permissions:
9+
contents: read
10+
pull-requests: read
11+
checks: write
12+
13+
jobs:
14+
golangci:
15+
name: lint
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- uses: actions/setup-go@v5
21+
with:
22+
go-version: '1.23'
23+
24+
- name: golangci-lint
25+
uses: golangci/golangci-lint-action@v7
26+
with:
27+
version: v2.4.0
28+
args: --config .golangci.yml

.golangci.yml

Lines changed: 61 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019 Iguazio
1+
# Copyright 2025 Iguazio
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -12,35 +12,69 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
#
15+
version: "2"
16+
17+
# timeout for analysis
18+
timeout: 5m
19+
run:
20+
build-tags:
21+
- test_unit
22+
- test_integration
1523
linters:
16-
disable-all: true
24+
default: none
1725
enable:
18-
- gofmt
19-
- revive
20-
- gosimple
26+
- errcheck
27+
- goconst
28+
- gocritic
29+
- govet
2130
- ineffassign
2231
- misspell
32+
- revive
2333
- staticcheck
2434
- unconvert
25-
- vet
26-
- vetshadow
27-
- errcheck
28-
29-
run:
30-
31-
# timeout for analysis
32-
timeout: 10m
33-
34-
skip-dirs:
35-
- hack
36-
- docs
37-
- test
38-
- vendor
39-
40-
issues:
41-
42-
# List of regexps of issue texts to exclude
43-
exclude:
44-
- "comment on"
45-
- "error should be the last"
46-
- "should have comment"
35+
- unused
36+
settings:
37+
gocritic:
38+
disabled-checks:
39+
- commentFormatting
40+
revive:
41+
rules:
42+
- name: errorf
43+
disabled: true
44+
exclusions:
45+
generated: lax
46+
presets:
47+
- comments
48+
- common-false-positives
49+
- legacy
50+
- std-error-handling
51+
rules:
52+
- linters:
53+
- goconst
54+
path: _test\.go
55+
- path: (.+)\.go$
56+
text: comment on
57+
- path: (.+)\.go$
58+
text: error should be the last
59+
paths:
60+
- docs
61+
- hack
62+
formatters:
63+
enable:
64+
- gci
65+
- gofmt
66+
settings:
67+
gci:
68+
sections:
69+
- standard
70+
- prefix(github.com/v3io/)
71+
- prefix(github.com/nuclio/)
72+
- default
73+
- blank
74+
- dot
75+
custom-order: true
76+
exclusions:
77+
generated: lax
78+
paths:
79+
- docs
80+
- hack

Makefile

Lines changed: 167 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,91 @@
1-
# Copyright 2019 Iguazio
1+
# Copyright 2025 The v3io-go Authors.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
55
# You may obtain a copy of the License at
66
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
7+
# http://www.apache.org/licenses/LICENSE-2.0
88
#
99
# Unless required by applicable law or agreed to in writing, software
1010
# distributed under the License is distributed on an "AS IS" BASIS,
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
15+
GO_VERSION := $(shell go version | cut -d " " -f 3)
16+
GOPATH ?= $(shell go env GOPATH)
17+
SHELL := /bin/bash
18+
19+
# Get default os / arch from go env
20+
V3IO_DEFAULT_OS := $(shell go env GOOS)
21+
V3IO_DEFAULT_ARCH := $(shell go env GOARCH || echo amd64)
22+
23+
V3IO_OS := $(if $(V3IO_OS),$(V3IO_OS),$(V3IO_DEFAULT_OS))
24+
V3IO_ARCH := $(if $(V3IO_ARCH),$(V3IO_ARCH),$(V3IO_DEFAULT_ARCH))
25+
26+
# Version information
27+
V3IO_VERSION_GIT_COMMIT = $(shell git rev-parse HEAD)
28+
V3IO_PATH ?= $(shell pwd)
29+
30+
# Link flags
31+
GO_LINK_FLAGS ?= -s -w
32+
33+
# Go test timeout
34+
V3IO_GO_TEST_TIMEOUT ?= "30m"
35+
36+
#
37+
# Must be first target
38+
#
39+
.PHONY: all
40+
all:
41+
$(error "Please pick a target (run 'make targets' to view targets)")
42+
43+
#
44+
# Linting and formatting
45+
#
46+
.PHONY: fmt
47+
fmt: ensure-golangci-linter
48+
gofmt -s -w .
49+
$(GOLANGCI_LINT_BIN) run --fix
50+
51+
.PHONY: lint
52+
lint: modules ensure-test-files-annotated ensure-golangci-linter
53+
@echo Linting...
54+
$(GOLANGCI_LINT_BIN) run -v
55+
@echo Done.
56+
57+
.PHONY: ensure-test-files-annotated
58+
ensure-test-files-annotated:
59+
$(eval test_files_missing_build_annotations=$(strip $(shell find . -type f -name '*_test.go' -exec bash -c "grep -m 1 -L '//go:build ' {} | grep go" \;)))
60+
@if [ -n "$(test_files_missing_build_annotations)" ]; then \
61+
echo "Found go test files without build annotations: "; \
62+
echo $(test_files_missing_build_annotations); \
63+
echo "!!! Go test files must be annotated with '//go:build test_<x>' !!!"; \
64+
exit 1; \
65+
fi
66+
@echo "All go test files have //go:build test_X annotation"
67+
@exit $(.SHELLSTATUS)
68+
69+
GOLANGCI_LINT_VERSION := 2.3.0
70+
GOLANGCI_LINT_BIN := $(CURDIR)/.bin/golangci-lint
71+
GOLANGCI_LINT_INSTALL_COMMAND := GOBIN=$(CURDIR)/.bin go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v$(GOLANGCI_LINT_VERSION)
72+
73+
.PHONY: ensure-golangci-linter
74+
ensure-golangci-linter:
75+
@if ! command -v $(GOLANGCI_LINT_BIN) >/dev/null 2>&1; then \
76+
echo "golangci-lint not found. Installing..."; \
77+
$(GOLANGCI_LINT_INSTALL_COMMAND); \
78+
else \
79+
installed_version=$$($(GOLANGCI_LINT_BIN) version | awk '/version/ {gsub(/^v/, "", $$4); print $$4}'); \
80+
if [ "$$installed_version" != "$(GOLANGCI_LINT_VERSION)" ]; then \
81+
echo "golangci-lint version mismatch ($$installed_version != $(GOLANGCI_LINT_VERSION)). Reinstalling..."; \
82+
$(GOLANGCI_LINT_INSTALL_COMMAND); \
83+
fi \
84+
fi
85+
86+
#
87+
# Environment validation
1488
#
15-
# To setup env locally on your dev box, run:
16-
# $ export $(grep -v '^#' ./hack/test.env | xargs)
1789
.PHONY: check-env
1890
check-env:
1991
ifndef V3IO_DATAPLANE_URL
@@ -39,45 +111,70 @@ ifndef V3IO_CONTROLPLANE_IGZ_ADMIN_PASSWORD
39111
endif
40112
@echo "All required env vars populated"
41113

114+
#
115+
# Schema generation
116+
#
42117
.PHONY: generate-capnp
43118
generate-capnp:
44-
pushd ./pkg/dataplane/schemas/; ./build; popd
119+
@echo "Generating Cap'n Proto schemas..."
120+
@cd ./pkg/dataplane/schemas/; ./build
121+
@echo "Schema generation complete."
45122

46-
.PHONY: clean
47-
clean:
48-
pushd ./pkg/dataplane/schemas/; ./clean; popd
123+
.PHONY: clean-schemas
124+
clean-schemas:
125+
@echo "Cleaning generated schemas..."
126+
@cd ./pkg/dataplane/schemas/; ./clean
127+
@echo "Schema cleanup complete."
49128

50-
.PHONY: fmt
51-
fmt:
52-
gofmt -s -w .
129+
#
130+
# Building
131+
#
132+
.PHONY: build-lib
133+
build-lib: modules
134+
@echo "Building v3io-go library..."
135+
@go build ./pkg/...
136+
@echo "Library build successful."
53137

54-
.PHONY: lint
55-
lint:
56-
./hack/lint/install.sh
57-
./hack/lint/run.sh
138+
.PHONY: build
139+
build: clean-schemas generate-capnp build-lib lint test
140+
@echo "Full build pipeline complete."
58141

59-
.PHONY: test
60-
test: check-env
61-
go test -race -tags unit -count 1 ./...
142+
#
143+
# Testing
144+
#
145+
.PHONY: test-unit
146+
test-unit: modules ensure-gopath
147+
go test -race -tags=test_unit -v ./pkg/... -short
148+
149+
.PHONY: test-integration
150+
test-integration: modules ensure-gopath
151+
go test -race -tags=test_integration -v ./pkg/... --timeout $(V3IO_GO_TEST_TIMEOUT)
152+
153+
.PHONY: test-coverage
154+
test-coverage:
155+
go test -tags=test_unit -coverprofile=coverage.out ./pkg/... || go tool cover -html=coverage.out
62156

63157
.PHONY: test-controlplane
64-
test-controlplane: check-env
65-
go test -test.v=true -race -tags unit -count 1 ./pkg/controlplane/...
158+
test-controlplane: modules ensure-gopath check-env
159+
go test -test.v=true -race -tags=test_unit -count=1 ./pkg/controlplane/...
66160

67161
.PHONY: test-dataplane
68-
test-dataplane: check-env
69-
go test -test.v=true -race -tags unit -count 1 ./pkg/dataplane/...
162+
test-dataplane: modules ensure-gopath check-env
163+
go test -test.v=true -race -tags=test_unit -count=1 ./pkg/dataplane/...
70164

71165
.PHONY: test-dataplane-simple
72-
test-dataplane-simple: check-env
73-
go test -test.v=true -tags unit -count 1 ./pkg/dataplane/...
166+
test-dataplane-simple: modules ensure-gopath check-env
167+
go test -test.v=true -tags=test_unit -count=1 ./pkg/dataplane/...
74168

75169
.PHONY: test-system
76170
test-system: test-controlplane test-dataplane-simple
77171

172+
.PHONY: test
173+
test: test-unit
174+
78175
.PHONY: build-test-container
79176
build-test-container:
80-
@echo Building test container...
177+
@echo "Building test container..."
81178
docker build \
82179
--file hack/test/docker/Dockerfile \
83180
--tag v3io-go-test:latest \
@@ -87,15 +184,50 @@ build-test-container:
87184
test-system-in-docker: build-test-container
88185
@echo "Running system test in docker container..."
89186
docker run --rm \
90-
--env V3IO_DATAPLANE_URL="${V3IO_DATAPLANE_URL}" \
91-
--env V3IO_DATAPLANE_USERNAME="${V3IO_DATAPLANE_USERNAME}" \
92-
--env V3IO_DATAPLANE_ACCESS_KEY="${V3IO_DATAPLANE_ACCESS_KEY}" \
93-
--env V3IO_CONTROLPLANE_URL="${V3IO_CONTROLPLANE_URL}" \
94-
--env V3IO_CONTROLPLANE_USERNAME="${V3IO_CONTROLPLANE_USERNAME}" \
95-
--env V3IO_CONTROLPLANE_PASSWORD="${V3IO_CONTROLPLANE_PASSWORD}" \
96-
--env V3IO_CONTROLPLANE_IGZ_ADMIN_PASSWORD="${V3IO_CONTROLPLANE_IGZ_ADMIN_PASSWORD}" \
187+
--env V3IO_DATAPLANE_URL="$(V3IO_DATAPLANE_URL)" \
188+
--env V3IO_DATAPLANE_USERNAME="$(V3IO_DATAPLANE_USERNAME)" \
189+
--env V3IO_DATAPLANE_ACCESS_KEY="$(V3IO_DATAPLANE_ACCESS_KEY)" \
190+
--env V3IO_CONTROLPLANE_URL="$(V3IO_CONTROLPLANE_URL)" \
191+
--env V3IO_CONTROLPLANE_USERNAME="$(V3IO_CONTROLPLANE_USERNAME)" \
192+
--env V3IO_CONTROLPLANE_PASSWORD="$(V3IO_CONTROLPLANE_PASSWORD)" \
193+
--env V3IO_CONTROLPLANE_IGZ_ADMIN_PASSWORD="$(V3IO_CONTROLPLANE_IGZ_ADMIN_PASSWORD)" \
97194
v3io-go-test:latest make test-system
98-
@echo Done.
195+
@echo "Docker test complete."
99196

100-
.PHONY: build
101-
build: clean generate-capnp lint test
197+
#
198+
# Go modules and environment
199+
#
200+
.PHONY: ensure-gopath
201+
ensure-gopath:
202+
ifndef GOPATH
203+
$(error GOPATH must be set)
204+
endif
205+
206+
.PHONY: modules
207+
modules: ensure-gopath
208+
@go mod download
209+
210+
.PHONY: tidy
211+
tidy:
212+
@go mod tidy
213+
214+
.PHONY: clean
215+
clean: clean-schemas
216+
@echo "Cleaning build artifacts..."
217+
@go clean -cache
218+
@rm -rf .bin/
219+
@rm -rf coverage.out
220+
@echo "Clean complete."
221+
222+
.PHONY: targets
223+
targets:
224+
@awk -F: '/^[^ \t="]+:/ && !/PHONY/ {print $$1}' Makefile | sort -u
225+
226+
#
227+
# Versioning
228+
#
229+
.PHONY: version
230+
version:
231+
@echo "Git commit: $(V3IO_VERSION_GIT_COMMIT)"
232+
@echo "Go version: $(GO_VERSION)"
233+
@echo "OS/Arch: $(V3IO_OS)/$(V3IO_ARCH)"

0 commit comments

Comments
 (0)