|
1 | | -.PHONY: help test lint security coverage benchmark clean fmt verify tools ci |
| 1 | +.PHONY: help test lint security coverage benchmark clean fmt verify tools ci license check-license |
2 | 2 |
|
3 | 3 | # Default target |
4 | 4 | help: |
5 | 5 | @echo "Available targets:" |
6 | | - @echo " test - Run all tests" |
7 | | - @echo " lint - Run linters (golangci-lint with gosec)" |
8 | | - @echo " security - Run vulnerability check (govulncheck)" |
9 | | - @echo " coverage - Run tests with coverage report" |
10 | | - @echo " benchmark - Run benchmarks" |
11 | | - @echo " clean - Clean build artifacts" |
12 | | - @echo " fmt - Format code" |
13 | | - @echo " verify - Run all checks (test, lint, security)" |
14 | | - @echo " tools - Install development tools" |
15 | | - @echo " ci - Run CI pipeline checks" |
| 6 | + @echo " test - Run all tests" |
| 7 | + @echo " lint - Run linters (golangci-lint with gosec)" |
| 8 | + @echo " security - Run vulnerability check (govulncheck)" |
| 9 | + @echo " coverage - Run tests with coverage report" |
| 10 | + @echo " benchmark - Run benchmarks" |
| 11 | + @echo " clean - Clean build artifacts" |
| 12 | + @echo " fmt - Format code" |
| 13 | + @echo " license - Add license headers to all Go files" |
| 14 | + @echo " check-license - Verify license headers are present" |
| 15 | + @echo " verify - Run all checks (test, lint, security, license)" |
| 16 | + @echo " tools - Install development tools" |
| 17 | + @echo " ci - Run CI pipeline checks (test, lint, security, license)" |
16 | 18 |
|
17 | 19 | # Run tests |
18 | 20 | test: |
|
60 | 62 | gofmt -s -w . |
61 | 63 |
|
62 | 64 | # Run all checks |
63 | | -verify: fmt test lint security |
| 65 | +verify: fmt test lint security check-license |
64 | 66 | @echo "All checks passed!" |
65 | 67 |
|
66 | 68 | # Install development tools |
67 | 69 | tools: |
68 | 70 | @echo "Installing development tools..." |
69 | | - go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest |
70 | | - go install golang.org/x/vuln/cmd/govulncheck@latest |
| 71 | + go install github.com/golangci/golangci-lint/cmd/ [email protected] |
| 72 | + go install golang.org/x/vuln/cmd/ [email protected] |
| 73 | + go install github.com/google/ [email protected] |
| 74 | + |
| 75 | +# Add license headers to all Go files |
| 76 | +# Uses Google's addlicense tool (github.com/google/addlicense) |
| 77 | +# Adds MPL-2.0 + SPDX headers with your name as copyright holder |
| 78 | +# Existing headers are preserved (no re-processing) |
| 79 | +# Note: Requires addlicense in PATH or ~/go/bin - install with 'make tools' |
| 80 | +license: |
| 81 | + @echo "Adding license headers to Go files..." |
| 82 | + @if [ -z "$(HOME)" ] || [ ! -d "$(HOME)" ]; then \ |
| 83 | + echo "Error: Invalid HOME directory (required for ~/go/bin tool installation)"; \ |
| 84 | + echo " If running in Docker/container, ensure HOME is set and ~/go/bin exists"; exit 1; \ |
| 85 | + fi |
| 86 | + @PATH="$(HOME)/go/bin:$$PATH" && \ |
| 87 | + command -v addlicense >/dev/null 2>&1 || { echo "Error: addlicense not found. Install with: make tools"; exit 1; } && \ |
| 88 | + find . -name "*.go" -not -path "./vendor/*" -not -path "./examples/*" -print0 | \ |
| 89 | + xargs -0 addlicense -c "Daniel Schmidt" -l mpl -s=only -y 2025 -v |
| 90 | + @echo "License header addition complete!" |
| 91 | + |
| 92 | +# Check that all Go files have license headers |
| 93 | +# Uses addlicense in check mode - accepts ANY copyright holder name |
| 94 | +# Only verifies that MPL-2.0 + SPDX headers exist |
| 95 | +# Note: Requires addlicense in PATH or ~/go/bin - install with 'make tools' |
| 96 | +check-license: |
| 97 | + @echo "Checking license headers..." |
| 98 | + @if [ -z "$(HOME)" ] || [ ! -d "$(HOME)" ]; then \ |
| 99 | + echo "Error: Invalid HOME directory (required for ~/go/bin tool installation)"; \ |
| 100 | + echo " If running in Docker/container, ensure HOME is set and ~/go/bin exists"; exit 1; \ |
| 101 | + fi |
| 102 | + @PATH="$(HOME)/go/bin:$$PATH" && \ |
| 103 | + command -v addlicense >/dev/null 2>&1 || { echo "Error: addlicense not found. Install with: make tools"; exit 1; } && \ |
| 104 | + find . -name "*.go" -not -path "./vendor/*" -not -path "./examples/*" -print0 | \ |
| 105 | + if xargs -0 addlicense -check -l mpl -s=only -y 2025; then \ |
| 106 | + echo "✓ All Go files have license headers!"; \ |
| 107 | + else \ |
| 108 | + echo "✗ Some files are missing license headers. Run 'make license' to add them."; exit 1; \ |
| 109 | + fi |
71 | 110 |
|
72 | 111 | # CI pipeline checks (used in GitHub Actions) |
73 | | -ci: test lint security |
| 112 | +ci: test lint security check-license |
74 | 113 | @echo "CI checks passed!" |
0 commit comments