-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile
More file actions
103 lines (87 loc) · 3.81 KB
/
Makefile
File metadata and controls
103 lines (87 loc) · 3.81 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Default target
build: validate_plugin validate_version
# Remove existing work dir and create a new directory for the render process
rm -rf work && \
mkdir -p work
# Copy the entire source tree, excluding .git directory, into the new directory
rsync -a --exclude='.git' . work/ >/dev/null 2>&1
# Change to the new directory to perform operations
cd work && \
go run generate/generator.go templates . $(plugin) $(plugin_version) $(plugin_github_url) && \
if [ ! -z "$(plugin_version)" ]; then \
MAJOR_VERSION=$$(echo $(plugin_version) | grep -o '^v[0-9]\+' || echo "v1") && \
if [ "$$MAJOR_VERSION" = "v1" ] || [ "$$MAJOR_VERSION" = "v0" ]; then \
echo "go get $(plugin_github_url)@$(plugin_version)" && \
go get $(plugin_github_url)@$(plugin_version); \
else \
echo "go get $(plugin_github_url)/$$MAJOR_VERSION@$(plugin_version)" && \
go get $(plugin_github_url)/$$MAJOR_VERSION@$(plugin_version); \
fi; \
fi && \
go mod tidy && \
$(MAKE) -f out/Makefile build
# Note: The work directory will contain the full code tree with changes,
# binaries will be copied to /usr/local/bin.
# Check if the 'plugin' variable is set
validate_plugin:
ifndef plugin
$(error "The 'plugin' variable is missing. Usage: make build plugin=<plugin_name> [plugin_version=<version>] [plugin_github_url=<url>]")
endif
# Check if plugin_github_url is provided when plugin_version is specified
validate_version:
ifdef plugin_version
ifndef plugin_github_url
$(error "The 'plugin_github_url' variable is required when 'plugin_version' is specified")
endif
endif
# render target
render: validate_plugin validate_version
@echo "Rendering code for plugin: $(plugin)"
# Remove existing work dir and create a new directory for the render process
rm -rf work && \
mkdir -p work
# Copy the entire source tree, excluding .git directory, into the new directory
rsync -a --exclude='.git' . work/ >/dev/null 2>&1
# Change to the new directory to perform operations
cd work && \
go run generate/generator.go templates . $(plugin) $(plugin_version) $(plugin_github_url) && \
if [ ! -z "$(plugin_version)" ]; then \
MAJOR_VERSION=$$(echo $(plugin_version) | grep -o '^v[0-9]\+' || echo "v1") && \
if [ "$$MAJOR_VERSION" = "v1" ] || [ "$$MAJOR_VERSION" = "v0" ]; then \
echo "go get $(plugin_github_url)@$(plugin_version)" && \
go get $(plugin_github_url)@$(plugin_version); \
else \
echo "go get $(plugin_github_url)/$$MAJOR_VERSION@$(plugin_version)" && \
go get $(plugin_github_url)/$$MAJOR_VERSION@$(plugin_version); \
fi; \
fi && \
go mod tidy
# Note: The work directory will contain the full code tree with rendered changes
# build_from_work target
build_from_work:
@if [ ! -d "work" ]; then \
echo "Error: 'work' directory does not exist. Please run the render target first." >&2; \
exit 1; \
fi
@echo "Building from work directory for plugin: $(plugin)"
# Change to the work directory to perform build operations
cd work && \
$(MAKE) -f out/Makefile build
# Note: This target builds from the 'work' directory and binaries will be copied to /usr/local/bin.
clean:
rm -rf work
# this target should only be used in the release workflows, running this locally will mutate your source code.
release: validate_plugin validate_version
go run generate/generator.go templates . $(plugin) $(plugin_version) $(plugin_github_url)
if [ ! -z "$(plugin_version)" ]; then \
MAJOR_VERSION=$$(echo $(plugin_version) | grep -o '^v[0-9]\+' || echo "v1") && \
if [ "$$MAJOR_VERSION" = "v1" ] || [ "$$MAJOR_VERSION" = "v0" ]; then \
echo "go get $(plugin_github_url)@$(plugin_version)" && \
go get $(plugin_github_url)@$(plugin_version); \
else \
echo "go get $(plugin_github_url)/$$MAJOR_VERSION@$(plugin_version)" && \
go get $(plugin_github_url)/$$MAJOR_VERSION@$(plugin_version); \
fi; \
fi
go mod tidy
make -f out/Makefile build