|
| 1 | +.PHONY: help build run test test-race lint clean deps tidy docs site release snapshot install |
| 2 | + |
| 3 | +# Default target |
| 4 | +.DEFAULT_GOAL := help |
| 5 | + |
| 6 | +# Variables |
| 7 | +BINARY_NAME=devtui |
| 8 | +VERSION?=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev") |
| 9 | +COMMIT?=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown") |
| 10 | +DATE?=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ") |
| 11 | +LDFLAGS=-ldflags "-X github.com/skatkov/devtui/cmd.version=$(VERSION) -X github.com/skatkov/devtui/cmd.commit=$(COMMIT) -X github.com/skatkov/devtui/cmd.date=$(DATE)" |
| 12 | + |
| 13 | +help: ## Display this help message |
| 14 | + @echo "DevTUI - Development targets:" |
| 15 | + @echo "" |
| 16 | + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}' |
| 17 | + @echo "" |
| 18 | + |
| 19 | +build: ## Build the project |
| 20 | + @echo "Building $(BINARY_NAME)..." |
| 21 | + go build -v $(LDFLAGS) -o $(BINARY_NAME) . |
| 22 | + @echo "Build complete: ./$(BINARY_NAME)" |
| 23 | + |
| 24 | +run: ## Run the TUI (main mode) |
| 25 | + @echo "Running DevTUI..." |
| 26 | + go run $(LDFLAGS) main.go |
| 27 | + |
| 28 | +test: ## Run all tests |
| 29 | + @echo "Running tests..." |
| 30 | + go test -v -failfast ./... |
| 31 | + |
| 32 | +test-race: ## Run tests with race detection (what CI uses) |
| 33 | + @echo "Running tests with race detection..." |
| 34 | + go test -v -failfast -race ./... |
| 35 | + |
| 36 | +test-coverage: ## Run tests with coverage report |
| 37 | + @echo "Running tests with coverage..." |
| 38 | + go test -coverprofile=coverage.txt ./... |
| 39 | + go tool cover -html=coverage.txt |
| 40 | + |
| 41 | +lint: ## Run golangci-lint |
| 42 | + @echo "Running linters..." |
| 43 | + golangci-lint run |
| 44 | + |
| 45 | +fmt: ## Format code with gofumpt and goimports |
| 46 | + @echo "Formatting code..." |
| 47 | + golangci-lint run --fix |
| 48 | + |
| 49 | +vet: ## Run go vet |
| 50 | + @echo "Running go vet..." |
| 51 | + go vet ./... |
| 52 | + |
| 53 | +check: lint test-race ## Run linters and tests with race detection |
| 54 | + |
| 55 | +docs: ## Generate CLI and TUI documentation for the website |
| 56 | + @echo "Generating documentation..." |
| 57 | + cd docs && go run *.go |
| 58 | + @echo "Documentation generated in site/" |
| 59 | + |
| 60 | +site: docs ## Alias for docs target |
| 61 | + |
| 62 | +clean: ## Clean build artifacts |
| 63 | + @echo "Cleaning..." |
| 64 | + rm -f $(BINARY_NAME) |
| 65 | + rm -f coverage.txt |
| 66 | + rm -rf dist/ |
| 67 | + @echo "Clean complete" |
| 68 | + |
| 69 | +deps: ## Download dependencies |
| 70 | + @echo "Downloading dependencies..." |
| 71 | + go mod download |
| 72 | + |
| 73 | +tidy: ## Run go mod tidy to clean up dependencies |
| 74 | + @echo "Tidying dependencies..." |
| 75 | + go mod tidy |
| 76 | + @echo "Dependencies tidied" |
| 77 | + |
| 78 | +update-deps: ## Update all dependencies to latest versions |
| 79 | + @echo "Updating dependencies..." |
| 80 | + go get -u ./... |
| 81 | + go mod tidy |
| 82 | + @echo "Dependencies updated" |
| 83 | + |
| 84 | +generate: ## Run go generate |
| 85 | + @echo "Running go generate..." |
| 86 | + go generate ./... |
| 87 | + |
| 88 | +release: ## Build release with goreleaser (creates binaries for all platforms) |
| 89 | + @echo "Building release with goreleaser..." |
| 90 | + goreleaser release --clean |
| 91 | + |
| 92 | +snapshot: ## Build snapshot release with goreleaser (no publish) |
| 93 | + @echo "Building snapshot release..." |
| 94 | + goreleaser release --snapshot --clean |
| 95 | + @echo "Snapshot built in dist/" |
| 96 | + |
| 97 | +install: build ## Build and install to GOPATH/bin |
| 98 | + @echo "Installing $(BINARY_NAME) to $(GOPATH)/bin..." |
| 99 | + go install $(LDFLAGS) . |
| 100 | + @echo "Installed: $(shell which $(BINARY_NAME))" |
| 101 | + |
| 102 | +verify: generate tidy ## Verify go generate and go mod tidy don't create changes |
| 103 | + @if [ -n "$$(git status --porcelain)" ]; then \ |
| 104 | + echo "Error: git status is not clean after generate and tidy"; \ |
| 105 | + git status --porcelain; \ |
| 106 | + exit 1; \ |
| 107 | + fi |
| 108 | + @echo "Verification passed" |
| 109 | + |
| 110 | +all: clean generate tidy build test lint ## Run all checks and build |
| 111 | + @echo "All tasks complete" |
0 commit comments