Help us shape the future of Go! Take the 2026 Go Developer Survey

workflow

package
v1.211.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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.

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 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) (*ExecutionResult, 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 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 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