-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
130 lines (107 loc) · 4.83 KB
/
Copy pathMakefile
File metadata and controls
130 lines (107 loc) · 4.83 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
# The commands used in this Makefile expect to be interpreted by bash.
# Adapted from Funnel's Makefile:
# https://github.com/ohsu-comp-bio/funnel/blob/master/Makefile
SHELL := /bin/bash
TESTS=$(shell go list ./... | grep -v /vendor/)
git_commit := $(shell git rev-parse --short HEAD)
git_branch := $(shell git symbolic-ref -q --short HEAD)
git_upstream := $(shell git config --get remote.origin.url)
export GIT_BRANCH = $(git_branch)
export GIT_UPSTREAM = $(git_upstream)
# Determine if the current commit has a tag
git_tag := $(shell git describe --tags --exact-match --abbrev=0 2>/dev/null)
ifeq ($(git_tag),)
version := unknown
else
version := $(git_tag)
endif
VERSION_LDFLAGS=\
-X "github.com/calypr/git-drs/version.BuildDate=$(shell date)" \
-X "github.com/calypr/git-drs/version.GitCommit=$(git_commit)" \
-X "github.com/calypr/git-drs/version.GitBranch=$(git_branch)" \
-X "github.com/calypr/git-drs/version.GitUpstream=$(git_upstream)" \
-X "github.com/calypr/git-drs/version.Version=$(version)"
export CGO_ENABLED=0
# Build the code
install:
@go install -ldflags '$(VERSION_LDFLAGS)' .
# Build the code
build:
@go build -ldflags '$(VERSION_LDFLAGS)' -buildvcs=false .
lint-depends:
go install golang.org/x/tools/cmd/goimports@latest
go install github.com/client9/misspell/cmd/misspell@latest
# Run code style and other checks
# Note: Using native Go tools instead of golangci-lint for Go 1.24 compatibility
lint:
@echo "Running go vet..."
@go vet ./...
@echo "Running gofmt..."
@files="$$(gofmt -s -l cmd/ internal/ tests/ git-drs.go)"; \
if [ -n "$$files" ]; then \
printf "%s\n" "$$files"; \
echo "Please run: gofmt -s -w cmd/ internal/ tests/ git-drs.go"; \
exit 1; \
fi
@echo "Running goimports..."
@files="$$(goimports -l cmd/ internal/ tests/ git-drs.go)"; \
if [ -n "$$files" ]; then \
printf "%s\n" "$$files"; \
echo "Please run: goimports -w cmd/ internal/ tests/ git-drs.go"; \
exit 1; \
fi
@echo "Running misspell..."
@misspell -error cmd/ internal/ tests/ docs/ *.go *.md Makefile
@echo "✅ All lint checks passed!"
# Auto-fix formatting issues
fmt:
@echo "Formatting with gofmt..."
@gofmt -s -w cmd/ internal/ tests/ git-drs.go
@echo "Formatting with goimports..."
@goimports -w cmd/ internal/ tests/ git-drs.go
@echo "✅ Formatting complete!"
# Run all tests
test:
@go test $(TESTS)
test-verbose:
@go test -v $(TESTS)
# Run tests with coverage
test-coverage:
@pkgs="$$(GOTOOLCHAIN=auto go list -f '{{if or (gt (len .TestGoFiles) 0) (gt (len .XTestGoFiles) 0)}}{{.ImportPath}}{{end}}' ./... | sed '/^$$/d')"; \
if [ -z "$$pkgs" ]; then echo "error: no test packages discovered for coverage" >&2; exit 1; fi; \
GOCOVERDIR= go test -v -race -coverprofile=coverage.out -covermode=atomic $$pkgs
@GOCOVERDIR= go tool cover -func=coverage.out | tail -1
# Run full repo coverage and store artifacts in coverage/
coverage:
@mkdir -p coverage
@pkgs="$$(GOTOOLCHAIN=auto go list -f '{{if or (gt (len .TestGoFiles) 0) (gt (len .XTestGoFiles) 0)}}{{.ImportPath}}{{end}}' ./... | sed '/^$$/d')"; \
if [ -z "$$pkgs" ]; then echo "error: no test packages discovered for coverage" >&2; exit 1; fi; \
GOCOVERDIR= GOTOOLCHAIN=auto go test $$pkgs -coverprofile=coverage/combined.out -covermode=atomic
@GOCOVERDIR= GOTOOLCHAIN=auto go tool cover -func=coverage/combined.out | tee coverage/summary.txt | tail -1
@echo "Coverage profile: coverage/combined.out"
@echo "Coverage summary: coverage/summary.txt"
# Focused coverage for highest-risk client paths
coverage-clients:
@mkdir -p coverage
@GOCOVERDIR= GOTOOLCHAIN=auto go test ./client/drs ./client/local -coverprofile=coverage/clients.out -covermode=atomic
@GOCOVERDIR= GOTOOLCHAIN=auto go tool cover -func=coverage/clients.out | tee coverage/clients_summary.txt | tail -1
@echo "Coverage profile: coverage/clients.out"
@echo "Coverage summary: coverage/clients_summary.txt"
# Generate HTML coverage report
coverage-html: test-coverage
@GOCOVERDIR= go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
@echo "Open it with: open coverage.html (macOS) or xdg-open coverage.html (Linux)"
coverage-html-full: coverage
@GOCOVERDIR= GOTOOLCHAIN=auto go tool cover -html=coverage/combined.out -o coverage/combined.html
@echo "Coverage report generated: coverage/combined.html"
@echo "Open it with: open coverage/combined.html (macOS) or xdg-open coverage/combined.html (Linux)"
# View coverage in browser
coverage-view: coverage-html
@open coverage.html || xdg-open coverage.html || echo "Please open coverage.html manually"
# Make everything usually needed to prepare for a pull request
full: proto install tidy lint test website webdash
# Remove build/development files.
clean:
@rm -rf ./bin ./pkg ./test_tmp ./build ./buildtools
.PHONY: proto proto-lint website docker webdash build debug coverage coverage-clients coverage-html-full test install