Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
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.ymlindex 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:latestbuild-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 }}-debianbytebase/bytebase-action:latest-debianbuild-args: |+ VERSION=${{ env.IMAGE_TAG }}GIT_COMMIT=${{ env.GIT_COMMIT }}\ No newline at end of filediff --git a/action/api.go b/action/api.goindex 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.goindex 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.goindex 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.Planif Config.Plan != "" {planP, err := client.getPlan(Config.Plan)@@ -573,8 +579,38 @@ func waitForRollout(ctx context.Context, client *Client, rolloutPreview *v1pb.Roreturn 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.actionindex 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 VERSIONARG GIT_COMMITWORKDIR /action-buildCOPY 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/*.goFROM alpine:3.22diff --git a/scripts/Dockerfile.action-debian b/scripts/Dockerfile.action-debianindex 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 VERSIONARG GIT_COMMITWORKDIR /action-buildCOPY 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/*.goFROM debian:bookworm-slim