workflow

package
v1.222.0-rc.12 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

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 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 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 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.

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 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 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