workflow

package
v0.16.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidType = errors.New("invalid type")
)

Functions

func Always

func Always(ctx Context) (bool, error)

Always will always run.

func GetAnyInput

func GetAnyInput(ctx Context, name string, required bool) (any, error)

GetAnyInput returns a value or output in the ctx. If a value does not exist, nil is returned, with a nil error unless required is true.

func GetAnyValue

func GetAnyValue(ctx Context, name string) (any, bool)

GetAnyValue returns a value or output in the ctx.

func GetInput

func GetInput[T any](ctx Context, name string, required bool) (T, error)

GetInput returns a value or output in the ctx. If a value does not exist, the type's zero value is returned, with a nil error unless required is true.

func GetValue

func GetValue[T any](ctx Context, name string) (T, error)

GetValue returns a value or output in the ctx. If a value does not exist, the type's zero value is returned, with a nil error.

Types

type Command

type Command func(ctx Context)

Command represents a side effect of a step. A step can return a command, which will then be executed after the stes completes. This enables a step to define outputs, values and more.

func Batch

func Batch(commands ...Command) Command

func SetOutput

func SetOutput(key string, value any) Command

SetOutput returns a Command that will store an output. Setting an output from a step without an ID is a no-op. Outputs are named depending on their scope. Within the same job, a step will be named like so:

"step.<stepId>.<key>"

From another job, the output can be referenced like so:

"job.<jobId>.step.<stepId>.<key>"

func SetValue

func SetValue(key string, value any) Command

SetValue returns a Command that will store value in key.

type Condition

type Condition = any

Condition controls whether or not a job or step (or post step) should run. A condition can be either a ConditionFunc, or a string which references a value retrievable using GetValue.

func ValueExists added in v0.13.0

func ValueExists(key string) Condition

ValueExists will evaluate to true if the given key has a value.

type ConditionFunc

type ConditionFunc = func(ctx Context) (bool, error)

ConditionFunc is an adapter to allow the use of ordinary functions as Conditions.

type Context

type Context struct {
	context.Context

	// Workflow is the current workflow.
	Workflow Workflow
	// Job is the current job.
	Job Job
	// Step is the current step.
	Step Step

	// Outputs holds the outputs of steps and jobs, mapped by their path.
	// Outputs should not be written directly, as they are managed by the workflow
	// runtime.
	// Example:
	//   ctx.Outputs["step.getManifests.manifests"]
	//   ctx.Outputs["jobs.oci.step.getManifests.manifests"]
	Outputs map[string]any

	// Values holds values (variables) stored by calling Store on a step to store
	// a named output. Values can later be used as inputs.
	// Values should not be written directly, as they are managed by the workflow
	// runtime.
	// Example:
	//    FetchTitlesFromIMDB().Store("titles", "movieTitles")
	//    CreateReportFromTitles("movieTitles")
	Values map[string]any

	// Error holds any current error of the context.
	Error error
}

type Input

type Input = any

Input is an input value to a step. A value can be either a Ref, or any verbatim value.

type Job

type Job struct {
	ID        string
	Name      string
	Steps     []Step
	DependsOn []string
	If        Condition
}

func (Job) Describe

func (j Job) Describe(namespace string) string

func (Job) Run

func (j Job) Run(ctx Context) (map[string]any, error)

type Ref

type Ref struct {
	Key string
}

Ref is an Input that refers to a value retrievable by GetValue.

type Step

type Step struct {
	ID   string
	Name string

	// Inputs holds a map of named inputs that can be used by the step.
	Inputs map[string]Input

	Main func(ctx Context) (Command, error)
	If   Condition

	Post   func(ctx Context) error
	PostIf Condition
}

func Run

func Run(f StepFunc) Step

func (Step) Describe

func (s Step) Describe(namespace string) string

func (Step) With

func (s Step) With(key string, input Input) Step

func (Step) WithCondition

func (s Step) WithCondition(condition Condition) Step

func (Step) WithID

func (s Step) WithID(id string) Step

type StepFunc

type StepFunc func(ctx Context) (Command, error)

type Workflow

type Workflow struct {
	Name string
	Jobs []Job
}

func (Workflow) Describe

func (w Workflow) Describe() string

func (Workflow) Run

func (w Workflow) Run(ctx context.Context) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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