workflow

package
v1.223.0-rc.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2026 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ControlFailWaitAll    = "wait_all"
	ControlFailFast       = "fail_fast"
	ControlFailBestEffort = "best_effort"

	ControlOutputGrouped  = "grouped"
	ControlOutputPrefixed = "prefixed"
	ControlOutputNone     = "none"

	ControlOutputCompletion = "completion"
	ControlOutputDefinition = "definition"
)

Variables

This section is empty.

Functions

func CalculateWorkingDirectory added in v1.222.0

func CalculateWorkingDirectory(workflowDef *schema.WorkflowDefinition, step *schema.WorkflowStep, basePath string) string

CalculateWorkingDirectory determines the working directory for a workflow step. Step-level working_directory overrides workflow-level. Relative paths resolve against basePath.

func CancelBackground added in v1.222.0

func CancelBackground(ctx context.Context, reg *background.Registry, names []string) error

CancelBackground gracefully tears down the named background steps and removes them from the registry so the end-of-scope auto-teardown does not stop them again.

func CheckAndGenerateWorkflowStepNames

func CheckAndGenerateWorkflowStepNames(workflowDefinition *schema.WorkflowDefinition)

CheckAndGenerateWorkflowStepNames generates step names for steps that don't have them. If a step doesn't have a name, it generates one in the format "step1", "step2", etc.

func ExecuteControlStep added in v1.222.0

func ExecuteControlStep(ctx context.Context, parent *schema.WorkflowStep, executor ControlChildExecutor, opts ControlExecutionOptions) error

func GatePendingBackground added in v1.222.0

func GatePendingBackground(ctx context.Context, reg *background.Registry, gated map[string]bool) error

GatePendingBackground applies the implicit readiness gate run before each foreground step: it blocks until every registered background step that has not already passed its gate is ready, then records those names in gated so later foreground steps don't re-probe them. A nil/empty registry (or all-gated) is a no-op.

func RunStepContainerOverride added in v1.222.0

func RunStepContainerOverride(ctx context.Context, params *ContainerStepParams) error

RunStepContainerOverride runs a shell step in a one-shot step-level container.

func StartBackground added in v1.222.0

func StartBackground(
	ctx context.Context,
	reg *background.Registry,
	runner background.Runner,
	step *schema.WorkflowStep,
	env []string,
) error

StartBackground launches a background step through the runner and registers its handle. Start is non-blocking: it does not wait on readiness, so consecutive background steps come up concurrently. The implicit readiness gate is applied by the workflow executor before the next foreground step (and by `wait`/`wait-all`), reusing the step's health check via Handle.WaitReady.

func StepContainerDisabled added in v1.222.0

func StepContainerDisabled(step *schema.WorkflowStep) bool

StepContainerDisabled reports whether the step explicitly opts out of the workflow container.

func StepContainerOverride added in v1.222.0

func StepContainerOverride(step *schema.WorkflowStep) bool

StepContainerOverride reports whether the step has an enabled container override.

func WaitAllBackground added in v1.222.0

func WaitAllBackground(ctx context.Context, reg *background.Registry) error

WaitAllBackground blocks until all currently-registered background steps are ready.

func WaitBackground added in v1.222.0

func WaitBackground(ctx context.Context, reg *background.Registry, names []string) error

WaitBackground blocks until every named background step is ready (a service's health check passes). Names are validated upstream, but a missing name is reported rather than silently ignored.

Types

type AtmosExecParams

type AtmosExecParams struct {
	// Ctx is the context for cancellation.
	Ctx context.Context
	// AtmosConfig is the atmos configuration.
	AtmosConfig *schema.AtmosConfiguration
	// Args are command arguments (e.g., ["terraform", "plan", "vpc"]).
	Args []string
	// Dir is the working directory for the command.
	Dir string
	// Env are environment variables for the command.
	Env []string
	// DryRun if true, don't actually execute the command.
	DryRun bool
}

AtmosExecParams holds parameters for executing an atmos command.

type AtmosExecutor

type AtmosExecutor func(params *AtmosExecParams) error

AtmosExecutor is a function type for executing atmos commands. This type allows injecting the actual atmos execution function.

type AuthProvider

type AuthProvider interface {
	// NeedsAuth returns true if authentication is needed for the given steps.
	NeedsAuth(steps []schema.WorkflowStep, commandLineIdentity string) bool

	// Authenticate performs authentication for the given identity.
	// Returns an error if authentication fails.
	Authenticate(ctx context.Context, identity string) error

	// GetCachedCredentials returns cached credentials for the identity.
	// Returns an error if no valid cached credentials are available.
	GetCachedCredentials(ctx context.Context, identity string) (any, error)

	// PrepareEnvironment prepares environment variables for the authenticated identity.
	// Returns the modified environment slice.
	PrepareEnvironment(ctx context.Context, identity string, baseEnv []string) ([]string, error)
}

AuthProvider abstracts authentication operations for workflow steps. This interface enables testing identity-based workflows without real auth providers.

type CommandRunner

type CommandRunner interface {
	// RunShell executes a shell command with the given parameters.
	// Parameters:
	//   - command: The shell command to execute
	//   - name: A name for the command (for logging/identification)
	//   - dir: Working directory for the command
	//   - env: Environment variables for the command
	//   - dryRun: If true, don't actually execute the command
	// Returns an error if the command fails.
	RunShell(command, name, dir string, env []string, dryRun bool) error

	// RunAtmos executes an atmos command with the given parameters.
	// Returns an error if the command fails.
	RunAtmos(params *AtmosExecParams) error
}

CommandRunner abstracts the execution of shell and atmos commands. This interface enables testing workflow logic without spawning real processes.

type ContainerRunner added in v1.222.0

type ContainerRunner struct {
	// Stack scopes the instance label namespace so background steps in different
	// stacks resolve to distinct instances.
	Stack string
	// DryRun skips the actual runtime calls (start/wait/stop become no-ops).
	DryRun bool
}

ContainerRunner starts background container services using Atmos's existing long-lived container lifecycle (Up/WaitHealthy/Down). It implements background.Runner. The container runtime supervises the process, so no goroutine is required.

func (*ContainerRunner) Start added in v1.222.0

Start launches the background container described by the step's `with:` block (step.Run) detached, and returns a handle that waits on its health check and tears it down.

type ContainerSession added in v1.222.0

type ContainerSession struct {
	// contains filtered or unexported fields
}

ContainerSession owns the long-lived container backing a workflow run.

func StartWorkflowContainer added in v1.222.0

func StartWorkflowContainer(ctx context.Context, params *ContainerStepParams) (*ContainerSession, error)

StartWorkflowContainer starts the workflow-level container if configured.

func (*ContainerSession) Cleanup added in v1.222.0

func (s *ContainerSession) Cleanup(success bool) error

Cleanup removes the workflow container according to policy.

func (*ContainerSession) ExecShell added in v1.222.0

func (s *ContainerSession) ExecShell(ctx context.Context, params *ContainerStepParams) error

ExecShell runs a shell command inside the workflow container.

type ContainerStepParams added in v1.222.0

type ContainerStepParams struct {
	Workflow     string
	WorkflowPath string
	BasePath     string
	WorkflowDef  *schema.WorkflowDefinition
	Step         *schema.WorkflowStep
	HostWorkDir  string
	Command      string
	StepEnv      []string
	RuntimeEnv   []string
	DryRun       bool
}

ContainerStepParams carries workflow and step execution inputs for the workflow container entry points. It keeps the public functions within the argument limit and groups related values together.

type ControlChild added in v1.222.0

type ControlChild struct {
	Step   schema.WorkflowStep
	Matrix map[string]string
}

type ControlChildExecutor added in v1.222.0

type ControlChildExecutor func(ctx context.Context, child *ControlChild, output ControlChildOutput) (*ControlChildResult, error)

type ControlChildOutput added in v1.222.0

type ControlChildOutput struct {
	Mode   string
	Prefix string
}

type ControlChildResult added in v1.222.0

type ControlChildResult struct {
	Stdout   string
	Stderr   string
	Canceled bool
}

type ControlCommandExecutor added in v1.222.0

type ControlCommandExecutor struct {
	WorkflowDefinition  *schema.WorkflowDefinition
	BaseEnv             []string
	CommandLineStack    string
	CommandLineIdentity string
	PrepareEnv          ControlEnvironmentFunc
	RunCommand          ControlCommandRunner
	// contains filtered or unexported fields
}

func (*ControlCommandExecutor) Execute added in v1.222.0

type ControlCommandRequest added in v1.222.0

type ControlCommandRequest struct {
	Context context.Context
	Program string
	Args    []string
	Env     []string
	Streams process.Streams
	Stdout  *bytes.Buffer
	Stderr  *bytes.Buffer
}

type ControlCommandRunner added in v1.222.0

type ControlCommandRunner func(request *ControlCommandRequest) error

type ControlEnvironmentFunc added in v1.222.0

type ControlEnvironmentFunc func(baseEnv []string, identity string, stepName string, workflowEnv map[string]string, stepEnv map[string]string) ([]string, error)

type ControlExecutionOptions added in v1.222.0

type ControlExecutionOptions struct {
	TemplateData ControlTemplateDataFunc
	StoreResult  ControlStoreResultFunc
}

type ControlResult added in v1.222.0

type ControlResult struct {
	Name      string
	Stdout    string
	Stderr    string
	Status    string
	Err       error
	Canceled  bool
	Completed int64
}

type ControlStoreResultFunc added in v1.222.0

type ControlStoreResultFunc func(result *scheduler.Result)

type ControlTemplateDataFunc added in v1.222.0

type ControlTemplateDataFunc func(stepName string, matrix map[string]string) map[string]any

type DefaultCommandRunner

type DefaultCommandRunner struct {
	// contains filtered or unexported fields
}

DefaultCommandRunner is the default implementation of CommandRunner that delegates to the provided shell and atmos execution functions. This is designed for dependency injection - the actual execution functions must be provided by the caller (typically from internal/exec).

func NewDefaultCommandRunner

func NewDefaultCommandRunner(shellExec ShellExecutor, atmosExec AtmosExecutor) *DefaultCommandRunner

NewDefaultCommandRunner creates a new DefaultCommandRunner with the given executors. Both executors should be provided - nil executors will result in ErrNilParam being returned.

func (*DefaultCommandRunner) RunAtmos

func (r *DefaultCommandRunner) RunAtmos(params *AtmosExecParams) error

RunAtmos executes an atmos command using the configured atmos executor.

func (*DefaultCommandRunner) RunShell

func (r *DefaultCommandRunner) RunShell(command, name, dir string, env []string, dryRun bool) error

RunShell executes a shell command using the configured shell executor.

type DefaultDependencyProvider added in v1.204.0

type DefaultDependencyProvider struct {
	// contains filtered or unexported fields
}

DefaultDependencyProvider implements DependencyProvider using the real dependencies package.

func NewDefaultDependencyProvider added in v1.204.0

func NewDefaultDependencyProvider(atmosConfig *schema.AtmosConfiguration) *DefaultDependencyProvider

NewDefaultDependencyProvider creates a new DefaultDependencyProvider.

func (*DefaultDependencyProvider) EnsureTools added in v1.204.0

func (p *DefaultDependencyProvider) EnsureTools(deps map[string]string) error

EnsureTools ensures all required tools are installed.

func (*DefaultDependencyProvider) LoadToolVersionsDependencies added in v1.204.0

func (p *DefaultDependencyProvider) LoadToolVersionsDependencies() (map[string]string, error)

LoadToolVersionsDependencies loads tools from .tool-versions file.

func (*DefaultDependencyProvider) MergeDependencies added in v1.204.0

func (p *DefaultDependencyProvider) MergeDependencies(base, overlay map[string]string) (map[string]string, error)

MergeDependencies merges two dependency maps, with overlay taking precedence.

func (*DefaultDependencyProvider) ResolveWorkflowDependencies added in v1.204.0

func (p *DefaultDependencyProvider) ResolveWorkflowDependencies(workflowDef *schema.WorkflowDefinition) (map[string]string, error)

ResolveWorkflowDependencies extracts tool dependencies from a workflow definition.

func (*DefaultDependencyProvider) UpdatePathForTools added in v1.204.0

func (p *DefaultDependencyProvider) UpdatePathForTools(deps map[string]string) error

UpdatePathForTools updates PATH to include tool binaries.

type DependencyProvider added in v1.204.0

type DependencyProvider interface {
	// LoadToolVersionsDependencies loads tools from .tool-versions file.
	// Returns an empty map if the file doesn't exist.
	LoadToolVersionsDependencies() (map[string]string, error)

	// ResolveWorkflowDependencies extracts tool dependencies from a workflow definition.
	ResolveWorkflowDependencies(workflowDef *schema.WorkflowDefinition) (map[string]string, error)

	// MergeDependencies merges two dependency maps, with overlay taking precedence.
	MergeDependencies(base, overlay map[string]string) (map[string]string, error)

	// EnsureTools ensures all required tools are installed.
	EnsureTools(dependencies map[string]string) error

	// UpdatePathForTools updates PATH to include tool binaries.
	UpdatePathForTools(dependencies map[string]string) error
}

DependencyProvider abstracts toolchain dependency resolution and installation. This interface enables testing workflow execution without actual tool installation.

type ExecuteOptions

type ExecuteOptions struct {
	// DryRun if true, commands are not actually executed.
	DryRun bool

	// CommandLineStack overrides the stack for all steps.
	CommandLineStack string

	// FromStep skips steps until this step name is reached.
	FromStep string

	// CommandLineIdentity sets the identity for steps without explicit identity.
	CommandLineIdentity string
}

ExecuteOptions contains options for workflow execution.

type ExecutionResult

type ExecutionResult struct {
	// WorkflowName is the name of the workflow.
	WorkflowName string

	// Steps contains results for each step.
	Steps []StepResult

	// Success indicates whether all steps succeeded.
	Success bool

	// Error is the first error encountered, if any.
	Error error

	// ResumeCommand is the command to resume from the failed step.
	ResumeCommand string
}

ExecutionResult represents the result of executing a complete workflow.

type Executor

type Executor struct {
	// contains filtered or unexported fields
}

Executor handles workflow execution with dependency injection for testing.

func NewExecutor

func NewExecutor(runner CommandRunner, authProvider AuthProvider, ui UIProvider) *Executor

NewExecutor creates a new Executor with the given dependencies. Nil dependencies are handled gracefully: runner is required for command execution, authProvider can be nil if no authentication is needed, ui can be nil to disable user-facing output, and depProvider can be nil to skip toolchain integration.

func (*Executor) Execute

func (e *Executor) Execute(params *WorkflowParams) (result *ExecutionResult, err error)

Execute runs a workflow with the given options. This is the main entry point for workflow execution.

func (*Executor) WithDependencyProvider added in v1.204.0

func (e *Executor) WithDependencyProvider(provider DependencyProvider) *Executor

WithDependencyProvider sets a custom DependencyProvider (primarily for testing).

type ProgressRenderer added in v1.221.0

type ProgressRenderer struct {
	// contains filtered or unexported fields
}

ProgressRenderer handles progress bar rendering for workflow execution. It displays a right-aligned progress bar showing step completion status. Each step gets its own progress line showing current position in the workflow.

func NewProgressRenderer added in v1.221.0

func NewProgressRenderer(workflow *schema.WorkflowDefinition, totalSteps int) *ProgressRenderer

NewProgressRenderer creates a new progress renderer for workflow execution. Returns nil if progress display is disabled or terminal doesn't support TTY.

func (*ProgressRenderer) Done added in v1.221.0

func (r *ProgressRenderer) Done()

Done marks the progress as complete. This can be used to clean up or render a final state.

func (*ProgressRenderer) IsEnabled added in v1.221.0

func (r *ProgressRenderer) IsEnabled() bool

IsEnabled returns whether progress rendering is enabled.

func (*ProgressRenderer) Render deprecated added in v1.221.0

func (r *ProgressRenderer) Render()

Render renders the progress bar with just the step name on the left. Format: stepName ... [████░░░] n/m

Deprecated: Use RenderWithLabel for combined step label + progress.

func (*ProgressRenderer) RenderPermanent added in v1.221.0

func (r *ProgressRenderer) RenderPermanent(stepLabel string)

RenderPermanent renders the progress bar WITH newline as a permanent record. Call this after step execution completes to preserve the progress line.

func (*ProgressRenderer) RenderWithLabel added in v1.221.0

func (r *ProgressRenderer) RenderWithLabel(stepLabel string)

RenderWithLabel renders the progress bar with the step label on the left. Format: 1/5 stepname ... [████░░░] n/m Renders WITHOUT newline for in-place display. Call ui.ClearLine() before any step output, then RenderPermanent() after step completes.

func (*ProgressRenderer) Update added in v1.221.0

func (r *ProgressRenderer) Update(current int, stepName string)

Update updates the progress to the current step.

type ShellExecutor

type ShellExecutor func(command, name, dir string, env []string, dryRun bool) error

ShellExecutor is a function type for executing shell commands. This type allows injecting the actual shell execution function.

type ShowRenderer added in v1.221.0

type ShowRenderer struct {
	// contains filtered or unexported fields
}

ShowRenderer handles rendering of show features for workflows.

func NewShowRenderer added in v1.221.0

func NewShowRenderer() *ShowRenderer

NewShowRenderer creates a new ShowRenderer.

func (*ShowRenderer) RenderHeaderIfNeeded added in v1.221.0

func (r *ShowRenderer) RenderHeaderIfNeeded(
	workflow *schema.WorkflowDefinition,
	workflowName string,
	flags map[string]string,
)

RenderHeaderIfNeeded renders the workflow header and flags if configured and not already rendered. This should be called before the first step executes.

type StepResult

type StepResult struct {
	// StepName is the name of the step.
	StepName string

	// Command is the command that was executed.
	Command string

	// Success indicates whether the step succeeded.
	Success bool

	// Error is the error if the step failed.
	Error error

	// Skipped indicates if the step was skipped (e.g., due to --from-step).
	Skipped bool
}

StepResult represents the result of executing a single workflow step.

type UIProvider

type UIProvider interface {
	// PrintMessage prints a message to the user.
	PrintMessage(format string, args ...any)

	// PrintError prints an error message to the user.
	PrintError(err error, title, explanation string)
}

UIProvider abstracts user interface operations for workflows. This interface enables testing without terminal interaction.

type WorkflowLoader

type WorkflowLoader interface {
	// LoadWorkflow loads a workflow definition from the given path.
	// Parameters:
	//   - atmosConfig: The atmos configuration
	//   - workflowPath: Path to the workflow file
	//   - workflowName: Name of the workflow to load
	// Returns the workflow definition and any error.
	LoadWorkflow(atmosConfig *schema.AtmosConfiguration, workflowPath, workflowName string) (*schema.WorkflowDefinition, error)

	// ListWorkflows returns all available workflows.
	ListWorkflows(atmosConfig *schema.AtmosConfiguration) ([]schema.DescribeWorkflowsItem, error)
}

WorkflowLoader abstracts loading and parsing workflow definitions. This interface enables testing without file system access.

type WorkflowParams

type WorkflowParams struct {
	// Ctx is the context for cancellation.
	Ctx context.Context
	// AtmosConfig is the atmos configuration.
	AtmosConfig *schema.AtmosConfiguration
	// Workflow is the name of the workflow.
	Workflow string
	// WorkflowPath is the path to the workflow file.
	WorkflowPath string
	// WorkflowDefinition is the parsed workflow definition.
	WorkflowDefinition *schema.WorkflowDefinition
	// Opts are the execution options.
	Opts ExecuteOptions
}

WorkflowParams contains parameters for workflow execution.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL