-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
90 lines (71 loc) · 2.53 KB
/
Makefile
File metadata and controls
90 lines (71 loc) · 2.53 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
# Makefile to build the project and place the binary in the dist/ directory
# Build command with common flags
BUILD_CMD = CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -tags=prod
PACKAGE = ./backup/main.go
COVERAGE_THRESHOLD = 98
.PHONY: build clean test test-integration lint tidy release sanity-check check-mod-tidy lint-config-check lint-fix format check-clean check-coverage
format:
go fmt ./...
@echo "OK: Code formatted."
lint-config-check:
@golangci-lint config path
@golangci-lint config verify
@echo "OK: Lint configuration is valid."
lint:
golangci-lint run ./...
lint-fix:
golangci-lint run --fix ./...
check-clean:
@git diff --quiet || (echo "ERROR: Working directory has uncommitted changes." && exit 1)
@echo "OK: Working directory is clean."
check-mod-tidy:
go mod tidy -diff
@echo "OK: No untidy module files detected."
sanity-check: format check-clean check-mod-tidy
@echo "OK: All sanity checks passed."
test:
go test -race ./... -v
test-integration:
go test -race -tags=integration ./... -v
tidy:
gofmt -s -w .
go mod tidy
build:
@mkdir -p dist
$(BUILD_CMD) -o dist/backup $(PACKAGE)
clean:
rm -rf dist
# Build for specific OS and architecture (e.g., make release-linux-amd64)
release-%:
@mkdir -p dist
GOOS=$(word 1,$(subst -, ,$*)) GOARCH=$(word 2,$(subst -, ,$*)) $(BUILD_CMD) -o dist/backup-$* $(PACKAGE)
release: release-linux-amd64 release-darwin-amd64 release-windows-amd64
@echo
@echo "Binaries with sizes:"
@for file in dist/*; do \
if [ -f "$$file" ]; then \
size=$$(stat --printf="%s" "$$file"); \
printf "%-40s Size: %s bytes\n" "$$file" "$$size"; \
fi; \
done
report-size: build
go install github.com/Zxilly/go-size-analyzer/cmd/gsa@latest
gsa --web --listen=":8910" --open dist/backup
check-coverage:
@go test ./... -count=1 -coverprofile=/tmp/coverage.out -coverpkg=./backup/...
@COVERAGE=$$(go tool cover -func=/tmp/coverage.out | grep '^total:' | awk '{print int($$3)}'); \
echo "Total coverage: $${COVERAGE}%"; \
if [ "$${COVERAGE}" -lt "$(COVERAGE_THRESHOLD)" ]; then \
echo "FAIL: Coverage $${COVERAGE}% is below threshold $(COVERAGE_THRESHOLD)%"; \
exit 1; \
else \
echo "OK: Coverage $${COVERAGE}% meets threshold $(COVERAGE_THRESHOLD)%"; \
fi
report-coverage:
@mkdir -p coverage
@go test ./... -count=1 -coverprofile=coverage/coverage.out -coverpkg=./backup/...
@echo
@echo "Coverage Summary:"
@go tool cover -func=coverage/coverage.out
@go tool cover -html=coverage/coverage.out -o coverage/coverage.html
@echo "Coverage report generated at coverage/coverage.html"