Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: output json (#16053)
p0ny680c1a4fc506
diff --git a/action/README.md b/action/README.mdindex 7814cfc55c..ddd4d75719 100644--- a/action/README.md+++ b/action/README.md@@ -26,6 +26,9 @@ This action is configured via command-line flags. Global flags apply to all commThese flags apply to the main `bytebase-action` command and its subcommands (`check`, `rollout`).+- **`--output`**: The output file location. The output file is a JSON file with the created resource names.+ - Default: `""` (empty string)+- **`--url`**: The Bytebase instance URL.- Default: `https://demo.bytebase.com`diff --git a/action/main.go b/action/main.goindex b304f79992..50691a11a2 100644--- a/action/main.go+++ b/action/main.go@@ -2,6 +2,7 @@ package mainimport ("context"+ "encoding/json""fmt""log/slog""net/url"@@ -24,6 +25,7 @@ import (var (Config struct {// bytebase-action flags+ Output stringURL stringServiceAccount stringServiceAccountSecret string@@ -49,10 +51,12 @@ var (Short: "Bytebase action",PersistentPreRunE: validateSharedFlags,}+ outputMap = map[string]string{})func init() {// bytebase-action flags+ cmd.PersistentFlags().StringVar(&Config.Output, "output", "", "Output file location. The output file is a JSON file with the created resource names")cmd.PersistentFlags().StringVar(&Config.URL, "url", "https://demo.bytebase.com", "Bytebase URL")cmd.PersistentFlags().StringVar(&Config.ServiceAccount, "service-account", "[email protected]", "Bytebase Service account")cmd.PersistentFlags().StringVar(&Config.ServiceAccountSecret, "service-account-secret", os.Getenv("BYTEBASE_SERVICE_ACCOUNT_SECRET"), "Bytebase Service account secret")@@ -62,11 +66,12 @@ func init() {// bytebase-action check flagscmdCheck := &cobra.Command{- Use: "check",- Short: "Check the release files",- Args: cobra.NoArgs,- PersistentPreRunE: nil,- RunE: runCheck,+ Use: "check",+ Short: "Check the release files",+ Args: cobra.NoArgs,+ PersistentPreRunE: nil,+ PersistentPostRunE: writeOutputJSON,+ RunE: runCheck,}cmd.AddCommand(cmdCheck)@@ -129,6 +134,27 @@ func validateRolloutFlags(*cobra.Command, []string) error {return nil}+func writeOutputJSON(*cobra.Command, []string) error {+ if Config.Output == "" {+ return nil+ }+ f, err := os.Create(Config.Output)+ if err != nil {+ return errors.Wrapf(err, "failed to create output file: %s", Config.Output)+ }+ defer f.Close()++ j, err := json.Marshal(outputMap)+ if err != nil {+ return errors.Wrapf(err, "failed to marshal output map")+ }++ if _, err := f.Write(j); err != nil {+ return errors.Wrapf(err, "failed to write output file: %s", Config.Output)+ }+ return nil+}+func runCheck(*cobra.Command, []string) error {platform := getJobPlatform()client, err := NewClient(Config.URL, Config.ServiceAccount, Config.ServiceAccountSecret)@@ -186,6 +212,7 @@ func runRollout(command *cobra.Command, _ []string) error {if err != nil {return errors.Wrapf(err, "failed to create release")}+ outputMap["release"] = createReleaseResponse.NameplanPreview, err := client.previewPlan(Config.Project, &v1pb.PreviewPlanRequest{Release: createReleaseResponse.Name,@@ -209,6 +236,7 @@ func runRollout(command *cobra.Command, _ []string) error {if err != nil {return errors.Wrapf(err, "failed to create plan")}+ outputMap["plan"] = planCreated.Nameslog.Info("plan created", "url", fmt.Sprintf("%s/%s", client.url, planCreated.Name))@@ -326,6 +354,7 @@ func runAndWaitForRollout(ctx context.Context, client *Client, planName string)if err != nil {return errors.Wrapf(err, "failed to preview rollout")}+ outputMap["rollout"] = rolloutEmpty.Nameslog.Info("rollout created", "url", fmt.Sprintf("%s/%s", client.url, rolloutEmpty.Name))