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): job summary (#17364)
p0ny94a053b823d9
diff --git a/action/command/rollout.go b/action/command/rollout.goindex 97e438288b..0401a33dae 100644--- a/action/command/rollout.go+++ b/action/command/rollout.go@@ -58,7 +58,7 @@ func rolloutPreRun(w *world.World) func(*cobra.Command, []string) error {func runRollout(w *world.World) func(command *cobra.Command, _ []string) error {return func(command *cobra.Command, _ []string) error {defer func() {- writeOutputJSON(w)+ postRun(w)}()w.IsRollout = truectx := command.Context()@@ -228,6 +228,7 @@ func runAndWaitForRollout(ctx context.Context, w *world.World, client *Client, pfor _, stage := range rolloutPreview.Stages {pendingStages = append(pendingStages, stage.Environment)}+ w.PendingStages = pendingStages// create rollout with no stages to obtain the rollout nameemptyTarget := ""@@ -243,6 +244,7 @@ func runAndWaitForRollout(ctx context.Context, w *world.World, client *Client, preturn errors.Wrapf(err, "failed to preview rollout")}w.OutputMap.Rollout = rolloutEmpty.Name+ w.Rollout = rolloutEmptyw.Logger.Info("rollout created", "url", fmt.Sprintf("%s/%s", client.url, rolloutEmpty.Name))@@ -379,6 +381,7 @@ func waitForRollout(ctx context.Context, w *world.World, client *Client, pending}rollout = rolloutAdvanced}+ w.Rollout = rolloutif i >= len(rollout.GetStages()) {return errors.Errorf("rollout has no more stages")}diff --git a/action/command/root.go b/action/command/root.goindex 9c96433573..47186036f8 100644--- a/action/command/root.go+++ b/action/command/root.go@@ -20,6 +20,7 @@ import ("github.com/bytebase/bytebase/action/common""github.com/bytebase/bytebase/action/world"+ v1pb "github.com/bytebase/bytebase/backend/generated-go/v1")func NewRootCommand(w *world.World) *cobra.Command {@@ -105,7 +106,7 @@ func rootPreRun(w *world.World) func(cmd *cobra.Command, args []string) error {}}-func writeOutputJSON(w *world.World) {+func postRun(w *world.World) {if err := func() error {if w.Output == "" {return nil@@ -138,6 +139,193 @@ func writeOutputJSON(w *world.World) {}(); err != nil {w.Logger.Error("failed to write output JSON", "error", err)}+ if err := func() error {+ if w.Platform == world.GitHub && w.IsRollout {+ filename := os.Getenv("GITHUB_STEP_SUMMARY")+ f, err := os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)+ if err != nil {+ return errors.Wrapf(err, "failed to open GitHub step summary file: %s", filename)+ }+ defer f.Close()++ summary := buildSummaryMarkdown(w)+ if _, err := f.WriteString(summary); err != nil {+ return errors.Wrapf(err, "failed to write GitHub step summary: %s", filename)+ }+ return nil+ }+ return nil+ }(); err != nil {+ w.Logger.Error("failed to write GitHub step summary", "error", err)+ }+}++func buildSummaryMarkdown(w *world.World) string {+ var sb strings.Builder+ if w.OutputMap.Release != "" {+ _, _ = sb.WriteString("Release: " + w.URL + "/" + w.OutputMap.Release + "\n")+ }+ if w.OutputMap.Plan != "" {+ _, _ = sb.WriteString("Plan: " + w.URL + "/" + w.OutputMap.Plan + "\n")+ }+ if w.OutputMap.Rollout != "" {+ _, _ = sb.WriteString("Rollout: " + w.URL + "/" + w.OutputMap.Rollout + "\n")+ }++ // Add stage status table+ buildOutputStagesMarkdown(w, &sb)++ return sb.String()+}++func buildOutputStagesMarkdown(w *world.World, sb *strings.Builder) {+ if w.IsRollout && w.Rollout != nil {+ pendingStages := w.PendingStages+ rollout := w.Rollout+ // build a table of stage and status in GitHub flavored markdown.+ // The stages come from the aggregated result of pendingStages and rollout.Stages.+ // pendingStages are the stages to be rolled out at the beginning of the execution,+ // they may or may not have been executed (depending on the targetStage input).+ // rollout.Stages are the stages that have been executed, and the stage status is+ // an aggregated status from stage tasks.++ // Combine stages from rollout.Stages and pendingStages, deduplicating+ allStages := []string{}+ seenStages := make(map[string]bool)++ // First add all stages from rollout.Stages+ for _, stage := range rollout.Stages {+ if !seenStages[stage.Environment] {+ allStages = append(allStages, stage.Environment)+ seenStages[stage.Environment] = true+ }+ }++ // Then append pendingStages that aren't already in the list+ for _, stage := range pendingStages {+ if !seenStages[stage] {+ allStages = append(allStages, stage)+ seenStages[stage] = true+ }+ }++ // Check if there are any stages to display+ if len(allStages) == 0 {+ sb.WriteString("\n### Rollout Stages\n\n")+ sb.WriteString("_No stages to display. The rollout may not have any stages._\n\n")+ return+ }++ // Create a map of stage environment to Stage object for quick lookup+ stageMap := make(map[string]*v1pb.Stage)+ for _, stage := range rollout.Stages {+ stageMap[stage.Environment] = stage+ }++ // Build the markdown table+ sb.WriteString("\n### Rollout Stages\n\n")+ sb.WriteString("| Stage | Status |\n")+ sb.WriteString("|-------|--------|\n")++ // Output all stages with their status+ for _, stageEnv := range allStages {+ stageName := extractStageName(stageEnv)++ // Determine status+ var status string+ if stage, exists := stageMap[stageEnv]; exists {+ // Stage exists in rollout, get its aggregated status+ status = getAggregatedStageStatus(stage)+ } else {+ // Stage is only in pendingStages, mark as pending+ status = "⏳ Pending"+ }++ sb.WriteString("| ")+ sb.WriteString(stageName)+ sb.WriteString(" | ")+ sb.WriteString(status)+ sb.WriteString(" |\n")+ }++ sb.WriteString("\n")+ }+}++// getAggregatedStageStatus determines the overall status of a stage based on its tasks+func getAggregatedStageStatus(stage *v1pb.Stage) string {+ if stage == nil || len(stage.Tasks) == 0 {+ return "⏳ Pending"+ }++ hasRunning := false+ hasFailed := false+ hasCanceled := false+ hasSkipped := false+ hasPending := false+ hasNotStarted := false+ allDone := true++ for _, task := range stage.Tasks {+ switch task.Status {+ case v1pb.Task_RUNNING:+ hasRunning = true+ allDone = false+ case v1pb.Task_FAILED:+ hasFailed = true+ allDone = false+ case v1pb.Task_CANCELED:+ hasCanceled = true+ allDone = false+ case v1pb.Task_SKIPPED:+ hasSkipped = true+ case v1pb.Task_PENDING:+ hasPending = true+ allDone = false+ case v1pb.Task_NOT_STARTED, v1pb.Task_STATUS_UNSPECIFIED:+ hasNotStarted = true+ allDone = false+ case v1pb.Task_DONE:+ // Task is done+ default:+ allDone = false+ }+ }++ // Determine overall stage status based on task statuses+ if hasFailed {+ return "❌ Failed"+ }+ if hasCanceled {+ return "⛔ Canceled"+ }+ if hasRunning {+ return "🔄 Running"+ }+ if hasPending {+ return "⏳ Pending"+ }+ if hasNotStarted {+ return "⏸️ Not Started"+ }+ if allDone && !hasSkipped {+ return "✅ Done"+ }+ if allDone && hasSkipped {+ return "⏭️ Skipped"+ }++ return "⏳ Pending"+}++// extractStageName extracts the stage name from the environment path+func extractStageName(environment string) string {+ // Format: environments/{environment}+ parts := strings.Split(environment, "/")+ if len(parts) >= 2 {+ return parts[len(parts)-1]+ }+ return environment}func checkVersionCompatibility(w *world.World, client *Client, cliVersion string) {diff --git a/action/world/world.go b/action/world/world.goindex 840f373d15..70552cdabb 100644--- a/action/world/world.go+++ b/action/world/world.go@@ -3,6 +3,8 @@ package worldimport ("log/slog""time"++ v1pb "github.com/bytebase/bytebase/backend/generated-go/v1")// World is the world environment for bytebase-action.@@ -46,11 +48,14 @@ type World struct {TargetStage stringPlan string+ // OutputsOutputMap struct {Release string `json:"release,omitempty"`Plan string `json:"plan,omitempty"`Rollout string `json:"rollout,omitempty"`}+ PendingStages []string+ Rollout *v1pb.Rollout}func NewWorld() *World {