-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
109 lines (89 loc) · 3.74 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
PROJECT := api
# This controls the remote HTTPS git location to compare against for breaking changes in CI.
#
# Most CI providers only clone the branch under test and to a certain depth, so when
# running buf check breaking in CI, it is generally preferable to compare against
# the remote repository directly.
#
# Basic authentication is available, see https://buf.build/docs/inputs#https for more details.
HTTPS_GIT := https://github.com/spacemeshos/api.git
# This controls the remote SSH git location to compare against for breaking changes in CI.
#
# CI providers will typically have an SSH key installed as part of your setup for both
# public and private repositories. Buf knows how to look for an SSH key at ~/.ssh/id_rsa
# and a known hosts file at ~/.ssh/known_hosts or /etc/ssh/known_hosts without any further
# configuration. We demo this with CircleCI.
#
# See https://buf.build/docs/inputs#ssh for more details.
SSH_GIT := ssh://[email protected]/spacemeshos/api.git
# This controls the version of buf to install and use.
BUF_VERSION := 1.30.0
GRPC_JSON_PROXY_VERSION := v2.19.1
PROTOC_GO_VERSION := v1.33.0
PROTOC_GEN_GO_VERSION := v1.3.0
GO_SWAGGER_VERSION := v0.31.0
# Everything below this line is meant to be static, i.e. only adjust the above variables. ###
ifeq ($(OS),Windows_NT)
UNAME_OS := windows
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
UNAME_ARCH := x86_64
endif
ifeq ($(PROCESSOR_ARCHITECTURE),ARM64)
UNAME_ARCH := aarch64
endif
PROTOC_BUILD := win64
BIN_DIR := $(abspath .)/bin
export PATH := $(BIN_DIR);$(PATH)
else
UNAME_OS := $(shell uname -s)
UNAME_ARCH := $(shell uname -m)
PROTOC_BUILD := $(shell echo ${UNAME_OS}-${UNAME_ARCH} | tr '[:upper:]' '[:lower:]' | sed 's/darwin/osx/' | sed 's/arm64/aarch_64/' | sed 's/aarch64/aarch_64/')
BIN_DIR := $(abspath .)/bin
export PATH := $(BIN_DIR):$(PATH)
endif
# `go install` will put binaries in $(GOBIN), avoiding
# messing up with global environment.
export GOBIN := $(BIN_DIR)
BUF := $(BIN_DIR)/buf_$(BUF_VERSION)
$(BUF): protoc-plugins deps
@mkdir -p $(BIN_DIR)
@rm -f $(BIN_DIR)/buf_*
@curl -sSL "https://github.com/bufbuild/buf/releases/download/v$(BUF_VERSION)/buf-$(UNAME_OS)-$(UNAME_ARCH)" -o $@
@chmod +x $@
@ln -sf $@ $(BIN_DIR)/buf
# Download protoc plugins
protoc-plugins:
@go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@$(GRPC_JSON_PROXY_VERSION)
@go install google.golang.org/protobuf/cmd/protoc-gen-go@$(PROTOC_GO_VERSION)
@go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@$(PROTOC_GEN_GO_VERSION)
@go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@$(GRPC_JSON_PROXY_VERSION)
.PHONY: protoc-plugins
# Download go deps
.PHONY: deps
deps:
@go install github.com/go-swagger/go-swagger/cmd/swagger@$(GO_SWAGGER_VERSION)
# local is what we run when testing locally.
# This does breaking change detection against our local git repository.
.PHONY: local
local: $(BUF)
buf breaking --against '.git#branch=master'
# Linter only. This does not do breaking change detection.
.PHONY: lint
lint: $(BUF)
buf lint
# https is what we run when testing in most CI providers.
# This does breaking change detection against our remote HTTPS git repository.
.PHONY: breaking
breaking: $(BUF)
buf breaking --against "$(HTTPS_GIT)#branch=master"
# Run all builds
.PHONY: build
build: $(BUF)
buf generate
swagger flatten --with-flatten=remove-unused release/openapi/swagger/src/api.swagger.json -o release/openapi/swagger/src/api.swagger.json
# Make sure build is up to date
.PHONY: check
check: $(BUF)
@git diff --quiet || (echo "\033[0;31mWorking directory not clean!\033[0m" && git --no-pager diff && exit 1)
@make build
@git diff --name-only --diff-filter=AM --exit-code . || { echo "\nPlease rerun 'make build' and commit changes.\n"; exit 1; }