-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
131 lines (107 loc) · 4.29 KB
/
Makefile
File metadata and controls
131 lines (107 loc) · 4.29 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
GO ?= go
PKG := github.com/censys/cencli
BUILD_DIR ?= bin
BINARY ?= censys
ifeq ($(OS),Windows_NT)
BINARY := $(BINARY).exe
endif
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo none)
DATE ?= $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
LDFLAGS := -s -w -X $(PKG)/internal/version.Version=$(VERSION) -X $(PKG)/internal/version.Commit=$(COMMIT) -X $(PKG)/internal/version.Date=$(DATE)
# Pinned tool versions (override via env)
SQLC_VERSION ?= v1.30.0
GOIMPORTS_VERSION ?= v0.25.0
MOCKGEN_VERSION ?= v0.6.0
GOLANGCI_LINT_VERSION ?= v1.64.8
STATICCHECK_VERSION ?= 2025.1.1
# Packages to include in coverage (exclude generated mocks)
PKGS := $(shell $(GO) list ./... | grep -vE 'gen/*')
$(BINARY):
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=0 $(GO) build -ldflags '$(LDFLAGS)' -o $(BUILD_DIR)/$(BINARY) cmd/cencli/main.go
clean:
rm -f $(BUILD_DIR)/$(BINARY)
build: clean $(BINARY)
all: fmt lint build test
tools:
go install github.com/sqlc-dev/sqlc/cmd/sqlc@$(SQLC_VERSION)
go install golang.org/x/tools/cmd/goimports@$(GOIMPORTS_VERSION)
go install go.uber.org/mock/mockgen@$(MOCKGEN_VERSION)
go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
go install honnef.co/go/tools/cmd/staticcheck@$(STATICCHECK_VERSION)
sqlc:
cd internal/store/db && sqlc generate
mocks:
@echo "Generating mocks using go:generate directives..."
go generate ./internal/...
fmt:
$(GO) fmt ./...
goimports -w .
vet:
$(GO) vet ./...
lint:
golangci-lint run --timeout=5m
test: mocks
$(GO) test ./...
test-race: mocks
$(GO) test -race ./...
cover:
$(GO) test -cover $(PKGS)
cover-html:
$(GO) test -coverprofile=coverage.out $(PKGS) && $(GO) tool cover -html=coverage.out -o coverage.html
# Check if current coverage meets the threshold
cover-check:
@echo "🔍 Checking coverage against threshold..."
@$(GO) test -coverprofile=coverage.out -covermode=atomic $(PKGS) > /dev/null 2>&1
@if [ -f ci/coverage_min_percent ]; then \
MIN=$$(cat ci/coverage_min_percent); \
else \
MIN=30; \
fi; \
$(GO) tool cover -func=coverage.out | awk -v min="$$MIN" '/^total:/ { \
pct = substr($$3, 1, length($$3)-1); \
print "📊 Coverage: " pct "% (minimum: " min "%)"; \
if (pct < min) { \
print "❌ Coverage below threshold"; \
exit 1; \
} \
print "✅ Coverage check passed"; \
}'
# Update the coverage threshold to current coverage (use with caution!)
cover-update-threshold:
@echo "📈 Updating coverage threshold to current coverage..."
@$(GO) test -coverprofile=coverage.out -covermode=atomic ./... > /dev/null 2>&1
@COVERAGE=$$($(GO) tool cover -func=coverage.out | awk '/^total:/ {print int(substr($$3, 1, length($$3)-1))}'); \
echo "$$COVERAGE" > ci/coverage_min_percent; \
echo "✅ Updated threshold to $$COVERAGE%"
# Show current coverage stats
cover-report:
@$(GO) test -coverprofile=coverage.out -covermode=atomic $(PKGS) > /dev/null 2>&1
@echo "📊 Coverage Report:"
@echo "===================="
@$(GO) tool cover -func=coverage.out | grep -E "(^github.com/censys/cencli/internal/|^total:)" | \
awk '{if ($$1 == "total:") print "\n" $$0; else print $$0}' | \
sort -t: -k3 -rn | head -20
@echo ""
@echo "Threshold: $$(cat ci/coverage_min_percent 2>/dev/null || echo "0")%"
e2e-setup:
@cp internal/config/templates/* cmd/cencli/e2e/fixtures/templates/
e2e: e2e-setup $(BINARY)
$(GO) test -v ./cmd/cencli/e2e
# Run E2E tests with environment variables from .env
# To run a specific fixture, use: make e2e-with-env FIXTURE=view/host-basic
# To run all fixtures for a command, use: make e2e-with-env FIXTURE=view/help
e2e-with-env: e2e-setup $(BINARY)
@if [ -n "$(FIXTURE)" ]; then \
echo "Running E2E test for fixture: $(FIXTURE)"; \
godotenv -f .env bash -c 'CENCLI_ENABLE_E2E_TESTS=true $(GO) test -v ./cmd/cencli/e2e -run TestE2E/$(FIXTURE)'; \
else \
godotenv -f .env bash -c 'CENCLI_ENABLE_E2E_TESTS=true $(GO) test -v ./cmd/cencli/e2e'; \
fi
completions: $(BINARY)
@echo "Generating completions..."
@mkdir -p completions
$(BUILD_DIR)/$(BINARY) completion bash > completions/censys.bash
$(BUILD_DIR)/$(BINARY) completion zsh > completions/_censys
.PHONY: all clean $(BINARY) tools sqlc fmt vet lint test test-race cover cover-html cover-check cover-update-threshold cover-report e2e mocks completions