-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
35 lines (29 loc) · 1.12 KB
/
Makefile
File metadata and controls
35 lines (29 loc) · 1.12 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
MIN_TEST_COVERAGE := 90
all: dep lint test-coverage ## Run dep, lint and test
dep: ## Get project dependencies
@echo "Getting project dependencies..."
@go mod tidy
lint: ## Lint all Golang files
@echo "Linting all Go files..."
@go vet ./...
test: ## Run all tests
@echo "Running all tests..."
@go test -race ./...
test-coverage: ## Run tests with coverage check. Fails if coverage is below the threshold.
@echo "Running tests with coverage check..."
@trap 'rm -f coverage.txt' EXIT; \
go test -race -coverprofile=coverage.txt ./...; \
if [ $$? -ne 0 ]; then \
echo "Test failed. Exiting."; \
exit 1; \
fi; \
result=$$(go tool cover -func=coverage.txt | grep -oP 'total:\s+\(statements\)\s+\K\d+' || echo "0"); \
if [ $$result -eq 0 ]; then \
echo "No test coverage information available."; \
exit 0; \
elif [ $$result -lt $(MIN_TEST_COVERAGE) ]; then \
echo "FAIL: Coverage $$result% is less than the minimum $(MIN_TEST_COVERAGE)%"; \
exit 1; \
fi
help: ## Display this help message
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'