-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
142 lines (122 loc) · 4.86 KB
/
Makefile
File metadata and controls
142 lines (122 loc) · 4.86 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
.PHONY: build generate clean run test test-verbose test-quick test-coverage test-coverage-open \
lint fmt fmt-check check all all-quick docs-update help-dev \
worktree-setup worktree-list worktree-delete
build:
go build
generate:
go generate ./...
clean:
rm -f spanner-mycli
rm -rf dist/
go clean -testcache
run:
./spanner-mycli -p ${PROJECT} -i ${INSTANCE} -d ${DATABASE}
test:
go test ./...
test-verbose:
go test -v ./...
# Quick tests for development cycle
test-quick:
go test -short ./...
# Test with coverage profile
test-coverage:
@mkdir -p tmp
@echo "Running tests with coverage..."
@go test -coverpkg=./... ./... -coverprofile=tmp/coverage.out.tmp
@echo "Excluding generated files from coverage..."
@grep -E -v '(_enumer\.go|enums/.*_enumer\.go)' tmp/coverage.out.tmp > tmp/coverage.out || true
@rm -f tmp/coverage.out.tmp
@echo "Generating coverage report..."
@go tool cover -html=tmp/coverage.out -o tmp/coverage.html
@echo "Coverage summary:"
@go tool cover -func=tmp/coverage.out | tail -1
@echo "Coverage report generated: tmp/coverage.html"
# Open coverage report in browser
test-coverage-open: test-coverage
@if command -v open >/dev/null 2>&1; then \
open tmp/coverage.html; \
elif command -v xdg-open >/dev/null 2>&1; then \
xdg-open tmp/coverage.html; \
else \
echo "Please open tmp/coverage.html manually"; \
fi
lint:
golangci-lint run
fmt:
@echo "Formatting code..."
golangci-lint fmt .
@echo "Code formatted successfully"
fmt-check:
@echo "Checking code formatting..."
@if golangci-lint fmt --diff . | grep -q "^diff"; then \
echo "Code formatting issues found. Run 'make fmt' to fix."; \
golangci-lint fmt --diff . | head -100; \
exit 1; \
else \
echo "Code formatting is correct"; \
fi
# Combined test, lint, and format check (required before push)
check: test lint fmt-check
# All development tasks with formatting (destructive)
all: fmt check
# Quick development cycle with formatting (destructive)
all-quick: fmt test-quick lint
# Update README.md help sections
# Note: go-flags uses ioctl(TIOCGWINSZ) for terminal width, ignoring COLUMNS env var.
# script(1) creates a PTY so stty can set the width. macOS syntax; Linux differs.
docs-update:
@echo "Updating help output for README.md..."
@mkdir -p tmp
@script -q tmp/help_output.txt sh -c "stty cols 200; go run . --help"
@sed -n '/Usage:/,$$p' tmp/help_output.txt | sed '1s/.*Usage:/Usage:/' > tmp/help_clean.txt; \
if [ ! -s tmp/help_clean.txt ]; then \
echo "ERROR: 'Usage:' not found in help output" >&2; \
exit 1; \
fi
@go run . --statement-help > tmp/statement_help.txt
@echo "Generated files:"
@echo " - tmp/help_clean.txt: --help output for README.md"
@echo " - tmp/statement_help.txt: --statement-help output for README.md"
# Show development help
help-dev:
@echo "Development Commands:"
@echo " make build - Build the application"
@echo " make test - Run full test suite (required before push)"
@echo " make test-coverage - Run tests with coverage report"
@echo " make test-coverage-open - Run coverage and open HTML report in browser"
@echo " make test-quick - Run quick tests (go test -short)"
@echo " make lint - Run linter (required before push)"
@echo " make fmt - Format code (modifies files)"
@echo " make fmt-check - Check if code is properly formatted"
@echo " make check - Run test && lint && fmt-check (required before push)"
@echo " make all - Run fmt && check (modifies files)"
@echo " make all-quick - Run fmt && test-quick && lint (modifies files)"
@echo " make clean - Clean build artifacts and test cache"
@echo " make run - Run with PROJECT/INSTANCE/DATABASE env vars"
@echo " make docs-update - Generate help output for README.md"
@echo " make worktree-setup - Setup phantom worktree (requires WORKTREE_NAME)"
@echo " make worktree-list - List existing phantom worktrees"
@echo " make worktree-delete - Delete phantom worktree (requires WORKTREE_NAME)"
# Phantom worktree management
worktree-setup:
@if [ -z "$(WORKTREE_NAME)" ]; then \
echo "WORKTREE_NAME required. Usage: make worktree-setup WORKTREE_NAME=issue-123-feature"; \
exit 1; \
fi
@echo "Creating phantom worktree: $(WORKTREE_NAME)"
@git fetch origin
@phantom create $(WORKTREE_NAME) --base origin/main
@echo "Worktree created successfully!"
@echo "Next: phantom shell $(WORKTREE_NAME) --tmux-horizontal"
worktree-list:
@phantom list
worktree-delete:
@if [ -z "$(WORKTREE_NAME)" ]; then \
echo "WORKTREE_NAME required. Usage: make worktree-delete WORKTREE_NAME=issue-123-feature"; \
exit 1; \
fi
@echo "Checking status of worktree: $(WORKTREE_NAME)"
@phantom exec $(WORKTREE_NAME) git status --porcelain
@echo "Deleting worktree: $(WORKTREE_NAME)"
@phantom delete $(WORKTREE_NAME)
@echo "Worktree deleted successfully"