forked from shenzhencenter/google-ads-pb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
84 lines (76 loc) · 3.46 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
VERSION = 14
INPUT_PATH = googleapis
OUTPUT_PATH = protogen
ADSLIB_PATH = $(INPUT_PATH)/google/ads/googleads/v${VERSION}
API_CONFIG_PATH = $(INPUT_PATH)/google/ads/googleads/v${VERSION}/googleads_v${VERSION}.yaml
GRPC_CONFIG_PATH = $(INPUT_PATH)/google/ads/googleads/v${VERSION}/googleads_grpc_service_config.json
BUILD_PATH = $(OUTPUT_PATH)/google/ads/googleads/v${VERSION}
BUILD_PKG = google.golang.org/genproto/googleapis/ads/googleads/v${VERSION}
PUBLISH_PKG = github.com/Optable/google-ads-pb/protogen
PUBLISH_CLIENT = github.com/Optable/google-ads-pb/clients
PATH := $(shell go env GOPATH)/bin:$(PATH)
.PHONY: generate
generate:
@if [ `git branch --show-current` = "main" ] ; then \
echo "You are on the main branch. Please checkout to another branch and retry." && exit 1; \
fi
@while [ -z "$$version" ]; do \
read -p 'Enter the version number (like ${VERSION}): ' version; \
done ;\
$(MAKE) VERSION=$$version go-install-deps clone prepare-folders build fix-files cleanup
@echo "Done!"
@echo "Please do the following steps:"
@echo "1. Update the version in the README.md"
@echo "2. Create a PR and merge it to main"
@echo "3. Create a tag with the version number (Ex: git tag v1.0.0)"
@echo "4. Push the tag to the remote (Ex: git push origin v1.0.0)"
@echo "5. Create a release in GitHub with the tag"
@echo "6. Publish the release on golang.org (Ex: GOPROXY=proxy.golang.org go list -m github.com/Optable/[email protected])"
@echo "7. Update the version to use the new one in the main project"
.PHONY: go-install-deps
go-install-deps:
@echo "\nInstalling dependencies..."
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
go install github.com/googleapis/gapic-generator-go/cmd/protoc-gen-go_gapic@latest
.PHONY: clone
clone:
@echo "\nCloning googleapis repo..."
rm -rf ./${INPUT_PATH}
git clone --depth=1 --branch=master https://github.com/googleapis/googleapis.git ./${INPUT_PATH}
.PHONY: prepare-folders
prepare-folders:
@echo "\nPreparing folders..."
rm -rf ./clients/* ./${OUTPUT_PATH}/*
.PHONY: build
build:
@echo "\nBuilding the protos and clients..."
protoc --proto_path=${INPUT_PATH} \
--go_out=${OUTPUT_PATH} --go_opt=paths=source_relative \
--go-grpc_out=${OUTPUT_PATH} --go-grpc_opt=paths=source_relative \
--go_gapic_out=${OUTPUT_PATH} \
--go_gapic_opt 'go-gapic-package=clients;clients' \
--go_gapic_opt "api-service-config=./${API_CONFIG_PATH}" \
--go_gapic_opt "grpc-service-config=./${GRPC_CONFIG_PATH}" \
`find ./${ADSLIB_PATH} -name \*.proto`
.PHONY: fix-files
fix-files:
@echo "\nFixing the files"
@echo "\nMoving the proto files..."
mv ${BUILD_PATH}/* ./${OUTPUT_PATH}
@echo "\nRenaming the package..."
find ./${OUTPUT_PATH} -name '*.go' -exec sed -i.bak "s|${BUILD_PKG}|${PUBLISH_PKG}|" '{}' \; -exec rm {}.bak \; \
&& find ./${OUTPUT_PATH}/clients/internal/snippets -name '*.go' -exec sed -i.bak "s|\"clients\"|\"${PUBLISH_CLIENT}\"|g" '{}' \; -exec rm {}.bak \;
@echo "\nMoving the clients..."
mv ./${OUTPUT_PATH}/clients/* ./clients/
@if [ -f ${OUTPUT_PATH}/resources/experiment_arm.pb.go ] ; then \
echo "\nRename experiment_arm.pb.go to experimentarm.pb.go"; \
mv -f ./${OUTPUT_PATH}/resources/experiment_arm.pb.go ./${OUTPUT_PATH}/resources/experimentarm.pb.go; \
fi
.PHONY: cleanup
cleanup:
@echo "\nCleaning up..."
rm -rf ./${INPUT_PATH} \
&& rm -rf ./${OUTPUT_PATH}/google \
&& rm -rf ./${OUTPUT_PATH}/clients \
&& rm -rf ./clients/*_example_test.go