@@ -23,10 +23,15 @@ DEFAULT_FASTLY_TEST_COMPUTE_SERVICE_ID = XsjdElScZGjmfCcTwsYRC1
23
23
FASTLY_TEST_NGWAF_WORKSPACE_ID ?=
24
24
DEFAULT_FASTLY_TEST_NGWAF_WORKSPACE_ID = Am2qjXkgamuYp3u54rQkLD
25
25
FASTLY_API_KEY ?=
26
- #
26
+
27
27
# Enables support for tools such as https://github.com/rakyll/gotest
28
28
TEST_COMMAND ?= $(GO ) test
29
29
30
+ # Tooling versions
31
+ GOLANGCI_LINT_VERSION = v2.4.0
32
+ BIN_DIR := $(CURDIR ) /bin
33
+ GOLANGCI_LINT := $(BIN_DIR ) /golangci-lint
34
+
30
35
all : mod-download tidy fmt lint test semgrep # # Runs all of the required cleaning and verification targets.
31
36
.PHONY : all
32
37
@@ -40,26 +45,53 @@ tidy: ## Cleans the Go module.
40
45
@$(GO ) mod tidy
41
46
.PHONY : tidy
42
47
43
- fmt : # # Properly formats Go files and orders dependencies.
48
+ install-linter : # # Installs golangci-lint v2.4.0 into ./bin (cross-platform)
49
+ @echo " ==> Installing golangci-lint $( GOLANGCI_LINT_VERSION) "
50
+ @mkdir -p $(BIN_DIR )
51
+ @if [ ! -x " $( GOLANGCI_LINT) " ]; then \
52
+ OS=$$(uname | tr '[:upper:]' '[:lower:]' ) ; \
53
+ ARCH=$$(uname -m ) ; \
54
+ case " $$ ARCH" in \
55
+ x86_64) ARCH=" amd64" ;; \
56
+ arm64| aarch64) ARCH=" arm64" ;; \
57
+ * ) echo " Unsupported architecture: $$ ARCH" && exit 1 ;; \
58
+ esac ; \
59
+ URL=" https://github.com/golangci/golangci-lint/releases/download/$( GOLANGCI_LINT_VERSION) /golangci-lint-$( GOLANGCI_LINT_VERSION) -$$ OS-$$ ARCH.tar.gz" ; \
60
+ echo " Downloading: $$ URL" ; \
61
+ curl -sSfL " $$ URL" | tar -xz -C $(BIN_DIR ) --strip-components=1; \
62
+ fi
63
+ .PHONY : install-linter
64
+
65
+ check-linter-version : # # Verifies installed golangci-lint version matches expected
66
+ @echo " ==> Checking golangci-lint version"
67
+ @EXPECTED=" $( GOLANGCI_LINT_VERSION) " ; \
68
+ INSTALLED=$$($(GOLANGCI_LINT ) version --format short | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+') ; \
69
+ if [ " $$ INSTALLED" != " $$ EXPECTED" ]; then \
70
+ echo " Expected golangci-lint $$ EXPECTED but found $$ INSTALLED" ; \
71
+ exit 1; \
72
+ fi
73
+ .PHONY : check-linter-version
74
+
75
+ fmt : install-linter # # Properly formats Go files and orders dependencies.
44
76
@echo " ==> Running golangci-lint fmt"
45
- @golangci-lint fmt
77
+ @$( GOLANGCI_LINT ) fmt
46
78
.PHONY : fmt
47
79
48
- test : # # Runs the test suite with VCR mocks enabled.
49
- @echo " ==> Testing ${NAME} "
50
- @$(TEST_COMMAND ) -timeout=30s -parallel=20 -tags=" ${GOTAGS} " ${GOPKGS} ${TESTARGS}
51
- .PHONY : test
52
-
53
- lint : # # Runs golangci lint
80
+ lint : install-linter check-linter-version # # Runs golangci lint
54
81
@echo " ==> Running golangci-lint"
55
- @golangci-lint run
82
+ @$( GOLANGCI_LINT ) run
56
83
.PHONY : lint
57
84
58
85
semgrep : # # Run semgrep checker.
59
86
@if [[ " $$ (uname)" == ' Darwin' ]]; then brew install semgrep; fi
60
87
@if command -v semgrep & > /dev/null; then semgrep ci --config auto --exclude-rule generic.secrets.security.detected-private-key.detected-private-key $(SEMGREP_ARGS ) ; fi
61
88
.PHONY : semgrep
62
89
90
+ test : # # Runs the test suite with VCR mocks enabled.
91
+ @echo " ==> Testing ${NAME} "
92
+ @$(TEST_COMMAND ) -timeout=30s -parallel=20 -tags=" ${GOTAGS} " ${GOPKGS} ${TESTARGS}
93
+ .PHONY : test
94
+
63
95
test-race : # # Runs the test suite with the -race flag to identify race conditions, if they exist.
64
96
@echo " ==> Testing ${NAME} (race)"
65
97
@$(TEST_COMMAND ) -timeout=60s -race -tags=" ${GOTAGS} " ${GOPKGS} ${TESTARGS}
@@ -89,9 +121,13 @@ fix-ngwaf-fixtures: ## Updates test fixtures with a specified default Next-Gen W
89
121
90
122
nilaway : # # Run nilaway
91
123
@nilaway ./...
124
+ .PHONY : nilaway
125
+
126
+ clean-bin : # # Removes locally installed binaries
127
+ @echo " ==> Cleaning ./bin directory"
128
+ @rm -rf $(BIN_DIR )
129
+ .PHONY : clean-bin
92
130
93
- .PHONY : help
94
131
help : # # Prints this help menu.
95
132
@grep -E ' ^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST ) | sort | awk ' BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
96
-
97
- .PHONY : clean
133
+ .PHONY : help
0 commit comments