-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
130 lines (108 loc) · 5.54 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
all: clean common replication podmon volumeGroupSnapshot migration
########################################################################
## GOLANG ##
########################################################################
# If GOPATH isn't defined then set its default location.
ifeq (,$(strip $(GOPATH)))
GOPATH := $(HOME)/go
else
# If GOPATH is already set then update GOPATH to be its own
# first element.
GOPATH := $(word 1,$(subst :, ,$(GOPATH)))
endif
export GOPATH
########################################################################
## PROTOC ##
########################################################################
# Only set PROTOC_VER if it has an empty value.
ifeq (,$(strip $(PROTOC_VER)))
PROTOC_VER := 26.1
endif
PROTOC_OS := $(shell uname -s)
ifeq (Darwin,$(PROTOC_OS))
PROTOC_OS := osx
endif
ifeq (Linux,$(PROTOC_OS))
PROTOC_OS := linux
endif
PROTOC_ARCH := $(shell uname -m)
ifeq (i386,$(PROTOC_ARCH))
PROTOC_ARCH := x86_32
endif
ifeq (arm64osx,$(PROTOC_ARCH)$(PROTOC_OS))
PROTOC_ARCH := aarch_64
endif
ifeq (x86_64,$(PROTOC_ARCH))
PROTOC_ARCH := x86_64
endif
PROTOC := ./protoc
PROTO_INCLUDE=.protoc/include
PROTOC_ZIP := protoc-$(PROTOC_VER)-$(PROTOC_OS)-$(PROTOC_ARCH).zip
ifeq (,$(strip $(PROTOC_OS)))
PROTOC_ZIP := protoc-$(PROTOC_VER)-win64.zip
endif
PROTOC_URL := https://github.com/google/protobuf/releases/download/v$(PROTOC_VER)/$(PROTOC_ZIP)
PROTOC_TMP_DIR := .protoc
PROTOC_TMP_BIN := $(PROTOC_TMP_DIR)/bin/protoc
$(PROTOC):
-mkdir -p "$(PROTOC_TMP_DIR)" && \
curl -L $(PROTOC_URL) -o "$(PROTOC_TMP_DIR)/$(PROTOC_ZIP)" && \
unzip "$(PROTOC_TMP_DIR)/$(PROTOC_ZIP)" -d "$(PROTOC_TMP_DIR)" && \
chmod 0755 "$(PROTOC_TMP_BIN)" && \
cp -f "$(PROTOC_TMP_BIN)" "$@"
stat "$@" > /dev/null 2>&1
########################################################################
## PROTOC-GEN-GO ##
########################################################################
# This is the recipe for getting and installing the go plug-in
# for protoc
PROTOC_GEN_GO := protoc-gen-go
$(PROTOC_GEN_GO):
go install google.golang.org/protobuf/cmd/[email protected]
go install google.golang.org/grpc/cmd/[email protected]
########################################################################
## PATH ##
########################################################################
# Update PATH with the current directory. This enables the protoc
# binary to discover the protoc-gen-go binary, built inside this
# directory.
export PATH := $(shell pwd):$(PATH)
.PHONY: replication
replication: $(PROTOC) $(PROTOC_GEN_GO)
$(PWD)/$(PROTOC) -I $(PROTO_INCLUDE) -I ./common --go_out="$@" --go_opt=paths=source_relative --go-grpc_out=require_unimplemented_servers=false:"$@" --go-grpc_opt=paths=source_relative --proto_path="$@" ./"$@"/"$@".proto
(cd "$@"; go mod tidy; go build "$@".pb.go)
.PHONY: migration
migration: $(PROTOC) $(PROTOC_GEN_GO)
$(PWD)/$(PROTOC) -I $(PROTO_INCLUDE) -I ./common --go_out="$@" --go_opt=paths=source_relative --go-grpc_out=require_unimplemented_servers=false:"$@" --go-grpc_opt=paths=source_relative --proto_path="$@" ./"$@"/"$@".proto
(cd "$@"; go mod tidy; go build "$@".pb.go)
.PHONY: podmon
podmon: $(PROTOC) $(PROTOC_GEN_GO)
$(PWD)/$(PROTOC) -I $(PROTO_INCLUDE) --go_out="$@" --go_opt=paths=source_relative --go-grpc_out=require_unimplemented_servers=false:"$@" --go-grpc_opt=paths=source_relative --proto_path="$@" ./"$@"/"$@".proto
(cd "$@"; go mod tidy; go build "$@".pb.go)
.PHONY: volumeGroupSnapshot
volumeGroupSnapshot: $(PROTOC) $(PROTOC_GEN_GO)
$(PWD)/$(PROTOC) -I $(PROTO_INCLUDE) -I ./common --go_out="$@" --go_opt=paths=source_relative --go-grpc_out=require_unimplemented_servers=false:"$@" --go-grpc_opt=paths=source_relative --proto_path="$@" ./"$@"/"$@".proto
(cd "$@"; go mod tidy; go build "$@".pb.go)
.PHONY: common
common: $(PROTOC) $(PROTOC_GEN_GO)
$(PWD)/$(PROTOC) -I $(PROTO_INCLUDE) --go_out="$@" --go_opt=paths=source_relative --go-grpc_out=require_unimplemented_servers=false:"$@" --go-grpc_opt=paths=source_relative --proto_path="$@" ./"$@"/"$@".proto
(cd "$@"; go mod tidy; go build "$@".pb.go)
clean:
rm -rf ./replication/replication.pb.go ./replication/replication_grpc.pb.go ./podmon/podmon.pb.go ./podmon/podmon_grpc.pb.go ./volumeGroupSnapshot/volumeGroupSnapshot.pb.go ./volumeGroupSnapshot/volumeGroupSnapshot_grpc.pb.go ./migration/migration.pb.go ./migration/migration_grpc.pb.go ./common/common.pb.go
clobber: clean
rm -rf "$(PROTOC)" "$(PROTOC_GEN_GO)" "$(PROTOC_TMP_DIR)"
.PHONY: actions action-help
actions: ## Run all GitHub Action checks that run on a pull request creation
@echo "Running all GitHub Action checks for pull request events..."
@act -l | grep -v ^Stage | grep pull_request | grep -v image_security_scan | awk '{print $$2}' | while read WF; do \
echo "Running workflow: $${WF}"; \
act pull_request --no-cache-server --platform ubuntu-latest=ghcr.io/catthehacker/ubuntu:act-latest --job "$${WF}"; \
done
action-help: ## Echo instructions to run one specific workflow locally
@echo "GitHub Workflows can be run locally with the following command:"
@echo "act pull_request --no-cache-server --platform ubuntu-latest=ghcr.io/catthehacker/ubuntu:act-latest --job <jobid>"
@echo ""
@echo "Where '<jobid>' is a Job ID returned by the command:"
@echo "act -l"
@echo ""
@echo "NOTE: if act is not installed, it can be downloaded from https://github.com/nektos/act"