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-golangci-linter
53+ @echo Linting...
54+ $(GOLANGCI_LINT_BIN ) run -v
55+ @echo Done.
56+
57+
58+ GOLANGCI_LINT_VERSION := 2.3.0
59+ GOLANGCI_LINT_BIN := $(CURDIR ) /.bin/golangci-lint
60+ GOLANGCI_LINT_INSTALL_COMMAND := GOBIN=$(CURDIR ) /.bin go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v$(GOLANGCI_LINT_VERSION )
61+
62+ .PHONY : ensure-golangci-linter
63+ ensure-golangci-linter :
64+ @if ! command -v $(GOLANGCI_LINT_BIN ) > /dev/null 2>&1 ; then \
65+ echo " golangci-lint not found. Installing..." ; \
66+ $(GOLANGCI_LINT_INSTALL_COMMAND ) ; \
67+ else \
68+ installed_version=$$($(GOLANGCI_LINT_BIN ) version | awk '/version/ {gsub(/^v/, "", $$4) ; print $$ 4}' ); \
69+ if [ " $$ installed_version" != " $( GOLANGCI_LINT_VERSION) " ]; then \
70+ echo " golangci-lint version mismatch ($$ installed_version != $( GOLANGCI_LINT_VERSION) ). Reinstalling..." ; \
71+ $(GOLANGCI_LINT_INSTALL_COMMAND ) ; \
72+ fi \
73+ fi
74+
75+ #
76+ # Environment validation
1477#
15- # To setup env locally on your dev box, run:
16- # $ export $(grep -v '^#' ./hack/test.env | xargs)
1778.PHONY : check-env
1879check-env :
1980ifndef V3IO_DATAPLANE_URL
@@ -39,45 +100,70 @@ ifndef V3IO_CONTROLPLANE_IGZ_ADMIN_PASSWORD
39100endif
40101 @echo "All required env vars populated"
41102
103+ #
104+ # Schema generation
105+ #
42106.PHONY : generate-capnp
43107generate-capnp :
44- pushd ./pkg/dataplane/schemas/; ./build; popd
108+ @echo " Generating Cap'n Proto schemas..."
109+ @cd ./pkg/dataplane/schemas/; ./build
110+ @echo " Schema generation complete."
45111
46- .PHONY : clean
47- clean :
48- pushd ./pkg/dataplane/schemas/; ./clean; popd
112+ .PHONY : clean-schemas
113+ clean-schemas :
114+ @echo " Cleaning generated schemas..."
115+ @cd ./pkg/dataplane/schemas/; ./clean
116+ @echo " Schema cleanup complete."
49117
50- .PHONY : fmt
51- fmt :
52- gofmt -s -w .
118+ #
119+ # Building
120+ #
121+ .PHONY : build-lib
122+ build-lib : modules
123+ @echo " Building v3io-go library..."
124+ @go build ./pkg/...
125+ @echo " Library build successful."
53126
54- .PHONY : lint
55- lint :
56- ./hack/lint/install.sh
57- ./hack/lint/run.sh
127+ .PHONY : build
128+ build : clean-schemas generate-capnp build-lib lint test
129+ @echo " Full build pipeline complete."
58130
59- .PHONY : test
60- test : check-env
61- go test -race -tags unit -count 1 ./...
131+ #
132+ # Testing
133+ #
134+ .PHONY : test-unit
135+ test-unit : modules ensure-gopath
136+ go test -race -tags=test_unit -v ./pkg/... -short
137+
138+ .PHONY : test-integration
139+ test-integration : modules ensure-gopath
140+ go test -race -tags=test_integration -v ./pkg/... --timeout $(V3IO_GO_TEST_TIMEOUT )
141+
142+ .PHONY : test-coverage
143+ test-coverage :
144+ go test -tags=test_unit -coverprofile=coverage.out ./pkg/... || go tool cover -html=coverage.out
62145
63146.PHONY : test-controlplane
64- test-controlplane : check-env
65- go test -test.v=true -race -tags unit -count 1 ./pkg/controlplane/...
147+ test-controlplane : modules ensure-gopath check-env
148+ go test -test.v=true -race -tags=test_unit -count= 1 ./pkg/controlplane/...
66149
67150.PHONY : test-dataplane
68- test-dataplane : check-env
69- go test -test.v=true -race -tags unit -count 1 ./pkg/dataplane/...
151+ test-dataplane : modules ensure-gopath check-env
152+ go test -test.v=true -race -tags=test_unit -count= 1 ./pkg/dataplane/...
70153
71154.PHONY : test-dataplane-simple
72- test-dataplane-simple : check-env
73- go test -test.v=true -tags unit -count 1 ./pkg/dataplane/...
155+ test-dataplane-simple : modules ensure-gopath check-env
156+ go test -test.v=true -tags=test_unit -count= 1 ./pkg/dataplane/...
74157
75158.PHONY : test-system
76159test-system : test-controlplane test-dataplane-simple
77160
161+ .PHONY : test
162+ test : test-unit
163+
78164.PHONY : build-test-container
79165build-test-container :
80- @echo Building test container...
166+ @echo " Building test container..."
81167 docker build \
82168 --file hack/test/docker/Dockerfile \
83169 --tag v3io-go-test:latest \
@@ -87,15 +173,50 @@ build-test-container:
87173test-system-in-docker : build-test-container
88174 @echo " Running system test in docker container..."
89175 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} " \
176+ --env V3IO_DATAPLANE_URL=" $( V3IO_DATAPLANE_URL) " \
177+ --env V3IO_DATAPLANE_USERNAME=" $( V3IO_DATAPLANE_USERNAME) " \
178+ --env V3IO_DATAPLANE_ACCESS_KEY=" $( V3IO_DATAPLANE_ACCESS_KEY) " \
179+ --env V3IO_CONTROLPLANE_URL=" $( V3IO_CONTROLPLANE_URL) " \
180+ --env V3IO_CONTROLPLANE_USERNAME=" $( V3IO_CONTROLPLANE_USERNAME) " \
181+ --env V3IO_CONTROLPLANE_PASSWORD=" $( V3IO_CONTROLPLANE_PASSWORD) " \
182+ --env V3IO_CONTROLPLANE_IGZ_ADMIN_PASSWORD=" $( V3IO_CONTROLPLANE_IGZ_ADMIN_PASSWORD) " \
97183 v3io-go-test:latest make test-system
98- @echo Done.
184+ @echo " Docker test complete. "
99185
100- .PHONY : build
101- build : clean generate-capnp lint test
186+ #
187+ # Go modules and environment
188+ #
189+ .PHONY : ensure-gopath
190+ ensure-gopath :
191+ ifndef GOPATH
192+ $(error GOPATH must be set)
193+ endif
194+
195+ .PHONY : modules
196+ modules : ensure-gopath
197+ @go mod download
198+
199+ .PHONY : tidy
200+ tidy :
201+ @go mod tidy
202+
203+ .PHONY : clean
204+ clean : clean-schemas
205+ @echo " Cleaning build artifacts..."
206+ @go clean -cache
207+ @rm -rf .bin/
208+ @rm -rf coverage.out
209+ @echo " Clean complete."
210+
211+ .PHONY : targets
212+ targets :
213+ @awk -F: ' /^[^ \t="]+:/ && !/PHONY/ {print $$1}' Makefile | sort -u
214+
215+ #
216+ # Versioning
217+ #
218+ .PHONY : version
219+ version :
220+ @echo " Git commit: $( V3IO_VERSION_GIT_COMMIT) "
221+ @echo " Go version: $( GO_VERSION) "
222+ @echo " OS/Arch: $( V3IO_OS) /$( V3IO_ARCH) "
0 commit comments