-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
144 lines (123 loc) · 5.27 KB
/
Copy pathMakefile
File metadata and controls
144 lines (123 loc) · 5.27 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
.PHONY: build generate clean run test test-verbose test-quick test-coverage test-coverage-open \
check-race 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 ./...
# Race detector on unit tests (same gate as the CI "race" job)
check-race:
go test -short -race ./...
# 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 and docs/system_variables.md reference table
# go-flags uses ioctl(TIOCGWINSZ) for terminal width, so capture help through a PTY.
docs-update:
@echo "Updating help output for README.md..."
@mkdir -p tmp
@go tool ptyhelp patch -file README.md -marker readme-help -cols 120 -o tmp/help_clean.txt -normalize-eol=lf -- go run . --help
@go tool ptyhelp patch -file README.md -marker statement-help -fence=none -o tmp/statement_help.txt -- go run . --statement-help
@echo "Updating system variables reference for docs/system_variables.md..."
@go tool ptyhelp patch -file docs/system_variables.md -marker sysvars-help -fence=none -o tmp/sysvars_help.txt -- go run . --sysvars-help
@echo "Generated files:"
@echo " - tmp/help_clean.txt: --help output for README.md"
@echo " - tmp/statement_help.txt: --statement-help output for README.md"
@echo " - tmp/sysvars_help.txt: --sysvars-help output for docs/system_variables.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 check-race - Run unit tests with race detector (same as CI race job)"
@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 and docs/system_variables.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"