Skip to content

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

feat(action): print version and check server version (#16431)

p0nyc8a472a4d4d2
diff --git a/.github/workflows/build-push-action-image.yml b/.github/workflows/build-push-action-image.yml
index 7c33a600ac..161f078576 100644
--- a/.github/workflows/build-push-action-image.yml
+++ b/.github/workflows/build-push-action-image.yml
@@ -40,6 +40,7 @@ jobs:
bytebase/bytebase-action:${{ env.IMAGE_TAG }}
bytebase/bytebase-action:latest
build-args: |
+ VERSION=${{ env.IMAGE_TAG }}
GIT_COMMIT=${{ env.GIT_COMMIT }}
build-debian:
runs-on: ubuntu-latest
@@ -70,4 +71,5 @@ jobs:
bytebase/bytebase-action:${{ env.IMAGE_TAG }}-debian
bytebase/bytebase-action:latest-debian
build-args: |
+ VERSION=${{ env.IMAGE_TAG }}
GIT_COMMIT=${{ env.GIT_COMMIT }}
\ No newline at end of file
diff --git a/action/api.go b/action/api.go
index 3a96872c75..e6561a31ff 100644
--- a/action/api.go
+++ b/action/api.go
@@ -363,3 +363,19 @@ func (c *Client) batchCancelTaskRuns(r *v1pb.BatchCancelTaskRunsRequest) (*v1pb.
}
return resp, nil
}
+
+func (c *Client) getActuatorInfo() (*v1pb.ActuatorInfo, error) {
+ req, err := http.NewRequest("GET", fmt.Sprintf("%s/v1/actuator/info", c.url), nil)
+ if err != nil {
+ return nil, err
+ }
+ body, err := c.doRequest(req)
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to get actuator info")
+ }
+ resp := &v1pb.ActuatorInfo{}
+ if err := protojsonUnmarshaler.Unmarshal(body, resp); err != nil {
+ return nil, err
+ }
+ return resp, nil
+}
diff --git a/action/args/version.go b/action/args/version.go
index 16597d61bd..831931cc57 100644
--- a/action/args/version.go
+++ b/action/args/version.go
@@ -1,3 +1,6 @@
package args
-var Gitcommit = "unknown"
+var (
+ Gitcommit = "unknown"
+ Version = "unknown"
+)
diff --git a/action/main.go b/action/main.go
index 4803861365..6bc04b13bd 100644
--- a/action/main.go
+++ b/action/main.go
@@ -200,6 +200,9 @@ func runCheck(*cobra.Command, []string) error {
return err
}
+ // Check version compatibility
+ checkVersionCompatibility(client, args.Version)
+
releaseFiles, err := getReleaseFiles(Config.FilePattern)
if err != nil {
return err
@@ -268,6 +271,9 @@ func runRollout(command *cobra.Command, _ []string) error {
return errors.Wrapf(err, "failed to create client")
}
+ // Check version compatibility
+ checkVersionCompatibility(client, args.Version)
+
var plan *v1pb.Plan
if Config.Plan != "" {
planP, err := client.getPlan(Config.Plan)
@@ -573,8 +579,38 @@ func waitForRollout(ctx context.Context, client *Client, rolloutPreview *v1pb.Ro
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)
+ }
+}
+
func main() {
- slog.Info("bytebase-action built at commit " + args.Gitcommit)
+ slog.Info("bytebase-action version " + args.Version + " built at commit " + args.Gitcommit)
ctx, cancel := context.WithCancel(context.Background())
c := make(chan os.Signal, 1)
// Trigger graceful shutdown on SIGINT or SIGTERM.
diff --git a/scripts/Dockerfile.action b/scripts/Dockerfile.action
index ff13224b02..3d0dde073b 100644
--- a/scripts/Dockerfile.action
+++ b/scripts/Dockerfile.action
@@ -1,10 +1,11 @@
FROM golang:1.24.3-alpine3.21 AS builder
+ARG VERSION
ARG GIT_COMMIT
WORKDIR /action-build
COPY action/ action/
COPY . .
RUN go build \
---ldflags="-X 'github.com/bytebase/bytebase/action/args.Gitcommit=${GIT_COMMIT}'" \
+--ldflags="-X 'github.com/bytebase/bytebase/action/args.Version=${VERSION}' -X 'github.com/bytebase/bytebase/action/args.Gitcommit=${GIT_COMMIT}'" \
-o bytebase-action action/*.go
FROM alpine:3.22
diff --git a/scripts/Dockerfile.action-debian b/scripts/Dockerfile.action-debian
index bf42aef08d..eaf0628048 100644
--- a/scripts/Dockerfile.action-debian
+++ b/scripts/Dockerfile.action-debian
@@ -1,10 +1,11 @@
FROM golang:1.24.3-bookworm AS builder
+ARG VERSION
ARG GIT_COMMIT
WORKDIR /action-build
COPY action/ action/
COPY . .
RUN go build \
---ldflags="-X 'github.com/bytebase/bytebase/action/args.Gitcommit=${GIT_COMMIT}'" \
+--ldflags="-X 'github.com/bytebase/bytebase/action/args.Version=${VERSION}' -X 'github.com/bytebase/bytebase/action/args.Gitcommit=${GIT_COMMIT}'" \
-o bytebase-action action/*.go
FROM debian:bookworm-slim