Debian Codegraph @

Makefile

raw
1 # Set V to 1 for verbose output from the Makefile
2 Q=$(if $V,,@)
3 SRC=$(shell find . -type f -name '*.go')
4
5 # protoc-gen-go constraints
6 GEN_GO_BIN ?= protoc-gen-go
7 GEN_GO_MIN_VERSION ?= 1.36.1
8 GEN_GO_VERSION ?= $(shell $(GEN_GO_BIN) --version | awk -F ' v' '{print $$NF}')
9
10 # protoc-gen-go-grpc constraints
11 GEN_GRPC_BIN ?= protoc-gen-go-grpc
12 GEN_GRPC_MIN_VERSION ?= 1.5.1
13 GEN_GRPC_VERSION ?= $(shell $(GEN_GRPC_BIN) --version | awk -F ' ' '{print $$NF}')
14
15 # Go tools
16 GOIMPORTS=golang.org/x/tools/cmd/goimports
17 GOLANGCI_LINT=github.com/golangci/golangci-lint/v2/cmd/golangci-lint
18 GOTESTSUM=gotest.tools/gotestsum
19 GOVULNCHECK=golang.org/x/vuln/cmd/govulncheck
20
21 all: lint generate test
22
23 ci: test
24
25 .PHONY: all ci
26
27 #########################################
28 # Build
29 #########################################
30
31 build: ;
32
33 #########################################
34 # Bootstrapping
35 #########################################
36
37 bootstra%:
38 $Q go install -mod=readonly google.golang.org/protobuf/cmd/protoc-gen-go
39 $Q go install -mod=readonly google.golang.org/grpc/cmd/protoc-gen-go-grpc
40
41 .PHONY: bootstrap
42
43 #########################################
44 # Test
45 #########################################
46
47 test:
48 $Q $(GOFLAGS) go tool $(GOTESTSUM) -- -coverpkg=./... -coverprofile=coverage.out -covermode=atomic ./...
49
50 race:
51 $Q $(GOFLAGS) go tool $(GOTESTSUM) -- -race ./...
52
53 .PHONY: test race
54
55 #########################################
56 # Linting
57 #########################################
58
59 fmt:
60 $Q go tool $(GOIMPORTS) -local github.com/smallstep/linkedca -l -w $(SRC)
61
62 lint: SHELL:=/bin/bash
63 lint:
64 $Q LOG_LEVEL=error go tool $(GOLANGCI_LINT) run --config <(curl -s https://raw.githubusercontent.com/smallstep/workflows/master/.golangci.yml) --timeout=30m
65 $Q go tool $(GOVULNCHECK) ./...
66
67 .PHONY: fmt lint
68
69 #########################################
70 # Generate
71 #########################################
72
73 generate: check-gen-go-version check-gen-grpc-version
74 @# remove any previously generated protobufs & gRPC files
75 @find . \
76 -type f \
77 -name "*.pb.go" \
78 -delete
79
80 @# generate the corresponding protobufs & gRPC code files
81 $Q protoc \
82 --proto_path=spec \
83 --go_opt=module=github.com/smallstep/linkedca \
84 --go_out=. \
85 --go-grpc_opt=module=github.com/smallstep/linkedca \
86 --go-grpc_out=. \
87 $(shell find spec -type f -name "*.proto")
88
89 .PHONY: generate
90
91 #########################################
92 # Tool constraints
93 #########################################
94
95 check-gen-go-version:
96 @if ! printf "%s\n%s" "$(GEN_GO_MIN_VERSION)" "$(GEN_GO_VERSION)" | sort -V -C; then \
97 echo "Your $(GEN_GO_BIN) version (v$(GEN_GO_VERSION)) is older than the minimum required (v$(GEN_GO_MIN_VERSION))."; \
98 exit 1; \
99 fi
100
101 .PHONY: check-gen-go-version
102
103 check-gen-grpc-version:
104 @if ! printf "%s\n%s" "$(GEN_GRPC_MIN_VERSION)" "$(GEN_GRPC_VERSION)" | sort -V -C; then \
105 echo "Your $(GEN_GRPC_BIN) version (v$(GEN_GRPC_VERSION)) is older than the minimum required (v$(GEN_GRPC_MIN_VERSION))."; \
106 exit 1; \
107 fi
108
109 .PHONY: check-gen-grpc-version