flow

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package flow implements a declarative automation pipeline runner. Flows are defined in YAML files and consist of sequential steps that invoke cloop subcommands with optional conditions and failure policies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuiltinTemplates

func BuiltinTemplates() map[string]*Flow

BuiltinTemplates returns all built-in flow templates keyed by name.

func ListFlows

func ListFlows(workDir string) ([]string, error)

ListFlows returns all .yaml / .yml files found in the flows directory (.cloop/flows/ relative to workDir).

func MarshalYAML

func MarshalYAML(f *Flow) ([]byte, error)

MarshalYAML serialises a Flow to a YAML byte slice with a header comment.

Types

type Flow

type Flow struct {
	// Name is a human-readable title for the pipeline.
	Name string `yaml:"name"`

	// Description is an optional longer description of the pipeline's purpose.
	Description string `yaml:"description,omitempty"`

	// Steps is the ordered list of pipeline steps.
	Steps []FlowStep `yaml:"steps"`
}

Flow is the top-level structure parsed from a flow YAML file.

func ExampleFlow

func ExampleFlow() *Flow

ExampleFlow returns a sample Flow struct that can be serialised to YAML.

func Load

func Load(path string) (*Flow, error)

Load reads and parses a Flow from the given YAML file path. The read is bounded by maxFlowYAMLBytes — a runaway file (e.g. a multi-GB blob in .cloop/flows/, or a user-supplied path pointing at the wrong artifact) is rejected with *boundedread.SizeError before any payload is loaded.

func ReleaseFlow

func ReleaseFlow() *Flow

ReleaseFlow returns the built-in release pipeline template.

func ReviewFlow

func ReviewFlow() *Flow

ReviewFlow returns the built-in review pipeline template.

type FlowStep

type FlowStep struct {
	// Name is a human-readable label for the step.
	Name string `yaml:"name"`

	// Command is the cloop subcommand to invoke (e.g., "lint", "run", "report").
	Command string `yaml:"command"`

	// Args are extra arguments passed to the cloop subcommand.
	Args []string `yaml:"args,omitempty"`

	// If is a shell condition evaluated before executing the step.
	// The step is skipped when the condition exits non-zero.
	// Example: "test -f go.mod"
	If string `yaml:"if,omitempty"`

	// OnFailure controls behaviour when the step's Command fails.
	// Valid values: "continue" (default), "abort", "retry".
	OnFailure OnFailurePolicy `yaml:"on_failure,omitempty"`

	// Env holds extra environment variables injected for this step only.
	Env map[string]string `yaml:"env,omitempty"`

	// MaxRetries is the number of additional attempts when OnFailure is "retry".
	// Defaults to 2.
	MaxRetries int `yaml:"max_retries,omitempty"`
}

FlowStep represents a single step in an automation pipeline.

type OnFailurePolicy

type OnFailurePolicy string

OnFailurePolicy controls what happens when a step fails.

const (
	OnFailureContinue OnFailurePolicy = "continue"
	OnFailureAbort    OnFailurePolicy = "abort"
	OnFailureRetry    OnFailurePolicy = "retry"
)

type RunConfig

type RunConfig struct {
	// WorkDir is the directory from which cloop commands are executed.
	WorkDir string

	// CloopBin is the path to the cloop binary. Defaults to the current executable.
	CloopBin string

	// DryRun prints commands without executing them.
	DryRun bool

	// Stdout and Stderr for step output. Defaults to os.Stdout/Stderr.
	Stdout *os.File
	Stderr *os.File
}

RunConfig controls the behaviour of Run.

type StepResult

type StepResult struct {
	StepName string
	Skipped  bool
	Err      error
	Duration time.Duration
	Attempts int
}

StepResult captures the outcome of a single step execution.

func Run

func Run(ctx context.Context, flow *Flow, cfg RunConfig) ([]StepResult, error)

Run executes the flow sequentially, honouring step conditions and failure policies. It returns a slice of StepResults (one per step) and a combined error if any step caused the pipeline to abort.

Jump to

Keyboard shortcuts

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