-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
78 lines (63 loc) · 1.75 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
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-print-directory
.SUFFIXES:
SHELL := bash
.SHELLFLAGS := -euo pipefail -c
.DELETE_ON_ERROR:
.DEFAULT_GOAL := all
#: Which golangci-lint version to install for linting
GOLANGCI_LINT_VERSION = $(shell cat .versions/GOLANGCI_LINT)
#: Which golangci-lint binary to use
GOLANGCI_LINT ?= .bin/golangci-lint-$(GOLANGCI_LINT_VERSION)
#: Which buf CLI version to install for code generation
BUF_VERSION = $(shell cat .versions/BUF)
#: Which buf CLI binary to use
BUF ?= .bin/buf-$(BUF_VERSION)
#: Which protoc-gen-slog CLI to use
PGSLOG ?= .bin/protoc-gen-slog
#: Which go CLI binary to use
GO ?= go
#: Test flags for Go tests
GO_TEST_FLAGS ?= -vet=off -race -cover
codegen += internal/gen
.PHONY: all
all:
$(MAKE) build
.PHONY: build
build: $(codegen)
$(GO) build ./...
.PHONY: install
install: $(codegen)
$(GO) install ./protoc-gen-slog
.PHONY: check
check: test lint
.PHONY: test
test: $(codegen)
$(GO) test $(GO_TEST_FLAGS) ./...
.PHONY: lint
lint: $(codegen) $(GOLANGCI_LINT) $(BUF)
$(GOLANGCI_LINT) run
$(BUF) lint
.PHONY: generate
generate: $(BUF) $(PGSLOG)
$(BUF) generate
.PHONY: generate-check
generate-check:
test -z "$$(git status --porcelain | tee /dev/stderr)"
.PHONY: clean
clean:
rm -rf $(codegen) .bin
$(codegen):
$(MAKE) generate
$(PGSLOG): export GOBIN=$(abspath .bin)
$(PGSLOG): $(shell find ./protoc-gen-slog)
$(GO) install ./protoc-gen-slog
$(GOLANGCI_LINT): export GOBIN=$(abspath .bin)
$(GOLANGCI_LINT):
$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) \
&& mv $(GOBIN)/golangci-lint $@
$(BUF): export GOBIN=$(abspath .bin)
$(BUF):
$(GO) install github.com/bufbuild/buf/cmd/buf@$(BUF_VERSION) \
&& mv $(GOBIN)/buf $@