-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
151 lines (125 loc) · 5.18 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
150
151
# See https://tech.davis-hansson.com/p/make/
SHELL := bash
.DELETE_ON_ERROR:
.SHELLFLAGS := -eu -o pipefail -c
.DEFAULT_GOAL := all
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-print-directory
BIN := .tmp/bin
export PATH := $(BIN):$(PATH)
export GOBIN := $(abspath $(BIN))
COPYRIGHT_YEARS := 2023-2024
# Set to use a different compiler. For example, `GO=go1.18rc1 make test`.
GO ?= go
LATEST_VERSION = $(shell git describe --tags --abbrev=0 2>/dev/null)
CURRENT_VERSION = $(shell git describe --tags --always --dirty)
# If not on release tag, this is a dev build. Add suffix to version.
ifneq ($(CURRENT_VERSION), $(LATEST_VERSION))
DEV_BUILD_VERSION_DIRECTIVE = buildVersionSuffix=-$(shell git describe --exclude '*' --always --dirty)
else
DEV_BUILD_VERSION_DIRECTIVE = buildVersion=$(CURRENT_VERSION)
endif
DEV_BUILD_VERSION_FLAG = -ldflags '-X "connectrpc.com/conformance/internal.$(DEV_BUILD_VERSION_DIRECTIVE)"'
.PHONY: help
help: ## Describe useful make targets
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "%-30s %s\n", $$1, $$2}'
.PHONY: all
all: ## Build, test, and lint (default)
$(MAKE) test
$(MAKE) lint
$(MAKE) runconformance
.PHONY: clean
clean: ## Delete intermediate build artifacts
@# -X only removes untracked files, -d recurses into directories, -f actually removes files/dirs
git clean -Xdf
.PHONY: test
test: build ## Run unit tests
$(GO) test -vet=off -race -cover ./...
.PHONY: build
build: generate ## Build all packages
$(GO) build ./...
.PHONY: generate
generate: $(BIN)/buf $(BIN)/license-header ## Regenerate code and licenses
buf generate proto
license-header \
--license-type apache \
--copyright-holder "The Connect Authors" \
--year-range "$(COPYRIGHT_YEARS)"
.PHONY: lint
lint: $(BIN)/golangci-lint $(BIN)/buf ## Lint Go and protobuf
test -z "$$($(BIN)/buf format -d . | tee /dev/stderr)"
$(GO) vet ./...
golangci-lint run
buf lint proto
.PHONY: lintfix
lintfix: $(BIN)/golangci-lint $(BIN)/buf ## Automatically fix some lint errors
golangci-lint run --fix
buf format -w proto
.PHONY: install
install: ## Install all binaries
$(GO) install $(DEV_BUILD_VERSION_FLAG) ./...
.PHONY: upgrade
upgrade: ## Upgrade dependencies
$(GO) get -u -t ./... && $(GO) mod tidy -v
.PHONY: checkgenerate
checkgenerate:
@# Used in CI to verify that `make generate` doesn't produce a diff.
test -z "$$(git status --porcelain | tee /dev/stderr)"
.PHONY: release
release: $(BIN)/goreleaser
goreleaser release
.PHONY: checkrelease
checkrelease: $(BIN)/goreleaser
# skips some validation and doesn't actually publish a release, just to test
# that building a release works
goreleaser release --clean --snapshot
.PHONY: runconformance
runconformance: runservertests runclienttests
.PHONY: runservertests
runservertests: $(BIN)/connectconformance $(BIN)/referenceserver $(BIN)/grpcserver
$(BIN)/connectconformance -v --conf ./testing/reference-impls-config.yaml --mode server --trace \
--known-failing @./testing/referenceserver-known-failing.txt \
-- $(BIN)/referenceserver
$(BIN)/connectconformance -v --conf ./testing/grpc-impls-config.yaml --mode server --trace \
--known-failing @./testing/grpcserver-known-failing.txt \
-- $(BIN)/grpcserver
$(BIN)/connectconformance -v --conf ./testing/grpc-web-server-impl-config.yaml --mode server --trace \
--known-failing @./testing/grpcserver-web-known-failing.txt \
-- $(BIN)/grpcserver
.PHONY: runclienttests
runclienttests: $(BIN)/connectconformance $(BIN)/referenceclient $(BIN)/grpcclient grpcwebclient
$(BIN)/connectconformance -v --conf ./testing/reference-impls-config.yaml --mode client --trace \
--known-failing @./testing/referenceclient-known-failing.txt \
-- $(BIN)/referenceclient
$(BIN)/connectconformance -v --conf ./testing/grpc-impls-config.yaml --mode client --trace \
--known-failing @./testing/grpcclient-known-failing.txt \
-- $(BIN)/grpcclient
$(BIN)/connectconformance -v --conf ./testing/grpc-web-client-impl-config.yaml --mode client --trace \
--known-failing @./testing/grpcwebclient-known-failing.txt \
-- ./testing/grpcwebclient/bin/grpcwebclient
.PHONY: grpcwebclient
grpcwebclient: generate
cd testing/grpcwebclient && npm run build
$(BIN)/connectconformance: Makefile generate
$(GO) build $(DEV_BUILD_VERSION_FLAG) -o $(@) ./cmd/connectconformance/
$(BIN)/referenceclient: Makefile generate
$(GO) build $(DEV_BUILD_VERSION_FLAG) -o $(@) ./cmd/referenceclient/
$(BIN)/referenceserver: Makefile generate
$(GO) build $(DEV_BUILD_VERSION_FLAG) -o $(@) ./cmd/referenceserver/
$(BIN)/grpcclient: Makefile generate
$(GO) build $(DEV_BUILD_VERSION_FLAG) -o $(@) ./cmd/grpcclient/
$(BIN)/grpcserver: Makefile generate
$(GO) build $(DEV_BUILD_VERSION_FLAG) -o $(@) ./cmd/grpcserver/
$(BIN)/buf: Makefile
@mkdir -p $(@D)
$(GO) install github.com/bufbuild/buf/cmd/[email protected]
$(BIN)/license-header: Makefile
@mkdir -p $(@D)
$(GO) install github.com/bufbuild/buf/private/pkg/licenseheader/cmd/[email protected]
$(BIN)/golangci-lint: Makefile
@mkdir -p $(@D)
$(GO) install github.com/golangci/golangci-lint/cmd/[email protected]
$(BIN)/goreleaser: Makefile
@mkdir -p $(@D)
$(GO) install github.com/goreleaser/[email protected]