-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
75 lines (60 loc) · 1.7 KB
/
Makefile
File metadata and controls
75 lines (60 loc) · 1.7 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
# Project variables
BINARY_NAME := sshto
OUTPUT_DIR := bin
MODULE := github.com/codoworks/sshto
# Go commands
GO := go
GOFMT := gofmt
GOVET := $(GO) vet
GOTEST := $(GO) test
GOBUILD := $(GO) build
# Build flags
LDFLAGS := -s -w
.PHONY: all build test test-coverage fmt fmt-check vet lint clean install tidy help
## all: Build the binary (default target)
all: build
## build: Build the binary to bin/
build:
@mkdir -p $(OUTPUT_DIR)
$(GOBUILD) -ldflags "$(LDFLAGS)" -o $(OUTPUT_DIR)/$(BINARY_NAME) .
## test: Run all tests
test:
$(GOTEST) -v -race ./...
## test-coverage: Run tests with coverage report
test-coverage:
$(GOTEST) -v -race -coverprofile=coverage.txt -covermode=atomic ./...
$(GO) tool cover -html=coverage.txt -o coverage.html
## fmt: Format all Go files
fmt:
$(GOFMT) -w .
## fmt-check: Check if code is formatted
fmt-check:
@if [ -n "$$($(GOFMT) -l .)" ]; then \
echo "Code is not formatted. Run 'make fmt'"; \
$(GOFMT) -d .; \
exit 1; \
fi
## vet: Run go vet
vet:
$(GOVET) ./...
## lint: Run golangci-lint (requires golangci-lint installed)
lint:
@which golangci-lint > /dev/null || (echo "golangci-lint not installed. Run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest" && exit 1)
golangci-lint run ./...
## clean: Remove build artifacts
clean:
rm -rf $(OUTPUT_DIR)
rm -f coverage.txt coverage.html
## install: Install binary to GOPATH/bin
install:
$(GOBUILD) -ldflags "$(LDFLAGS)" -o $(GOPATH)/bin/$(BINARY_NAME) .
## tidy: Tidy and verify module dependencies
tidy:
$(GO) mod tidy
$(GO) mod verify
## help: Show this help message
help:
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@sed -n 's/^## //p' $(MAKEFILE_LIST) | column -t -s ':' | sed 's/^/ /'