-
Notifications
You must be signed in to change notification settings - Fork 59
/
Makefile
165 lines (137 loc) · 5.46 KB
/
Makefile
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
.PHONY: clean
SHELL := /usr/bin/env bash -o pipefail ## Set the shell to use for finding Go files (default: /bin/bash)
# Compile program (implicit default target).
#
# GO_ARGS allows for passing additional arguments.
# e.g. make build GO_ARGS='--ldflags "-s -w"'
.PHONY: build
build: config ## Compile program (CGO disabled)
CGO_ENABLED=0 $(GO_BIN) build $(GO_ARGS) ./cmd/fastly
GO_BIN ?= go ## Allows overriding go executable.
TEST_COMMAND ?= $(GO_BIN) test ## Enables support for tools such as https://github.com/rakyll/gotest
TEST_ARGS ?= -v -timeout 15m ./... ## The compute tests can sometimes exceed the default 10m limit
GOHOSTOS ?= $(shell go env GOHOSTOS || echo unknown)
GOHOSTARCH ?= $(shell go env GOHOSTARCH || echo unknown)
ifeq ($(OS), Windows_NT)
SHELL = cmd.exe
.SHELLFLAGS = /c
GO_FILES = $(shell where /r pkg *.go)
GO_FILES += $(shell where /r cmd *.go)
CONFIG_SCRIPT = scripts\config.sh
CONFIG_FILE = pkg\config\config.toml
else
GO_FILES = $(shell find cmd pkg -type f -name '*.go')
CONFIG_SCRIPT = ./scripts/config.sh
CONFIG_FILE = pkg/config/config.toml
endif
# Build executables using goreleaser (useful for local testing purposes).
#
# You can pass flags to goreleaser via GORELEASER_ARGS
# --clean will save you deleting the dist dir
# --single-target will be quicker and only build for your os & architecture
# --skip=post-hooks which prevents errors such as trying to execute the binary for each OS (e.g. we call scripts/documentation.sh and we can't run Windows exe on a Mac).
# --skip=validate will skip the checks (e.g. git tag checks which result in a 'dirty git state' error)
#
# EXAMPLE:
# make release GORELEASER_ARGS="--clean --skip=post-hooks --skip=validate"
release: dependencies $(GO_FILES) ## Build executables using goreleaser
@GOHOSTOS="${GOHOSTOS}" GOHOSTARCH="${GOHOSTARCH}" goreleaser build ${GORELEASER_ARGS}
# Useful for attaching a debugger such as https://github.com/go-delve/delve
debug:
@$(GO_BIN) build -gcflags="all=-N -l" $(GO_ARGS) -o "fastly" ./cmd/fastly
.PHONY: config
config:
@$(CONFIG_SCRIPT)
.PHONY: all
all: config dependencies tidy fmt vet staticcheck gosec semgrep test build install ## Run EVERYTHING!
# Update CI tools used by ./.github/workflows/pr_test.yml
.PHONY: dependencies
dependencies:
@while read -r line || [ -n "$$line" ]; do \
$(GO_BIN) install $$line; \
done < .github/dependencies.txt
@if [ "$$(uname)" = 'Darwin' ]; then \
if ! command -v semgrep &> /dev/null; then \
brew install semgrep; \
fi \
fi
# Clean up Go modules file.
.PHONY: tidy
tidy:
$(GO_BIN) mod tidy
# Run formatter.
.PHONY: fmt
fmt:
@echo gofmt -l ./{cmd,pkg}
@eval "bash -c 'F=\$$(gofmt -l ./{cmd,pkg}) ; if [[ \$$F ]] ; then echo \$$F ; exit 1 ; fi'"
# Run static analysis.
.PHONY: vet
vet: config ## Run vet static analysis
$(GO_BIN) vet ./{cmd,pkg}/...
# Run linter.
.PHONY: revive
revive: ## Run linter (using revive)
revive ./...
# Run security vulnerability checker.
.PHONY: gosec
gosec: ## Run security vulnerability checker
gosec -quiet -exclude=G104 ./{cmd,pkg}/...
nilaway: ## Run nilaway
@nilaway ./...
# Run semgrep checker.