-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathMakefile
127 lines (102 loc) · 3.42 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
.PHONY: default
default: build ;
SHELL := /bin/bash -o pipefail
# the rationale for using both `git describe` and `git rev-parse` is because
# when CI builds the application it can be based on a git tag, so this ensures
# the output is consistent across environments.
VERSION ?= $(shell git describe --tags 2>/dev/null || git rev-parse --short HEAD)
# Allows overriding go executable.
GO_BIN ?= go
# Enables support for tools such as https://github.com/rakyll/gotest
TEST_COMMAND ?= $(GO_BIN) test
# The compute tests can sometimes exceed the default 10m limit.
TEST_ARGS ?= -timeout 15m ./...
CLI_ENV ?= "development"
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
# You can pass flags to goreleaser via GORELEASER_ARGS
# --skip-validate will skip the checks
# --rm-dist will save you deleting the dist dir
# --single-target will be quicker and only build for your os & architecture
# e.g.
# make fastly GORELEASER_ARGS="--skip-validate --rm-dist"
fastly: dependencies $(GO_FILES)
@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 test build install
# Update CI tools used by ./.github/workflows/pr_test.yml
.PHONY: dependencies
dependencies:
$(GO_BIN) install github.com/securego/gosec/v2/cmd/gosec@latest
$(GO_BIN) install honnef.co/go/tools/cmd/staticcheck@latest
$(GO_BIN) install github.com/mgechev/revive@latest
$(GO_BIN) install github.com/goreleaser/[email protected]
# 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
$(GO_BIN) vet ./{cmd,pkg}/...
# Run linter.
.PHONY: revive
revive:
revive ./...
# Run security vulnerability checker.
.PHONY: gosec
gosec:
gosec -quiet -exclude=G104 ./{cmd,pkg}/...
# Run third-party static analysis.
.PHONY: staticcheck
staticcheck:
staticcheck ./{cmd,pkg}/...
# Run tests
.PHONY: test
test: config
@$(TEST_COMMAND) -race $(TEST_ARGS)
# Compile program.
#
# GO_ARGS allows for passing additional arguments.
# e.g. make build GO_ARGS='--ldflags "-s -w"'
.PHONY: build
build: config
$(GO_BIN) build $(GO_ARGS) ./cmd/fastly
# Compile and install program.
#
# GO_ARGS allows for passing additional arguments.
.PHONY: install
install: config
$(GO_BIN) install $(GO_ARGS) ./cmd/fastly
# Scaffold a new CLI command from template files.
.PHONY: scaffold
scaffold:
@$(shell pwd)/scripts/scaffold.sh $(CLI_PACKAGE) $(CLI_COMMAND) $(CLI_API)
# Scaffold a new CLI 'category' command from template files.
.PHONY: scaffold-category
scaffold-category:
@$(shell pwd)/scripts/scaffold-category.sh $(CLI_CATEGORY) $(CLI_CATEGORY_COMMAND) $(CLI_PACKAGE) $(CLI_COMMAND) $(CLI_API)
.PHONY: clean