-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathMakefile
More file actions
109 lines (81 loc) · 2.95 KB
/
Makefile
File metadata and controls
109 lines (81 loc) · 2.95 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
# Set V to 1 for verbose output from the Makefile
Q=$(if $V,,@)
SRC=$(shell find . -type f -name '*.go')
# protoc-gen-go constraints
GEN_GO_BIN ?= protoc-gen-go
GEN_GO_MIN_VERSION ?= 1.36.1
GEN_GO_VERSION ?= $(shell $(GEN_GO_BIN) --version | awk -F ' v' '{print $$NF}')
# protoc-gen-go-grpc constraints
GEN_GRPC_BIN ?= protoc-gen-go-grpc
GEN_GRPC_MIN_VERSION ?= 1.5.1
GEN_GRPC_VERSION ?= $(shell $(GEN_GRPC_BIN) --version | awk -F ' ' '{print $$NF}')
# Go tools
GOIMPORTS=golang.org/x/tools/cmd/goimports
GOLANGCI_LINT=github.com/golangci/golangci-lint/v2/cmd/golangci-lint
GOTESTSUM=gotest.tools/gotestsum
GOVULNCHECK=golang.org/x/vuln/cmd/govulncheck
all: lint generate test
ci: test
.PHONY: all ci
#########################################
# Build
#########################################
build: ;
#########################################
# Bootstrapping
#########################################
bootstra%:
$Q go install -mod=readonly google.golang.org/protobuf/cmd/protoc-gen-go
$Q go install -mod=readonly google.golang.org/grpc/cmd/protoc-gen-go-grpc
.PHONY: bootstrap
#########################################
# Test
#########################################
test:
$Q $(GOFLAGS) go tool $(GOTESTSUM) -- -coverpkg=./... -coverprofile=coverage.out -covermode=atomic ./...
race:
$Q $(GOFLAGS) go tool $(GOTESTSUM) -- -race ./...
.PHONY: test race
#########################################
# Linting
#########################################
fmt:
$Q go tool $(GOIMPORTS) -local github.com/smallstep/linkedca -l -w $(SRC)
lint: SHELL:=/bin/bash
lint:
$Q LOG_LEVEL=error go tool $(GOLANGCI_LINT) run --config <(curl -s https://raw.githubusercontent.com/smallstep/workflows/master/.golangci.yml) --timeout=30m
$Q go tool $(GOVULNCHECK) ./...
.PHONY: fmt lint
#########################################
# Generate
#########################################
generate: check-gen-go-version check-gen-grpc-version
@# remove any previously generated protobufs & gRPC files
@find . \
-type f \
-name "*.pb.go" \
-delete
@# generate the corresponding protobufs & gRPC code files
$Q protoc \
--proto_path=spec \
--go_opt=module=github.com/smallstep/linkedca \
--go_out=. \
--go-grpc_opt=module=github.com/smallstep/linkedca \
--go-grpc_out=. \
$(shell find spec -type f -name "*.proto")
.PHONY: generate
#########################################
# Tool constraints
#########################################
check-gen-go-version:
@if ! printf "%s\n%s" "$(GEN_GO_MIN_VERSION)" "$(GEN_GO_VERSION)" | sort -V -C; then \
echo "Your $(GEN_GO_BIN) version (v$(GEN_GO_VERSION)) is older than the minimum required (v$(GEN_GO_MIN_VERSION))."; \
exit 1; \
fi
.PHONY: check-gen-go-version
check-gen-grpc-version:
@if ! printf "%s\n%s" "$(GEN_GRPC_MIN_VERSION)" "$(GEN_GRPC_VERSION)" | sort -V -C; then \
echo "Your $(GEN_GRPC_BIN) version (v$(GEN_GRPC_VERSION)) is older than the minimum required (v$(GEN_GRPC_MIN_VERSION))."; \
exit 1; \
fi
.PHONY: check-gen-grpc-version