forked from DataDog/pup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
147 lines (120 loc) · 4.9 KB
/
Copy pathMakefile
File metadata and controls
147 lines (120 loc) · 4.9 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
135
136
137
138
139
140
141
142
143
144
145
146
147
# Makefile for Pup - Datadog API CLI Wrapper
# Uses goreleaser for repeatable builds
.PHONY: help build build-all build-snapshot test test-verbose lint clean install deps check-goreleaser version
# Default target
.DEFAULT_GOAL := help
# Binary name
BINARY_NAME := pup
# Get version information
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
# Build flags
LDFLAGS := -s -w \
-X github.com/DataDog/pup/internal/version.Version=$(VERSION) \
-X github.com/DataDog/pup/internal/version.Commit=$(COMMIT) \
-X github.com/DataDog/pup/internal/version.Date=$(DATE) \
-X github.com/DataDog/pup/internal/version.BuiltBy=makefile
# Go build flags
GO_BUILD_FLAGS := -trimpath -ldflags "$(LDFLAGS)"
help: ## Show this help message
@echo "Pup - Datadog API CLI Wrapper"
@echo ""
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@awk 'BEGIN {FS = ":.*##"; printf ""} /^[a-zA-Z_-]+:.*?##/ { printf " %-20s %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
build: check-goreleaser ## Build binary for current platform using goreleaser (fast, local development)
@echo "Building $(BINARY_NAME) for current platform..."
@goreleaser build --snapshot --clean --single-target
@echo "Binary available at: dist/pup_*/$(BINARY_NAME)"
build-all: check-goreleaser ## Build binaries for all platforms using goreleaser
@echo "Building $(BINARY_NAME) for all platforms..."
@goreleaser build --snapshot --clean
@echo "Binaries available in dist/ directory"
build-snapshot: check-goreleaser ## Create a full snapshot release (archives, checksums, SBOMs) without publishing
@echo "Creating snapshot release..."
@goreleaser release --snapshot --clean --skip=publish,sign
@echo "Release artifacts available in dist/ directory"
build-quick: ## Quick build using go build (no goreleaser, fastest for development)
@echo "Building $(BINARY_NAME) with go build..."
@CGO_ENABLED=0 go build $(GO_BUILD_FLAGS) -o $(BINARY_NAME) .
@echo "Binary available at: ./$(BINARY_NAME)"
test: ## Run tests
@echo "Running tests..."
@go test ./...
test-verbose: ## Run tests with verbose output
@echo "Running tests (verbose)..."
@go test -v ./...
test-coverage: ## Run tests with coverage report
@echo "Running tests with coverage..."
@go test -coverprofile=coverage.out ./...
@go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report: coverage.html"
lint: ## Run linters (requires golangci-lint)
@echo "Running linters..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run; \
else \
echo "golangci-lint not found. Install it from: https://golangci-lint.run/"; \
exit 1; \
fi
fmt: ## Format code
@echo "Formatting code..."
@go fmt ./...
@if command -v goimports >/dev/null 2>&1; then \
goimports -w .; \
fi
clean: ## Remove build artifacts
@echo "Cleaning build artifacts..."
@rm -rf dist/
@rm -f $(BINARY_NAME)
@rm -f coverage.out coverage.html
@echo "Clean complete"
install: build-quick ## Install binary to $GOPATH/bin
@echo "Installing $(BINARY_NAME)..."
@go install $(GO_BUILD_FLAGS) .
@echo "Installed to: $$(go env GOPATH)/bin/$(BINARY_NAME)"
deps: ## Download and verify dependencies
@echo "Downloading dependencies..."
@go mod download
@go mod verify
@echo "Dependencies ready"
tidy: ## Tidy go.mod and go.sum
@echo "Tidying dependencies..."
@go mod tidy
check-goreleaser: ## Check if goreleaser is installed
@if ! command -v goreleaser >/dev/null 2>&1; then \
echo "Error: goreleaser is not installed"; \
echo ""; \
echo "Install goreleaser:"; \
echo " brew install goreleaser/tap/goreleaser # macOS"; \
echo " go install github.com/goreleaser/goreleaser@latest"; \
echo ""; \
echo "Or visit: https://goreleaser.com/install/"; \
exit 1; \
fi
version: ## Show version information
@echo "Version: $(VERSION)"
@echo "Commit: $(COMMIT)"
@echo "Date: $(DATE)"
run: build-quick ## Build and run the binary
@./$(BINARY_NAME)
dev: ## Build and install for development, then show version
@$(MAKE) install
@$(BINARY_NAME) version 2>/dev/null || echo "Note: 'pup version' command not yet implemented"
validate: ## Run all validation checks (test, lint, build)
@echo "Running validation checks..."
@$(MAKE) test
@$(MAKE) lint
@$(MAKE) build-quick
@echo "✓ All validation checks passed"
release-test: check-goreleaser ## Test release process without publishing (requires clean git state)
@echo "Testing release process..."
@if [ -n "$$(git status --porcelain)" ]; then \
echo "Error: working directory is not clean. Commit or stash changes first."; \
exit 1; \
fi
@goreleaser release --snapshot --clean --skip=publish
@echo "✓ Release test successful. Artifacts in dist/"
.PHONY: help build build-all build-snapshot build-quick test test-verbose test-coverage lint fmt clean install deps tidy check-goreleaser version run dev validate release-test