-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
84 lines (70 loc) · 2.26 KB
/
Makefile
File metadata and controls
84 lines (70 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
.PHONY: setup build test test-verbose test-coverage lint clean run install tidy help
# Build configuration
BINARY_NAME=natcheck
VERSION?=$(shell git describe --tags --always --dirty 2>/dev/null || echo "v0.1.0-dev")
BUILD_DIR=.
CMD_DIR=./cmd/natcheck
INTERNAL_PACKAGES=./internal/...
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOTEST=$(GOCMD) test
GOMOD=$(GOCMD) mod
GOINSTALL=$(GOCMD) install
GOCLEAN=$(GOCMD) clean
# Build flags
LDFLAGS=-ldflags "-X main.version=$(VERSION)"
## help: Display this help message
help:
@echo "natcheck - Build Targets"
@echo ""
@echo "Usage:"
@echo " make <target>"
@echo ""
@echo "Targets:"
@awk '/^## [a-zA-Z_-]+:/ { sub(/^## /, ""); split($$0, parts, ": "); printf " %-20s %s\n", parts[1], substr($$0, length(parts[1])+3) }' $(MAKEFILE_LIST)
## setup: Install development tools (golangci-lint v2.9.0)
setup:
@echo "Installing dev tools..."
$(GOINSTALL) github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.9.0
@echo "Setup complete."
## build: Build the binary
build:
@echo "Building $(BINARY_NAME) $(VERSION)..."
$(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) $(CMD_DIR)
@echo "Build complete: $(BUILD_DIR)/$(BINARY_NAME)"
## test: Run all tests (short mode)
test:
@echo "Running tests..."
$(GOTEST) -race -short -timeout 60s $(INTERNAL_PACKAGES)
## test-verbose: Run tests with verbose output
test-verbose:
@echo "Running tests (verbose)..."
$(GOTEST) -race -v -timeout 60s $(INTERNAL_PACKAGES)
## test-coverage: Run tests with coverage report
test-coverage:
@echo "Running tests with coverage..."
$(GOTEST) -race -coverprofile=coverage.out $(INTERNAL_PACKAGES)
$(GOCMD) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report: coverage.html"
## lint: Run golangci-lint
lint:
@echo "Running linter..."
@command -v golangci-lint >/dev/null 2>&1 || { echo "golangci-lint not found"; exit 1; }
golangci-lint run ./...
## run: Build and run natcheck with default flags
run: build
./$(BINARY_NAME)
## install: Install natcheck to GOPATH/bin
install:
@echo "Installing $(BINARY_NAME)..."
$(GOINSTALL) $(LDFLAGS) $(CMD_DIR)
## clean: Remove build artifacts
clean:
@echo "Cleaning..."
$(GOCLEAN)
rm -f $(BUILD_DIR)/$(BINARY_NAME)
rm -f coverage.out coverage.html
## tidy: Tidy go modules
tidy:
$(GOMOD) tidy