-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
116 lines (102 loc) · 3.95 KB
/
Copy pathMakefile
File metadata and controls
116 lines (102 loc) · 3.95 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
# =============================================================================
# NFTBan v1.0.0 - Makefile
# =============================================================================
# SPDX-License-Identifier: MPL-2.0
# meta:name="Makefile"
# meta:type="config"
# meta:owner="Antonios Voulvoulis <contact@nftban.com>"
# meta:created_date="2025-01-07"
# meta:description="Build and development automation"
# meta:input="None"
# meta:output="Build artifacts"
# meta:depends=""
# meta:inventory.files=""
# meta:inventory.binaries="go, bash, shellcheck"
# meta:inventory.env_vars=""
# meta:inventory.config_files=""
# meta:inventory.systemd_units=""
# meta:inventory.network=""
# meta:inventory.privileges="none"
# =============================================================================
.PHONY: all build clean test fuzz fuzz-long lint lint-headers lint-shell lint-go install help
# Default target
all: build
# Build all Go binaries
build:
@echo "Building NFTBan..."
@./build.sh
# Clean build artifacts
clean:
@echo "Cleaning..."
@rm -rf bin/ dist/
@go clean -cache -testcache
# Run all tests
test:
@echo "Running tests..."
@go test ./...
@./tests/test_all_commands.sh 2>/dev/null || true
# Run fuzz tests (30 seconds per test)
fuzz:
@echo "Running fuzz tests..."
@go test -fuzz=FuzzParseLogLine -fuzztime=30s ./internal/parser/
@go test -fuzz=FuzzParseFeedLine -fuzztime=30s ./internal/parser/
@go test -fuzz=FuzzValidateAndNormalizeIP -fuzztime=30s ./internal/parser/
@echo "Fuzz tests completed."
# Run fuzz tests for longer duration (use for CI)
fuzz-long:
@echo "Running extended fuzz tests (5 minutes each)..."
@go test -fuzz=FuzzParseLogLine -fuzztime=5m ./internal/parser/
@go test -fuzz=FuzzSSHDetector -fuzztime=5m ./internal/parser/
@go test -fuzz=FuzzMailDetector -fuzztime=5m ./internal/parser/
@go test -fuzz=FuzzFTPDetector -fuzztime=5m ./internal/parser/
@go test -fuzz=FuzzPanelDetector -fuzztime=5m ./internal/parser/
@go test -fuzz=FuzzParseFeedLine -fuzztime=5m ./internal/parser/
@go test -fuzz=FuzzValidateAndNormalizeIP -fuzztime=5m ./internal/parser/
@go test -fuzz=FuzzParseBool -fuzztime=5m ./internal/parser/
@go test -fuzz=FuzzParseInt -fuzztime=5m ./internal/parser/
@go test -fuzz=FuzzParseDuration -fuzztime=5m ./internal/parser/
@echo "Extended fuzz tests completed."
# Run all linters
lint: lint-headers lint-shell lint-go
@echo "All linting passed."
# Validate file-header compliance
lint-headers:
@echo "Validating headers (per CONTRIBUTING.md File Headers)..."
@./tools/validate-headers.sh
# ShellCheck for Bash scripts
lint-shell:
@echo "Running ShellCheck..."
@find cli/ -name "*.sh" -type f -exec shellcheck --severity=warning {} + 2>/dev/null || true
@find tools/ -name "*.sh" -type f -exec shellcheck --severity=warning {} + 2>/dev/null || true
# Go static analysis
lint-go:
@echo "Running Go linters..."
@go fmt ./...
@go vet ./...
@staticcheck ./... 2>/dev/null || true
# Install pre-commit hooks
install-hooks:
@echo "Installing pre-commit hooks..."
@pip install pre-commit 2>/dev/null || pip3 install pre-commit
@pre-commit install
@echo "Pre-commit hooks installed."
# Install NFTBan
install:
@echo "Installing NFTBan..."
@sudo ./install.sh
# Help
help:
@echo "NFTBan Makefile Targets:"
@echo ""
@echo " make build - Build all Go binaries"
@echo " make clean - Clean build artifacts"
@echo " make test - Run all tests"
@echo " make fuzz - Run fuzz tests (30 seconds each)"
@echo " make fuzz-long - Run extended fuzz tests (5 minutes each)"
@echo " make lint - Run all linters (headers, shell, go)"
@echo " make lint-headers - Validate file-header compliance (per CONTRIBUTING.md)"
@echo " make lint-shell - Run ShellCheck on Bash scripts"
@echo " make lint-go - Run Go formatters and linters"
@echo " make install-hooks - Install pre-commit hooks"
@echo " make install - Install NFTBan (requires sudo)"
@echo " make help - Show this help"