-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
133 lines (111 loc) · 3.71 KB
/
Copy pathMakefile
File metadata and controls
133 lines (111 loc) · 3.71 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
# zepctl Makefile
# Build variables
BINARY_NAME := zepctl
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")
LDFLAGS := -ldflags "-s -w -X github.com/getzep/zepctl/internal/cli.version=$(VERSION) -X github.com/getzep/zepctl/internal/cli.commit=$(COMMIT) -X github.com/getzep/zepctl/internal/cli.date=$(DATE)"
# Go variables
GOCMD := go
GOBUILD := $(GOCMD) build
GOTEST := $(GOCMD) test
GOMOD := $(GOCMD) mod
GOFMT := gofumpt
GOLINT := golangci-lint
# Paths
CMD_PATH := ./cmd/zepctl
BUILD_DIR := build
DIST_DIR := dist
.PHONY: all build clean test lint fmt tidy help
## Default target
all: lint test build
## Build the binary for the current platform
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) $(CMD_PATH)
## Build for all target platforms
build-all: build-linux-amd64 build-linux-arm64 build-darwin-arm64
## Build for Linux amd64
build-linux-amd64:
@echo "Building for linux/amd64..."
@mkdir -p $(BUILD_DIR)
GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 $(CMD_PATH)
## Build for Linux arm64
build-linux-arm64:
@echo "Building for linux/arm64..."
@mkdir -p $(BUILD_DIR)
GOOS=linux GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64 $(CMD_PATH)
## Build for macOS arm64
build-darwin-arm64:
@echo "Building for darwin/arm64..."
@mkdir -p $(BUILD_DIR)
GOOS=darwin GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 $(CMD_PATH)
## Run tests
test:
@echo "Running tests..."
$(GOTEST) -v -race -coverprofile=coverage.out ./...
## Run tests with coverage report
test-coverage: test
@echo "Generating coverage report..."
$(GOCMD) tool cover -html=coverage.out -o coverage.html
## Run linter
lint:
@echo "Running linter..."
$(GOLINT) run ./...
## Format code
fmt:
@echo "Formatting code..."
$(GOFMT) -w .
## Check formatting
fmt-check:
@echo "Checking code formatting..."
@test -z "$$($(GOFMT) -l .)" || (echo "Code is not formatted. Run 'make fmt'" && exit 1)
## Tidy dependencies
tidy:
@echo "Tidying dependencies..."
$(GOMOD) tidy
## Verify dependencies
verify:
@echo "Verifying dependencies..."
$(GOMOD) verify
## Clean build artifacts
clean:
@echo "Cleaning..."
@rm -rf $(BUILD_DIR) $(DIST_DIR)
@rm -f coverage.out coverage.html
## Install the binary locally
install: build
@echo "Installing $(BINARY_NAME)..."
@cp $(BUILD_DIR)/$(BINARY_NAME) $(shell go env GOPATH)/bin/$(BINARY_NAME)
## Run GoReleaser in snapshot mode (for testing)
release-snapshot:
@echo "Creating snapshot release..."
goreleaser release --snapshot --clean
## Run GoReleaser (requires GITHUB_TOKEN)
release:
@echo "Creating release..."
goreleaser release --clean
## Display help
help:
@echo "zepctl Makefile"
@echo ""
@echo "Usage:"
@echo " make <target>"
@echo ""
@echo "Targets:"
@echo " all Run lint, test, and build (default)"
@echo " build Build for current platform"
@echo " build-all Build for all target platforms"
@echo " test Run tests"
@echo " test-coverage Run tests with coverage report"
@echo " lint Run linter"
@echo " fmt Format code"
@echo " fmt-check Check code formatting"
@echo " tidy Tidy dependencies"
@echo " verify Verify dependencies"
@echo " clean Clean build artifacts"
@echo " install Install binary locally"
@echo " release-snapshot Test release with goreleaser"
@echo " release Create release with goreleaser"
@echo " help Display this help"