-
Notifications
You must be signed in to change notification settings - Fork 123
/
Makefile
149 lines (119 loc) · 4.33 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
include tools/tools.mk
include hack/dev/dev.mk
TELEMETRY_WRITE_KEY ?= ""
TELEMETRY_URL ?= ""
VERSION := $(shell git describe --abbrev=0)
COMMIT_SHA := $(shell git rev-parse HEAD)
BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS += -X "github.com/cerbos/cerbos/internal/util.Version=$(VERSION)"
LDFLAGS += -X "github.com/cerbos/cerbos/internal/util.Commit=$(COMMIT_SHA)"
LDFLAGS += -X "github.com/cerbos/cerbos/internal/util.BuildDate=$(BUILD_DATE)"
.PHONY: all
all: clean build
.PHONY: clean
clean:
@-rm -rf $(GEN_DIR)
@-rm -rf $(MOCK_DIR)
@-rm -rf $(DOCS_OUT_DIR)
@-rm -rf $(JSONSCHEMA_DIR)
@-rm -rf $(OPENAPI_DIR)
.PHONY: clean-tools
clean-tools:
@-rm -rf $(TOOLS_BIN_DIR)
.PHONY: lint
lint: $(GOLANGCI_LINT) $(BUF)
@ $(GOLANGCI_LINT) run --config=.golangci.yaml --fix
@ $(BUF) lint
@ $(BUF) format --diff --exit-code
.PHONY: lint-helm
lint-helm:
@ deploy/charts/validate.sh
.PHONY: generate
generate: clean generate-proto-code generate-json-schemas generate-mocks deps confdocs
.PHONY: generate-proto-code
generate-proto-code: proto-gen-deps
@-rm -rf $(GEN_DIR)
@ $(BUF) format -w
@ $(BUF) generate --template '$(BUF_GEN_TEMPLATE)' .
.PHONY: generate-json-schemas
generate-json-schemas: proto-gen-deps
@-rm -rf $(JSONSCHEMA_DIR)
@ $(BUF) generate --template '$(JSONSCHEMA_BUF_GEN_TEMPLATE)' api/public
.PHONY: generate-mocks
generate-mocks: $(MOCKERY)
@-rm -rf $(MOCK_DIR)
@ $(MOCKERY) --quiet --srcpkg=./internal/storage/index --name=Index --output=$(MOCK_DIR)
@ $(MOCKERY) --quiet --srcpkg=./internal/storage --name=Store --output=$(MOCK_DIR)
.PHONY: generate-notice
generate-notice: $(GO_LICENCE_DETECTOR)
@ go mod download
@ go list -m -json all | $(GO_LICENCE_DETECTOR) -includeIndirect \
-noticeTemplate=hack/notice/templates/NOTICE.txt.tmpl \
-overrides=hack/notice/overrides/overrides.json \
-rules=hack/notice/rules.json \
-noticeOut=NOTICE.txt
.PHONY: confdocs
confdocs:
@ mkdir -p ./internal/confdocs
@ go run ./hack/tools/confdocs/confdocs.go > ./internal/confdocs/generated.go
@ CGO_ENABLED=0 go run ./internal/confdocs/generated.go
@ rm -rf ./internal/confdocs
.PHONY: deps
deps:
@ go mod tidy -compat=1.18
.PHONY: test-all
test-all: test-race test-integration
.PHONY: test
test: $(GOTESTSUM)
@ CGO_ENABLED=0 $(GOTESTSUM) -- -tags=tests $(COVERPROFILE) -cover ./...
.PHONY: test-race
test-race: $(GOTESTSUM) $(TESTSPLIT)
@ $(TESTSPLIT) split --kind=unit --index=$(TESTSPLIT_INDEX) --total=$(TESTSPLIT_TOTAL) | xargs $(GOTESTSUM) --junitfile=junit.unit.$(TESTSPLIT_INDEX).xml -- -tags=tests -race -cover -coverprofile=unit.cover
.PHONY: test-integration
test-integration: $(GOTESTSUM) $(TESTSPLIT)
@ $(TESTSPLIT) split --kind=integration --index=$(TESTSPLIT_INDEX) --total=$(TESTSPLIT_TOTAL) | xargs $(GOTESTSUM) --junitfile=junit.integration.$(TESTSPLIT_INDEX).xml -- -tags=tests,integration -cover -coverprofile=integration.cover
.PHONY: test-times
test-times: $(TESTSPLIT)
@ $(TESTSPLIT) combine --kinds=unit,integration --total=$(TESTSPLIT_TOTAL)
.PHONY: coverage
coverage:
@ hack/scripts/cover.sh
.PHONY: compile
compile:
@ CGO_ENABLED=0 go build ./... && CGO_ENABLED=0 go test -tags="tests e2e" -run=ignore ./... > /dev/null
.PHONY: pre-commit
pre-commit: lint-helm generate lint test-all
.PHONY: build
build: generate lint test package
.PHONY: package
package: $(GORELEASER)
@ TELEMETRY_WRITE_KEY=$(TELEMETRY_WRITE_KEY) TELEMETRY_URL=$(TELEMETRY_URL) $(GORELEASER) release --config=.goreleaser.yml --snapshot --skip-publish --clean
.PHONY: docs
docs: confdocs
@ docs/build.sh
.PHONY: install
install: install-cerbos install-cerbosctl
.PHONY: install-cerbos
install-cerbos:
@ if [ -x "$$(command -v cerbos)" ]; then \
echo "cerbos is already installed, do you want to re-install it? [y/N] " && read ans; \
if [ $$ans = y ] || [ $$ans = Y ] ; then \
go install -ldflags '$(LDFLAGS)' ./cmd/cerbos; \
else \
echo "aborting install"; \
exit -1; \
fi; \
fi; \
.PHONY: install-cerbosctl
install-cerbosctl:
@ if [ -x "$$(command -v cerbosctl)" ]; then \
echo "cerbosctl is already installed, do you want to re-install it? [y/N] " && read ans; \
if [ $$ans = y ] || [ $$ans = Y ] ; then \
go install -ldflags '$(LDFLAGS)' ./cmd/cerbosctl; \
else \
echo "aborting install"; \
exit -1; \
fi; \
fi; \
.PHONY: warm-cache
warm-cache: compile proto-gen-deps $(GOTESTSUM) $(MOCKERY) $(TESTSPLIT)