-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
89 lines (72 loc) · 2.66 KB
/
Makefile
File metadata and controls
89 lines (72 loc) · 2.66 KB
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
default: fmt lint generate install
build:
go build -v ./...
install: build
go install -v ./...
lint:
golangci-lint run
generate:
cd tools; go generate ./...
fmt:
gofmt -s -w -e .
test:
go test -v -cover -timeout=120s -parallel=10 ./...
testacc:
TF_ACC=1 go test -v -cover -timeout 120m ./...
# files to be copied
SERVICES_DIR ?= ../services
# source dir for the generated proto bits, and connect RPC bits
SOURCE_PROTO_DIR = dakr/proto/api/v1
SOURCE_GEN_PB_DIR = dakr/gen/api/v1
SOURCE_GEN_CONNECT_DIR = dakr/gen/api/v1/apiv1connect
# target dir for the generated proto bits, and connect RPC bits
TARGET_PROTO_DIR = internal/proto/api/v1
TARGET_GEN_PB_DIR = internal/gen/api/v1
TARGET_GEN_CONNECT_DIR = internal/gen/api/v1/apiv1connect
PROTO_FILES = common.proto k8s.proto recommendation.proto
GEN_PB_FILES = common.pb.go k8s.pb.go recommendation.pb.go
GEN_CONNECT_FILES = k8s.connect.go recommendation.connect.go
.PHONY: proto
proto:
@echo "Copying protos from $(SERVICES_DIR)/$(SOURCE_PROTO_DIR) to $(TARGET_PROTO_DIR)"
@for proto in $(PROTO_FILES); do \
if [ -f $(SERVICES_DIR)/$(SOURCE_PROTO_DIR)/$$proto ]; then \
cp $(SERVICES_DIR)/$(SOURCE_PROTO_DIR)/$$proto $(TARGET_PROTO_DIR)/; \
else \
echo "Error: Missing file: $$proto"; \
exit 1; \
fi; \
done
@echo "Done copying protos."
@echo "Copying generated pb.go files from $(SERVICES_DIR)/$(SOURCE_GEN_PB_DIR) to $(TARGET_GEN_PB_DIR)"
@for proto in $(GEN_PB_FILES); do \
if [ -f $(SERVICES_DIR)/$(SOURCE_GEN_PB_DIR)/$$proto ]; then \
cp $(SERVICES_DIR)/$(SOURCE_GEN_PB_DIR)/$$proto $(TARGET_GEN_PB_DIR)/; \
else \
echo "Error: Missing file: $$proto"; \
exit 1; \
fi; \
done
@echo "Done copying generated pb.go files."
@echo "Copying generated pb.go files for connect rpc from $(SERVICES_DIR)/$(SOURCE_GEN_CONNECT_DIR) to $(TARGET_GEN_CONNECT_DIR)"
@for proto in $(GEN_CONNECT_FILES); do \
if [ -f $(SERVICES_DIR)/$(SOURCE_GEN_CONNECT_DIR)/$$proto ]; then \
cp $(SERVICES_DIR)/$(SOURCE_GEN_CONNECT_DIR)/$$proto $(TARGET_GEN_CONNECT_DIR)/; \
else \
echo "Error: Missing file: $$proto"; \
exit 1; \
fi; \
done
@echo "Done copying generated pb.go files."
@echo "Replacing import paths in copied .go files..."
@OLD_IMPORT="github.com/devzero-inc/services/dakr/gen/api/v1"; \
NEW_IMPORT="github.com/devzero-inc/terraform-provider-devzero/internal/gen/api/v1"; \
for f in $(TARGET_GEN_PB_DIR)/*.go $(TARGET_GEN_CONNECT_DIR)/*.go; do \
if [ "$$(uname)" = "Darwin" ]; then \
sed -i '' "s|$$OLD_IMPORT|$$NEW_IMPORT|g" $$f; \
else \
sed -i "s|$$OLD_IMPORT|$$NEW_IMPORT|g" $$f; \
fi; \
done
@echo "Import path replacement complete."
.PHONY: fmt lint test testacc build install generate