-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
134 lines (111 loc) · 3.89 KB
/
Makefile
File metadata and controls
134 lines (111 loc) · 3.89 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
.PHONY: all build clean test lint fmt vet install help docker-build release release-snapshot release-test
# Binary name
BINARY_NAME=gac
DOCKER_IMAGE=gac:latest
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOFMT=$(GOCMD) fmt
GOVET=$(GOCMD) vet
# Build parameters
BUILD_DIR=build
VERSION?=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT?=$(shell git rev-parse --short HEAD 2>/dev/null || echo "none")
DATE?=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
BUILT_BY?=make
LDFLAGS=-ldflags "-s -w -X main.Version=$(VERSION) -X main.Commit=$(COMMIT) -X main.Date=$(DATE) -X main.BuiltBy=$(BUILT_BY)"
all: test build
## build: Build the binary
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) -v
## clean: Remove build artifacts
clean:
@echo "Cleaning..."
$(GOCLEAN)
@rm -rf $(BUILD_DIR)
@rm -f $(BINARY_NAME)
## test: Run tests
test:
@echo "Running tests..."
$(GOTEST) -v ./...
## test-coverage: Run tests with coverage
test-coverage:
@echo "Running tests with coverage..."
$(GOTEST) -v -coverprofile=coverage.out ./...
$(GOCMD) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
## lint: Run linter (requires golangci-lint)
lint:
@echo "Running linter..."
@which golangci-lint > /dev/null || (echo "golangci-lint not installed. Install from https://golangci-lint.run/usage/install/" && exit 1)
golangci-lint run ./...
## gosec: Run security scanner (requires gosec)
# Version should match .github/workflows/pr-checks.yml (currently v2.23.0)
gosec:
@echo "Running security scanner..."
@which gosec > /dev/null || (echo "gosec not installed. Install with: go install github.com/securego/gosec/v2/cmd/gosec@v2.23.0" && exit 1)
gosec ./...
## fmt: Format code
fmt:
@echo "Formatting code..."
$(GOFMT) ./...
## vet: Run go vet
vet:
@echo "Running go vet..."
$(GOVET) ./...
## tidy: Tidy go modules
tidy:
@echo "Tidying go modules..."
$(GOMOD) tidy
## deps: Download dependencies
deps:
@echo "Downloading dependencies..."
$(GOMOD) download
## update-deps: Update dependencies
update-deps:
@echo "Updating dependencies..."
$(GOGET) -u ./...
$(GOMOD) tidy
## install: Install binary to $GOPATH/bin
install: build
@echo "Installing $(BINARY_NAME)..."
@cp $(BUILD_DIR)/$(BINARY_NAME) $(GOPATH)/bin/$(BINARY_NAME)
## docker-build: Build Docker image
docker-build:
@echo "Building Docker image..."
docker build -t $(DOCKER_IMAGE) .
## run: Build and run the binary
run: build
@echo "Running $(BINARY_NAME)..."
./$(BUILD_DIR)/$(BINARY_NAME)
## check: Run all checks (fmt, vet, lint, gosec, test)
check: fmt vet lint gosec test
## release-snapshot: Build release snapshot locally (requires goreleaser)
release-snapshot:
@echo "Building release snapshot..."
@which goreleaser > /dev/null || (echo "goreleaser not installed. Install from https://goreleaser.com/install/" && exit 1)
goreleaser build --snapshot --clean
## release-test: Test release configuration without publishing
release-test:
@echo "Testing release configuration..."
@which goreleaser > /dev/null || (echo "goreleaser not installed. Install from https://goreleaser.com/install/" && exit 1)
goreleaser check
goreleaser release --snapshot --skip=publish --clean
## release: Create and publish a release (requires goreleaser and git tag)
release:
@echo "Creating release..."
@which goreleaser > /dev/null || (echo "goreleaser not installed. Install from https://goreleaser.com/install/" && exit 1)
@git describe --exact-match --tags HEAD > /dev/null 2>&1 || (echo "Error: Not on a tagged commit. Create a tag first with: git tag v0.1.0" && exit 1)
goreleaser release --clean
## help: Show this help message
help:
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'