-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathMakefile
More file actions
123 lines (98 loc) · 4.16 KB
/
Copy pathMakefile
File metadata and controls
123 lines (98 loc) · 4.16 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
SHELL := /bin/bash -o pipefail
GO ?= go
# List of tests to run
FILES ?= ./...
# List all our actual files, excluding vendor
GOPKGS ?= $(shell $(GO) list $(FILES) | grep -v /vendor/)
# Tags specific for building
GOTAGS ?=
# Number of procs to use
GOMAXPROCS ?= 4
NAME := $(notdir $(shell pwd))
# Test Resource IDs
FASTLY_TEST_DELIVERY_SERVICE_ID ?=
DEFAULT_FASTLY_TEST_DELIVERY_SERVICE_ID = kKJb5bOFI47uHeBVluGfX1
FASTLY_TEST_COMPUTE_SERVICE_ID ?=
DEFAULT_FASTLY_TEST_COMPUTE_SERVICE_ID = XsjdElScZGjmfCcTwsYRC1
FASTLY_TEST_NGWAF_WORKSPACE_ID ?=
DEFAULT_FASTLY_TEST_NGWAF_WORKSPACE_ID = Am2qjXkgamuYp3u54rQkLD
FASTLY_API_KEY ?=
# Enables support for tools such as https://github.com/rakyll/gotest
TEST_COMMAND ?= $(GO) test
# Tooling versions
GOLANGCI_LINT_VERSION = v2.10.1
BIN_DIR := $(CURDIR)/bin
GOLANGCI_LINT := $(BIN_DIR)/golangci-lint
all: mod-download tidy fmt lint test semgrep ## Runs all of the required cleaning and verification targets.
.PHONY: all
mod-download: ## Downloads the Go module.
@echo "==> Downloading Go module"
@$(GO) mod download
.PHONY: mod-download
tidy: ## Cleans the Go module.
@echo "==> Tidying module"
@$(GO) mod tidy
.PHONY: tidy
install-linter: ## Installs golangci-lint via go install
@echo "==> Installing golangci-lint $(GOLANGCI_LINT_VERSION)"
@mkdir -p $(BIN_DIR)
@GOBIN=$(BIN_DIR) go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
.PHONY: install-linter
check-linter-version: ## Verifies installed golangci-lint version matches expected
@echo "==> Checking golangci-lint version"
@EXPECTED="$(GOLANGCI_LINT_VERSION)"; \
EXPECTED=$${EXPECTED#v}; \
INSTALLED=$$($(GOLANGCI_LINT) version --short); \
if [ "$$INSTALLED" != "$$EXPECTED" ]; then \
echo "Expected golangci-lint v$$EXPECTED but found $$INSTALLED"; \
exit 1; \
fi
.PHONY: check-linter-version
fmt: install-linter ## Properly formats Go files and orders dependencies.
@echo "==> Running golangci-lint fmt"
@$(GOLANGCI_LINT) fmt
.PHONY: fmt
lint: install-linter check-linter-version ## Runs golangci lint
@echo "==> Running golangci-lint"
@$(GOLANGCI_LINT) run
.PHONY: lint
semgrep: ## Run semgrep checker.
@if [[ "$$(uname)" == 'Darwin' ]]; then brew install semgrep; fi
@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
.PHONY: semgrep
test: ## Runs the test suite with VCR mocks enabled.
@echo "==> Testing ${NAME}"
@$(TEST_COMMAND) -timeout=30s -parallel=20 -tags="${GOTAGS}" ${GOPKGS} ${TESTARGS}
.PHONY: test
test-race: ## Runs the test suite with the -race flag to identify race conditions, if they exist.
@echo "==> Testing ${NAME} (race)"
@$(TEST_COMMAND) -timeout=60s -race -tags="${GOTAGS}" ${GOPKGS} ${TESTARGS}
.PHONY: test-race
test-full: ## Runs the tests with VCR disabled (i.e., makes external calls).
@echo "==> Testing ${NAME} with VCR disabled"
@VCR_DISABLE=1 \
bash -c \
'${GO} test -timeout=60s -parallel=20 ${GOPKGS} ${TESTARGS}'
.PHONY: test-full
fix-delivery-fixtures: ## Updates test fixtures with a specified default Delivery service ID.
@echo "==> Updating fixtures"
@$(shell pwd)/scripts/fixFixtures.sh ${FASTLY_TEST_DELIVERY_SERVICE_ID} ${DEFAULT_FASTLY_TEST_DELIVERY_SERVICE_ID}
.PHONY: fix-delivery-fixtures
fix-compute-fixtures: ## Updates test fixtures with a specified default Compute service ID.
@echo "==> Updating fixtures"
@$(shell pwd)/scripts/fixFixtures.sh ${FASTLY_TEST_COMPUTE_SERVICE_ID} ${DEFAULT_FASTLY_TEST_COMPUTE_SERVICE_ID}
.PHONY: fix-compute-fixtures
fix-ngwaf-fixtures: ## Updates test fixtures with a specified default Next-Gen WAF workspace ID.
@echo "==> Updating fixtures"
@$(shell pwd)/scripts/fixFixtures.sh ${FASTLY_TEST_NGWAF_WORKSPACE_ID} ${DEFAULT_FASTLY_TEST_NGWAF_WORKSPACE_ID}
.PHONY: fix-ngwaf-fixtures
nilaway: ## Run nilaway
@nilaway ./...
.PHONY: nilaway
clean-bin: ## Removes locally installed binaries
@echo "==> Cleaning ./bin directory"
@rm -rf $(BIN_DIR)
.PHONY: clean-bin
help: ## Prints this help menu.
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: help