forked from infobloxopen/protoc-gen-gorm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
133 lines (109 loc) · 4.85 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
include Makefile.buf
GENTOOL_IMAGE := infoblox/atlas-gentool:dev-gengorm
GOPATH ?= $(HOME)/go
SRCPATH := $(patsubst %/,%,$(GOPATH))/src
PROJECT_ROOT := github.com/infobloxopen/protoc-gen-gorm
lint: $(BUF)
buf lint
build: $(BUF)
buf build
test: lint build
go test -v ./...
regenerate: clean-gen generate
clean-gen:
cd example/postgres_arrays && rm -f *.pb.gorm.go && rm -f *.pb.go
cd example/user && rm -f *.pb.gorm.go && rm -f *.pb.go
cd example/feature_demo && rm -f *.pb.gorm.go && rm -f *.pb.go
cd options && rm -f *.pb.gorm.go && rm -f *.pb.go
cd types && rm -f types.pb.go
generate: options/gorm.pb.go types/types.pb.go example/user/*.pb.go example/postgres_arrays/*.pb.go example/feature_demo/*.pb.go
options/gorm.pb.go: proto/options/gorm.proto
buf generate --template proto/options/buf.gen.yaml --path proto/options
types/types.pb.go: proto/types/types.proto
buf generate --template proto/types/buf.gen.yaml --path proto/types
example/feature_demo/*.pb.go: example/feature_demo/*.proto
buf generate --template example/feature_demo/buf.gen.yaml --path example/feature_demo
example/user/*.pb.go: example/user/*.proto
buf generate --template example/user/buf.gen.yaml --path example/user
example/postgres_arrays/*.pb.go: example/postgres_arrays/*.proto
buf generate --template example/postgres_arrays/buf.gen.yaml --path example/postgres_arrays
install:
go install -v .
gentool:
docker build -f docker/Dockerfile -t $(GENTOOL_IMAGE) .
docker image prune -f --filter label=stage=server-intermediate
generate-gentool: SRCROOT_ON_HOST := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
generate-gentool: SRCROOT_IN_CONTAINER := /go/src/$(PROJECT_ROOT)
generate-gentool: DOCKERPATH := /go/src
generate-gentool: DOCKER_RUNNER := docker run --rm
generate-gentool: DOCKER_RUNNER += -v $(SRCROOT_ON_HOST):$(SRCROOT_IN_CONTAINER)
generate-gentool: DOCKER_GENERATOR := infoblox/atlas-gentool:dev-gengorm
generate-gentool: GENERATOR := $(DOCKER_RUNNER) $(DOCKER_GENERATOR)
generate-gentool: #gentool
$(DOCKER_RUNNER) \
$(GENTOOL_IMAGE) \
--go_out="plugins=grpc:$(DOCKERPATH)" \
--gorm_out="engine=postgres,enums=string,gateway:$(DOCKERPATH)" \
feature_demo/demo_multi_file.proto \
feature_demo/demo_multi_file_service.proto \
feature_demo/demo_service.proto \
feature_demo/demo_types.proto
$(DOCKER_RUNNER) \
$(GENTOOL_IMAGE) \
--go_out="plugins=grpc:$(DOCKERPATH)" \
--gorm_out="engine=postgres,enums=string,gateway:$(DOCKERPATH)" \
user/user.proto
$(DOCKER_RUNNER) \
$(GENTOOL_IMAGE) \
--go_out="plugins=grpc:$(DOCKERPATH)" \
--gorm_out="engine=postgres,enums=string,gateway:$(DOCKERPATH)" \
postgres_arrays/postgres_arrays.proto
build-local:
rm -rf example/feature_demo/github.com/
rm -rf example/feature_demo/google.golang.org
go install
protoc --proto_path . \
-I./proto/ \
-I./third_party/proto/ \
-I=. example/feature_demo/demo_multi_file.proto \
example/feature_demo/demo_service.proto --gorm_out="engine=postgres,enums=string,gateway:./example/feature_demo" --go_out=./example/feature_demo
build-user-local:
rm -rf example/user/github.com/
rm -rf example/user/google.golang.org
go install
protoc --proto_path . \
-I./proto/ \
-I./third_party/proto/ \
example/user/user.proto --gorm_out="engine=postgres,enums=string,gateway:./example/user" --go_out=./example/user
build-postgres-local:
rm -rf example/postgres_arrays/github.com/
rm -rf example/postgres_arrays/google.golang.org
go install
protoc --proto_path . \
-I./proto/ \
-I./third_party/proto/ \
example/postgres_arrays/postgres_arrays.proto --gorm_out="engine=postgres,enums=string,gateway:./example/postgres_arrays" --go_out=./example/postgres_arrays
.PHONY: compile
compile:
rm -rf build && mkdir build
for RAW_DIST in $$(go tool dist list); do \
DIST=($${RAW_DIST//// }) && export GOOS=$${DIST[0]} && export GOARCH=$${DIST[1]} && CURRENT="build/protoc-gen-gorm-$$GOOS-$$GOARCH" \
&& go build -o "$$CURRENT" github.com/infobloxopen/protoc-gen-gorm \
|| rm -vf "$$CURRENT"; \
done
GITHUB_USER ?= wk8
GITHUB_REPO ?= protoc-gen-gorm
.PHONY: release
release: _github_release compile
@ git push && if [[ "$$(git status --porcelain)" ]]; then echo 'Working dir dirty, aborting' && exit 1; fi
@ if [ ! "$$TAG" ]; then echo 'TAG env var not set, aborting' && exit 1; fi
git tag "$$TAG" && git push --tags
github-release release --user $(GITHUB_USER) --repo $(GITHUB_REPO) --tag "$$TAG"
cd build && for FILE in $$(ls protoc-gen-gorm-*); do \
github-release upload --user $(GITHUB_USER) --repo $(GITHUB_REPO) --tag "$$TAG" --file "$$FILE" --name "$$FILE"; \
done
# see https://github.com/github-release/github-release
.PHONY: _github_release
_github_release:
@ which github-release &> /dev/null || go get -u github.com/github-release/github-release
@ if [ ! "$$GITHUB_TOKEN" ]; then echo 'GITHUB_TOKEN env var not set, aborting' && exit 1; fi