-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
71 lines (60 loc) · 2.5 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
TAG_NAME := $(if $(TAG_NAME),$(TAG_NAME),$(shell git describe --exact-match --tags HEAD 2>/dev/null || :))
BRANCH_NAME := $(if $(BRANCH_NAME),$(BRANCH_NAME),$(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || :))
LONG_VERSION := $(shell git describe --tags --long --abbrev=7 --always HEAD)$(shell echo -$(BRANCH_NAME) | tr / - | grep -v '\-master' || :)
VERSION := $(if $(TAG_NAME),$(TAG_NAME),$(LONG_VERSION))
BUF_VERSION := 1.21.0
PROTOC_GEN_GO_VERSION := 1.30.0
TWIRP_VERSION := 8.1.3
## build:
.PHONY: build
build:
go build -o build/ ./cmd/...
## install:
install:
go install -ldflags "-X main.version=$(VERSION)" ./cmd/twirp-openapi-gen
## test:
test:
go test ./internal/generator
## fmt: format the code using goimports
fmt:
goimports -w $(shell find . -type f -name "*.go" -not -name "*.pb.go" -not -name "*.twirp.go")
## gen: generate go twirp code using buf
gen:
rm -rf ./internal/generator/testdata/gen && \
buf generate ./internal/generator/testdata/paymentapis --template ./internal/generator/testdata/paymentapis/buf.gen.yaml && \
buf generate ./internal/generator/testdata/petapis --template ./internal/generator/testdata/petapis/buf.gen.yaml
## pet-api: generate pet api openapi json doc
pet-api:
./build/twirp-openapi-gen \
-in ./internal/generator/testdata/petapis/pet/v1/pet.proto \
-out ./internal/generator/testdata/pet-api-doc.json \
-proto-path "$(shell realpath ./internal/generator/testdata/paymentapis/)" \
-proto-path "$(shell realpath ./internal/generator/testdata/petapis/)" \
-servers https://petapi.example.com \
-path-prefix "" \
-doc-version 1.0 \
-title "Pet API"
pet-api-yaml:
./build/twirp-openapi-gen \
-format yml \
-in ./internal/generator/testdata/petapis/pet/v1/pet.proto \
-out ./internal/generator/testdata/pet-api-doc.yaml \
-proto-path "$(shell realpath ./internal/generator/testdata/paymentapis/)" \
-proto-path "$(shell realpath ./internal/generator/testdata/petapis/)" \
-servers https://petapi.example.com \
-path-prefix "" \
-doc-version 1.0 \
-title "Pet API"
## tools: download tools; buf, protoc-gen-go and protoc-gen-twirp
tools:
go install github.com/bufbuild/buf/cmd/buf@v$(BUF_VERSION)
go install google.golang.org/protobuf/cmd/protoc-gen-go@v$(PROTOC_GEN_GO_VERSION)
go install github.com/twitchtv/twirp/protoc-gen-twirp@v$(TWIRP_VERSION)
## version: print version
version:
echo $(VERSION)
.PHONY: help
## help: prints this help message
help:
@echo "Usage: \n"
@sed -n 's/^##//p' $(MAKEFILE_LIST) | column -t -s ':' | sed -e 's/^/ /'