@@ -16,9 +16,9 @@ SRC_DIR := .
1616CGO_ENABLED := 0
1717
1818# Version information (from git tags and commit)
19- VERSION = dev
20- COMMIT = unknown
21- BUILD_TIME = unknown
19+ VERSION := $( shell git describe --tags --always --dirty 2>NUL || echo dev)
20+ COMMIT := $( shell git rev-parse --short HEAD 2>NUL || echo unknown)
21+ BUILD_TIME := $( shell git log -1 --format= % cI 2>NUL || echo unknown)
2222
2323# Optimization flags for smallest possible binary
2424GCFLAGS := -gcflags="all=-l"
@@ -34,27 +34,41 @@ BUILD_TAGS := netgo osusergo
3434GOOS_BUILD := $(if $(GOOS ) ,$(GOOS ) ,$(shell go env GOOS) )
3535GOARCH_BUILD := $(if $(GOARCH ) ,$(GOARCH ) ,$(shell go env GOARCH) )
3636
37- .PHONY : build clean test fmt vet help lint all deps ci goreleaser-check goreleaser-test
37+ .PHONY : build build-release clean test test-coverage fmt vet help lint all deps ci run install
3838
3939# Build the binary into the build directory
4040build : $(BUILD_DIR )
4141 @CGO_ENABLED=$(CGO_ENABLED ) go build $(LDFLAGS ) -tags " $( BUILD_TAGS) " -o $(BINARY ) ./$(SRC_DIR )
4242
43+ # Build optimized release binary
44+ build-release : $(BUILD_DIR )
45+ @CGO_ENABLED=$(CGO_ENABLED ) go build $(LDFLAGS_RELEASE ) -tags " $( BUILD_TAGS) " -trimpath -o $(BINARY ) ./$(SRC_DIR )
46+
4347$(BUILD_DIR ) :
4448 @mkdir -p $(BUILD_DIR )
4549
50+ # Run the application
51+ run : build
52+ @$(BINARY )
53+
54+ # Install to GOPATH/bin
55+ install :
56+ @CGO_ENABLED=$(CGO_ENABLED ) go install $(LDFLAGS ) -tags " $( BUILD_TAGS) " .
57+
4658# Clean build artifacts
4759clean :
4860 @rm -rf $(BUILD_DIR ) $(DIST_DIR ) coverage.out coverage.html
4961
5062# Run tests
5163test :
52- @go test ./...
64+ @go test ./... -v
5365
66+ # Run tests with coverage
5467test-coverage :
55- # @go test -race - coverprofile=coverage.out . /...
68+ @go test -coverprofile=coverage.out -covermode=atomic ./internal /...
5669 @go tool cover -html=coverage.out -o coverage.html
5770 @go tool cover -func=coverage.out | tail -1
71+ @echo " Coverage report: coverage.html"
5872
5973# Format Go code
6074fmt :
6680
6781# Run both fmt and vet
6882lint : fmt vet
69- @go tool golangci-lint run
83+ @golangci-lint run 2> /dev/null || echo " ⚠️ golangci-lint not installed "
7084
7185# Build and run tests
7286all : clean test build
@@ -76,20 +90,20 @@ deps:
7690
7791ci : deps lint test build
7892
79- goreleaser-check :
80- @go tool goreleaser check || echo " ⚠️ goreleaser not found"
81-
82- goreleaser-test :
83- @./scripts/test-goreleaser.sh
84-
8593# Show help
8694help :
8795 @echo " Available targets:"
88- @echo " build - Build the spc binary into $( BUILD_DIR) / directory"
89- @echo " clean - Remove build artifacts"
90- @echo " test - Run Go tests"
91- @echo " fmt - Format Go code"
92- @echo " vet - Run go vet"
93- @echo " lint - Run fmt and vet"
94- @echo " all - Build and run tests"
95- @echo " help - Show this help"
96+ @echo " build - Build the spc binary into $( BUILD_DIR) / directory"
97+ @echo " build-release - Build optimized release binary"
98+ @echo " run - Build and run the application"
99+ @echo " install - Install to GOPATH/bin"
100+ @echo " clean - Remove build artifacts"
101+ @echo " test - Run Go tests"
102+ @echo " test-coverage - Run tests with coverage report"
103+ @echo " fmt - Format Go code"
104+ @echo " vet - Run go vet"
105+ @echo " lint - Run fmt, vet, and golangci-lint"
106+ @echo " deps - Download dependencies"
107+ @echo " ci - Run CI pipeline (deps, lint, test, build)"
108+ @echo " all - Clean, test, and build"
109+ @echo " help - Show this help"
0 commit comments