Skip to content

Commit df6ec9d

Browse files
committed
Add support to build steampipe standalone FDW for pre-release versions of plugins
1 parent 883869c commit df6ec9d

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

Makefile

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ install: build
1414
fi
1515

1616
# build standalone
17-
standalone: validate_plugin prebuild.go
17+
standalone: validate_plugin validate_version prebuild.go
1818
@echo "Building standalone FDW for plugin: $(plugin)"
1919

2020
# Remove existing work dir and create a new directory for the render process
@@ -26,7 +26,11 @@ standalone: validate_plugin prebuild.go
2626

2727
# Change to the new directory to perform operations
2828
cd work && \
29-
go run generate/generator.go templates . $(plugin) $(plugin_github_url) && \
29+
go run generate/generator.go templates . $(plugin) $(plugin_version) $(plugin_github_url) && \
30+
if [ ! -z "$(plugin_version)" ]; then \
31+
echo "go get $(plugin_github_url)@$(plugin_version)" && \
32+
go get $(plugin_github_url)@$(plugin_version); \
33+
fi && \
3034
go mod tidy && \
3135
$(MAKE) -C ./fdw clean && \
3236
$(MAKE) -C ./fdw go && \
@@ -43,7 +47,7 @@ standalone: validate_plugin prebuild.go
4347
# binaries will be copied to build-${PLATFORM} folder
4448

4549
# render target
46-
render: validate_plugin prebuild.go
50+
render: validate_plugin validate_version prebuild.go
4751
@echo "Rendering code for plugin: $(plugin)"
4852

4953
# Remove existing work dir and create a new directory for the render process
@@ -55,7 +59,11 @@ render: validate_plugin prebuild.go
5559

5660
# Change to the new directory to perform operations
5761
cd work && \
58-
go run generate/generator.go templates . $(plugin) $(plugin_github_url) && \
62+
go run generate/generator.go templates . $(plugin) $(plugin_version) $(plugin_github_url) && \
63+
if [ ! -z "$(plugin_version)" ]; then \
64+
echo "go get $(plugin_github_url)@$(plugin_version)" && \
65+
go get $(plugin_github_url)@$(plugin_version); \
66+
fi && \
5967
go mod tidy
6068

6169
# Note: The work directory will contain the full code tree with rendered changes
@@ -84,9 +92,17 @@ build_from_work:
8492
# Note: This target builds from the 'work' directory and copies binaries to the build-${PLATFORM} folder
8593

8694
validate_plugin:
87-
ifndef plugin
88-
$(error "You must specify the 'plugin' variable")
89-
endif
95+
ifndef plugin
96+
$(error "The 'plugin' variable is missing. Usage: make build plugin=<plugin_name> [plugin_version=<version>] [plugin_github_url=<url>]")
97+
endif
98+
99+
# Check if plugin_github_url is provided when plugin_version is specified
100+
validate_version:
101+
ifdef plugin_version
102+
ifndef plugin_github_url
103+
$(error "The 'plugin_github_url' variable is required when 'plugin_version' is specified")
104+
endif
105+
endif
90106

91107
build: prebuild.go
92108
$(MAKE) -C ./fdw clean

generate/generator.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515

1616
const templateExt = ".tmpl"
1717

18-
func RenderDir(templatePath, root, plugin, pluginGithubUrl, pgVersion string) {
18+
func RenderDir(templatePath, root, plugin, pluginGithubUrl, pluginVersion, pgVersion string) {
1919
var targetFilePath string
2020
err := filepath.Walk(templatePath, func(filePath string, info os.FileInfo, err error) error {
2121
if err != nil {
@@ -64,10 +64,12 @@ func RenderDir(templatePath, root, plugin, pluginGithubUrl, pgVersion string) {
6464
data := struct {
6565
Plugin string
6666
PluginGithubUrl string
67+
PluginVersion string
6768
PgVersion string
6869
}{
6970
plugin,
7071
pluginGithubUrl,
72+
pluginVersion,
7173
pgVersion,
7274
}
7375

@@ -95,25 +97,35 @@ func RenderDir(templatePath, root, plugin, pluginGithubUrl, pgVersion string) {
9597
func main() {
9698
// Check if the correct number of command-line arguments are provided
9799
if len(os.Args) < 4 {
98-
fmt.Println("Usage: go run generator.go <templatePath> <root> <plugin> [pluginGithubUrl]")
100+
fmt.Println("Usage: go run generator.go <templatePath> <root> <plugin> [plugin_version] [pluginGithubUrl]")
99101
return
100102
}
101103

102104
templatePath := os.Args[1]
103105
root := os.Args[2]
104106
plugin := os.Args[3]
107+
var pluginVersion string
105108
var pluginGithubUrl string
106109

107-
fmt.Println(len(os.Args))
110+
// Check if pluginVersion is provided as a command-line argument
111+
if len(os.Args) >= 5 {
112+
pluginVersion = os.Args[4]
113+
}
108114

109115
// Check if PluginGithubUrl is provided as a command-line argument
110-
if len(os.Args) == 5 {
111-
pluginGithubUrl = os.Args[4]
116+
if len(os.Args) >= 6 {
117+
pluginGithubUrl = os.Args[5]
112118
} else {
113119
// If PluginGithubUrl is not provided, generate it based on PluginAlias
114120
pluginGithubUrl = "github.com/turbot/steampipe-plugin-" + plugin
115121
}
116122

123+
// If pluginVersion is provided but pluginGithubUrl is not, error out
124+
if pluginVersion != "" && pluginGithubUrl == "" {
125+
fmt.Println("Error: plugin_github_url is required when plugin_version is specified")
126+
return
127+
}
128+
117129
// Convert relative paths to absolute paths
118130
absTemplatePath, err := filepath.Abs(templatePath)
119131
if err != nil {
@@ -130,7 +142,7 @@ func main() {
130142
// get the postgres version used
131143
pgVersion := getPostgreSQLVersion()
132144

133-
RenderDir(absTemplatePath, absRoot, plugin, pluginGithubUrl, pgVersion)
145+
RenderDir(absTemplatePath, absRoot, plugin, pluginGithubUrl, pluginVersion, pgVersion)
134146
}
135147

136148
func getPostgreSQLVersion() string {

0 commit comments

Comments
 (0)