forked from Dicklesworthstone/ntm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
146 lines (123 loc) · 4.38 KB
/
Makefile
File metadata and controls
146 lines (123 loc) · 4.38 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
# NTM - Named Tmux Manager
# https://github.com/Dicklesworthstone/ntm
BINARY_NAME := ntm
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
BUILD_TIME := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS := -ldflags "-s -w -X github.com/Dicklesworthstone/ntm/internal/cli.Version=$(VERSION)"
GO := go
GOFLAGS := -trimpath
# Output directory
DIST := dist
.PHONY: all build clean install test test-short test-all test-e2e lint fmt help pre-commit upgrade-contract
all: build
## Build for current platform
build:
$(GO) build $(GOFLAGS) $(LDFLAGS) -o $(BINARY_NAME) ./cmd/ntm
## Build for all platforms
build-all: clean
@mkdir -p $(DIST)
GOOS=darwin GOARCH=amd64 $(GO) build $(GOFLAGS) $(LDFLAGS) -o $(DIST)/$(BINARY_NAME)-darwin-amd64 ./cmd/ntm
GOOS=darwin GOARCH=arm64 $(GO) build $(GOFLAGS) $(LDFLAGS) -o $(DIST)/$(BINARY_NAME)-darwin-arm64 ./cmd/ntm
GOOS=linux GOARCH=amd64 $(GO) build $(GOFLAGS) $(LDFLAGS) -o $(DIST)/$(BINARY_NAME)-linux-amd64 ./cmd/ntm
GOOS=linux GOARCH=arm64 $(GO) build $(GOFLAGS) $(LDFLAGS) -o $(DIST)/$(BINARY_NAME)-linux-arm64 ./cmd/ntm
@echo "Built binaries in $(DIST)/"
## Install to /usr/local/bin
install: build
install -m 755 $(BINARY_NAME) /usr/local/bin/$(BINARY_NAME)
@echo "Installed $(BINARY_NAME) to /usr/local/bin/"
@echo ""
@echo "Add to your shell rc file:"
@echo ' eval "$$(ntm shell zsh)" # for zsh'
@echo ' eval "$$(ntm shell bash)" # for bash'
## Install to user bin directory
install-user: build
@mkdir -p $(HOME)/.local/bin
install -m 755 $(BINARY_NAME) $(HOME)/.local/bin/$(BINARY_NAME)
@echo "Installed $(BINARY_NAME) to ~/.local/bin/"
@echo "Make sure ~/.local/bin is in your PATH"
## Uninstall
uninstall:
rm -f /usr/local/bin/$(BINARY_NAME)
rm -f $(HOME)/.local/bin/$(BINARY_NAME)
@echo "Uninstalled $(BINARY_NAME)"
## Run tests (fast, skips E2E)
test:
$(GO) test -v -short ./...
## Run all tests including E2E (requires agents)
test-all:
$(GO) test -v ./...
## Run E2E tests only (requires agents)
test-e2e:
$(GO) test -v ./e2e/...
## Validate upgrade asset naming contract
upgrade-contract:
@echo "Running upgrade contract tests..."
$(GO) test -v -run TestUpgradeAsset ./internal/cli/
## Pre-commit checks (run upgrade contract tests when relevant files are staged)
pre-commit:
@changed=$$(git diff --cached --name-only); \
if echo "$$changed" | grep -Eq '(^|/)(\.goreleaser\.yaml|internal/cli/upgrade.go|internal/cli/cli_test.go)$$'; then \
echo "Detected upgrade-related staged changes; running upgrade contract tests..."; \
$(GO) test -v -run TestUpgradeAsset ./internal/cli/; \
else \
echo "No upgrade-related staged changes detected; skipping upgrade contract tests."; \
fi
## Run tests with coverage
test-coverage:
$(GO) test -v -coverprofile=coverage.out ./...
$(GO) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report: coverage.html"
## Lint the code
lint:
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run; \
else \
echo "golangci-lint not installed. Run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"; \
fi
## Format code
fmt:
$(GO) fmt ./...
@if command -v goimports >/dev/null 2>&1; then \
goimports -w .; \
fi
## Clean build artifacts
clean:
rm -f $(BINARY_NAME)
rm -rf $(DIST)
rm -f coverage.out coverage.html
## Update dependencies
deps:
$(GO) mod download
$(GO) mod tidy
## Generate completions
completions:
@mkdir -p $(DIST)/completions
./$(BINARY_NAME) completion bash > $(DIST)/completions/ntm.bash
./$(BINARY_NAME) completion zsh > $(DIST)/completions/_ntm
./$(BINARY_NAME) completion fish > $(DIST)/completions/ntm.fish
@echo "Generated completions in $(DIST)/completions/"
## Show version
version:
@echo $(VERSION)
## Show help
help:
@echo "NTM - Named Tmux Manager"
@echo ""
@echo "Usage: make <target>"
@echo ""
@echo "Targets:"
@grep -E '^## ' $(MAKEFILE_LIST) | sed 's/## / /'
@echo ""
@echo "Build targets:"
@echo " build Build for current platform"
@echo " build-all Build for all platforms"
@echo " install Install to /usr/local/bin"
@echo " install-user Install to ~/.local/bin"
@echo ""
@echo "Development:"
@echo " test Run tests (fast, skips E2E)"
@echo " test-all Run all tests including E2E"
@echo " test-e2e Run E2E tests only (requires agents)"
@echo " lint Run linter"
@echo " fmt Format code"
@echo " clean Remove build artifacts"