Documentation
¶
Overview ¶
Package workflow provides a generic way to represent running tasks with or without dependencies. The implementation mimics GitHub actions / workflows.
Index ¶
- Variables
- func Always(ctx Context) (bool, error)
- func GetAnyInput(ctx Context, name string, required bool) (any, error)
- func GetAnyValue(ctx Context, name string) (any, bool)
- func GetInput[T any](ctx Context, name string, required bool) (T, error)
- func GetValue[T any](ctx Context, name string) (T, error)
- type Command
- type Condition
- type ConditionFunc
- type Context
- type Input
- type Job
- type Ref
- type Step
- type StepFunc
- type Workflow
Constants ¶
This section is empty.
Variables ¶
var ErrDependentJobFailed = errors.New("dependent job failed")
var (
ErrInvalidType = errors.New("invalid type")
)
var ErrSkipped = errors.New("skipped")
ErrSkipped is returned when a Job or Step is skipped when invoked.
Functions ¶
func GetAnyInput ¶
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 ¶
GetAnyValue returns a value in the ctx.
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 SetOutput ¶
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>"
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.
type ConditionFunc ¶
ConditionFunc is an adapter to allow the use of ordinary functions as Conditions.
func ValueExists ¶ added in v0.13.0
func ValueExists(key string) ConditionFunc
ValueExists will evaluate to true if the given key has a value AND the job has not already failed.
type Context ¶
type Context struct { context.Context // Workflow is the current workflow. Workflow Workflow // WorkflowRun describes the current invocation. WorkflowRun models.WorkflowRun // Job is the current job. Job Job JobIndex int // Step is the current step. Step Step StepIndex int // 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 // Error holds any current error of the context. Error error }
Context is a context.Context implementation holding additional context for a workflow. The value should be seen as being immutable.
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 is an optional ID by which to reference any outputs created by the job's // steps. ID string // Name is a human-readable name of the job. Name string // Steps holds all the steps that are run as part of the job. Steps []Step // DependsOn optionally holds the ids of jobs that must complete for this job // to run. // Jobs will not run if one of its dependencies fail. DependsOn []string // If holds a [Condition] that must pass for this job to run. If Condition }
Job represents a series of steps. The implementation mimics GitHub actions / workflows.
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 }
Step represents a single unit of an operation. The implementation mimics GitHub actions / workflows.
func (Step) Run ¶ added in v0.17.0
Run runs a step. Returns the modified context. Returns ErrSkipped if the job was not run. It's the caller's responsibility to ensure [Step.Main] is defined.
func (Step) RunPost ¶ added in v0.17.0
RunPost runs a step's post step. Returns ErrSkipped if the job was not run. It's the caller's responsibility to ensure [Step.Post] is defined.
func (Step) WithCondition ¶
type Workflow ¶
type Workflow struct { // Name is the human-readable name of the workflow. Name string // Jobs holds all the jobs that the workflow should run. // Jobs are started in the order defined by their dependencies. Jobs []Job }
Workflow is a generic way to represent running tasks with or without dependencies. The implementation mimics GitHub actions / workflows.