Skip to content

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

2.0 KB
Raw Blame
package world

import (
	"log/slog"
	"net/http"
	"time"

	v1pb "github.com/bytebase/bytebase/backend/generated-go/v1"
)

// World is the world environment for bytebase-action.
type World struct {
	Logger      *slog.Logger
	Platform    JobPlatform
	CurrentTime time.Time

	// Whether it is the rollout subcommand.
	IsRollout bool
	// How long the rollout subcommand waits between status polls. Not a flag:
	// releases keep the default, and the workflow tests shorten it.
	RolloutPollInterval time.Duration

	// bytebase-action flags
	Output               string
	URL                  string
	Timeout              time.Duration
	ServiceAccount       string
	ServiceAccountSecret string
	AccessToken          string // Alternative to service account auth, e.g. from workload identity exchange
	CustomHeaders        http.Header
	CustomHeaderError    error
	Project              string // projects/{project}
	Targets              []string
	FilePattern          string
	// Whether to use declarative mode.
	Declarative bool

	// bytebase-action check flags
	// An enum to determine should we fail on warning or error.
	// Valid values:
	// - SKIP
	// - FAIL_ON_WARNING
	// - FAIL_ON_ERROR
	CheckRelease string
	// Custom linting rules in natural language for AI-powered validation.
	CustomRules string

	// bytebase-action rollout flags
	// Rollout up to the target-stage.
	// Format: environments/{environment}
	TargetStage       string
	Plan              string
	ReleaseIDTemplate string // Template for release ID
	ReleaseIDTimezone string // Timezone for release ID variables

	// Outputs
	OutputMap struct {
		Release      string                     `json:"release,omitempty"`
		Plan         string                     `json:"plan,omitempty"`
		Rollout      string                     `json:"rollout,omitempty"`
		CheckResults *v1pb.CheckReleaseResponse `json:"checkResults,omitempty"`
	}
	Rollout *v1pb.Rollout
}

func NewWorld() *World {
	return &World{
		CurrentTime:         time.Now(),
		Logger:              slog.Default(),
		RolloutPollInterval: 5 * time.Second,
	}
}