Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

refactor: action pkgs (#16804)

p0ny68eee7f01133
diff --git a/action/api.go b/action/command/api.go
similarity index 99%
rename from action/api.go
rename to action/command/api.go
index e6561a31ff..57b0d2da59 100644
--- a/action/api.go
+++ b/action/command/api.go
@@ -1,4 +1,4 @@
-package main
+package command
import (
"bytes"
diff --git a/action/azure_devops.go b/action/command/azure_devops.go
similarity index 98%
rename from action/azure_devops.go
rename to action/command/azure_devops.go
index 74d901ca59..381629c6df 100644
--- a/action/azure_devops.go
+++ b/action/command/azure_devops.go
@@ -1,4 +1,4 @@
-package main
+package command
import (
"fmt"
diff --git a/action/bitbucket.go b/action/command/bitbucket.go
similarity index 99%
rename from action/bitbucket.go
rename to action/command/bitbucket.go
index 48a8d7b9c9..e52b1425c5 100644
--- a/action/bitbucket.go
+++ b/action/command/bitbucket.go
@@ -1,4 +1,4 @@
-package main
+package command
import (
"bytes"
diff --git a/action/check_cmd.go b/action/command/check.go
similarity index 99%
rename from action/check_cmd.go
rename to action/command/check.go
index 5f0ba2ef53..cb66b89877 100644
--- a/action/check_cmd.go
+++ b/action/command/check.go
@@ -1,4 +1,4 @@
-package main
+package command
import (
"log/slog"
diff --git a/action/file.go b/action/command/file.go
similarity index 98%
rename from action/file.go
rename to action/command/file.go
index e8a3cd05dd..df79817413 100644
--- a/action/file.go
+++ b/action/command/file.go
@@ -1,4 +1,4 @@
-package main
+package command
import (
"log/slog"
diff --git a/action/file_test.go b/action/command/file_test.go
similarity index 99%
rename from action/file_test.go
rename to action/command/file_test.go
index 70eebe1c79..c235ff66ac 100644
--- a/action/file_test.go
+++ b/action/command/file_test.go
@@ -1,4 +1,4 @@
-package main
+package command
import (
"testing"
diff --git a/action/gitlab.go b/action/command/gitlab.go
similarity index 99%
rename from action/gitlab.go
rename to action/command/gitlab.go
index 719efbddde..4e1f3a7127 100644
--- a/action/gitlab.go
+++ b/action/command/gitlab.go
@@ -1,4 +1,4 @@
-package main
+package command
import (
"encoding/json"
diff --git a/action/platform.go b/action/command/platform.go
similarity index 98%
rename from action/platform.go
rename to action/command/platform.go
index a5c96a741e..b2f5c2c630 100644
--- a/action/platform.go
+++ b/action/command/platform.go
@@ -1,4 +1,4 @@
-package main
+package command
import "os"
diff --git a/action/rollout_cmd.go b/action/command/rollout.go
similarity index 99%
rename from action/rollout_cmd.go
rename to action/command/rollout.go
index 2135284ace..c49a5a1e48 100644
--- a/action/rollout_cmd.go
+++ b/action/command/rollout.go
@@ -1,4 +1,4 @@
-package main
+package command
import (
"context"
diff --git a/action/root_cmd.go b/action/command/root.go
similarity index 76%
rename from action/root_cmd.go
rename to action/command/root.go
index 08a7ea6225..9a300c5656 100644
--- a/action/root_cmd.go
+++ b/action/command/root.go
@@ -1,4 +1,4 @@
-package main
+package command
import (
"encoding/json"
@@ -99,3 +99,33 @@ func writeOutputJSON(w *world.World) func(cmd *cobra.Command, args []string) err
return nil
}
}
+
+func checkVersionCompatibility(client *Client, cliVersion string) {
+ if cliVersion == "unknown" {
+ slog.Warn("CLI version unknown, unable to check compatibility")
+ return
+ }
+
+ actuatorInfo, err := client.getActuatorInfo()
+ if err != nil {
+ slog.Warn("Unable to get server version for compatibility check", "error", err)
+ return
+ }
+
+ serverVersion := actuatorInfo.Version
+ if serverVersion == "" {
+ slog.Warn("Server version is empty, unable to check compatibility")
+ return
+ }
+
+ if cliVersion == "latest" {
+ slog.Warn("Using 'latest' CLI version. It is recommended to use a specific version like bytebase-action:" + serverVersion + " to match your Bytebase server version " + serverVersion)
+ return
+ }
+
+ if cliVersion != serverVersion {
+ slog.Warn("CLI version mismatch", "cliVersion", cliVersion, "serverVersion", serverVersion, "recommendation", "use bytebase-action:"+serverVersion+" to match your Bytebase server")
+ } else {
+ slog.Info("CLI version matches server version", "version", cliVersion)
+ }
+}
diff --git a/action/main.go b/action/main.go
index e6d4758720..1c7d1d7bdd 100644
--- a/action/main.go
+++ b/action/main.go
@@ -9,40 +9,11 @@ import (
"syscall"
"github.com/bytebase/bytebase/action/args"
+ "github.com/bytebase/bytebase/action/command"
"github.com/bytebase/bytebase/action/world"
"github.com/bytebase/bytebase/backend/common/log"
)
-func checkVersionCompatibility(client *Client, cliVersion string) {
- if cliVersion == "unknown" {
- slog.Warn("CLI version unknown, unable to check compatibility")
- return
- }
-
- actuatorInfo, err := client.getActuatorInfo()
- if err != nil {
- slog.Warn("Unable to get server version for compatibility check", "error", err)
- return
- }
-
- serverVersion := actuatorInfo.Version
- if serverVersion == "" {
- slog.Warn("Server version is empty, unable to check compatibility")
- return
- }
-
- if cliVersion == "latest" {
- slog.Warn("Using 'latest' CLI version. It is recommended to use a specific version like bytebase-action:" + serverVersion + " to match your Bytebase server version " + serverVersion)
- return
- }
-
- if cliVersion != serverVersion {
- slog.Warn("CLI version mismatch", "cliVersion", cliVersion, "serverVersion", serverVersion, "recommendation", "use bytebase-action:"+serverVersion+" to match your Bytebase server")
- } else {
- slog.Info("CLI version matches server version", "version", cliVersion)
- }
-}
-
func main() {
slog.Info("bytebase-action version " + args.Version + " built at commit " + args.Gitcommit)
ctx, cancel := context.WithCancel(context.Background())
@@ -58,7 +29,7 @@ func main() {
}()
w := world.NewWorld()
- cmd := NewRootCommand(w)
+ cmd := command.NewRootCommand(w)
if err := cmd.ExecuteContext(ctx); err != nil {
slog.Error("failed to execute command", log.BBError(err))