fnfile

package
v0.0.0-...-6932d60 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateCombinations

func GenerateCombinations(kvs KeyValues) []set.Set[string]

fruit: [apple, pear, orange] animal: [cat, dog]

should generate

apple, cat apple, dog pear, cat pear, dog orange, cat orange, dog

func GivingUp

func GivingUp(attempts *multierror.Error) error

func UnmarshalJSONToNamedMap

func UnmarshalJSONToNamedMap[T any](m map[string]T, newFn func(name string) T, data []byte) error

func UnmarshalJSONTryAsString

func UnmarshalJSONTryAsString[T any](data []byte, fromFn fromString[T]) (T, error)

Types

type CallInfoOption

type CallInfoOption func(options *CallInfoOptions)

type CallInfoOptions

type CallInfoOptions struct {
	Clock timejumper.Clock
	In    io.Reader
}

type CheckSumAlgorithm

type CheckSumAlgorithm string
const (
	SHA1   CheckSumAlgorithm = "SHA1"
	SHA256 CheckSumAlgorithm = "SHA256"
	SHA512 CheckSumAlgorithm = "SHA512"
)

type DeferSpec

type DeferSpec struct {
	StepMeta
	Do
}

func UnmarshalDefer

func UnmarshalDefer(data []byte) (DeferSpec, error)

func (DeferSpec) Handle

func (spec DeferSpec) Handle(w ResponseWriter, _ *FnContext)

func (*DeferSpec) UnmarshalJSON

func (spec *DeferSpec) UnmarshalJSON(data []byte) (err error)

type DiscardResponseWriter

type DiscardResponseWriter struct {
	ResponseWriter
}

func (DiscardResponseWriter) Defer

func (DiscardResponseWriter) ErrOutWriter

func (w DiscardResponseWriter) ErrOutWriter() io.Writer

func (DiscardResponseWriter) Error

func (w DiscardResponseWriter) Error(_ error)

func (DiscardResponseWriter) ErrorOrNil

func (w DiscardResponseWriter) ErrorOrNil() error

func (DiscardResponseWriter) OutWriter

func (w DiscardResponseWriter) OutWriter() io.Writer

type Do

type Do struct {
	StepMeta
	Steps Steps `json:"steps"`
}

func UnmarshalDo

func UnmarshalDo(data []byte) (Do, error)

func (Do) Handle

func (do Do) Handle(w ResponseWriter, c *FnContext)

func (*Do) UnmarshalJSON

func (do *Do) UnmarshalJSON(data []byte) (err error)

type Duration

type Duration time.Duration

Duration uses time.ParseDuration (see https://pkg.go.dev/time#ParseDuration) for unmarshalling.

func (Duration) MarshalJSON

func (t Duration) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*Duration) UnmarshalJSON

func (t *Duration) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type Dynamic

type Dynamic struct {
	StepMeta
	JSON string `json:"json,omitempty"`
}

func UnmarshalDynamic

func UnmarshalDynamic(data []byte) (Dynamic, error)

func (Dynamic) Handle

func (dynamic Dynamic) Handle(w ResponseWriter, c *FnContext)

func (*Dynamic) UnmarshalJSON

func (dynamic *Dynamic) UnmarshalJSON(data []byte) (err error)

type Features

type Features struct {
}

type FileCondition

type FileCondition struct {
	IfSpec

	// Sources matched files have their contents hashed.
	// If the content hashes change between runs, this fn will be marked as "out-of-date".
	Sources FileGlobs `json:"from,omitempty"`

	// Generates matched files are checked to exist.
	// If these files do not exist, this fn will be marked as "out-of-date".
	// When providing a glob, only 1 match is required to keep this fn "up-to-date".
	Generates FileGlobs `json:"makes,omitempty"`
}

func (*FileCondition) Exec

func (f *FileCondition) Exec(w ResponseWriter, c *FnContext)

type FileGlobs

type FileGlobs []string

FileGlobs is a series patterns to match for files

type Fn

type Fn struct {
	StepMeta
	Run string `json:"run,omitempty"`
}

func UnmarshalFn

func UnmarshalFn(data []byte) (Fn, error)

func UnmarshalFnFromStringData

func UnmarshalFnFromStringData(data []byte) (Fn, error)

func (Fn) Handle

func (fn Fn) Handle(w ResponseWriter, c *FnContext)

func (*Fn) UnmarshalJSON

func (fn *Fn) UnmarshalJSON(data []byte) (err error)

type FnCondition

type FnCondition struct {
	IfSpec

	Fn string `json:"fn"`
}

type FnContext

type FnContext struct {
	// contains filtered or unexported fields
}

func NewCallInfo

func NewCallInfo(ctx context.Context, options ...CallInfoOption) *FnContext

func (*FnContext) CloneWith

func (c *FnContext) CloneWith(ctx context.Context) *FnContext

func (*FnContext) Context

func (c *FnContext) Context() context.Context

func (*FnContext) FnFile

func (c *FnContext) FnFile() FnFile

func (*FnContext) In

func (c *FnContext) In() io.Reader

type FnDef

type FnDef struct {
	Name string `json:"-"`

	Run RunOption `json:"run,omitempty"`

	// Inputs are parameters for this FnDef, used when called by another FnDef.
	Inputs Inputs `json:"inputs,omitempty"`

	// Locals are values only available inside this fn via contexts.Locals
	Locals Vars `json:"locals,omitempty"`

	// Outputs are values that are available via contexts.Fn
	Outputs Vars `json:"outputs,omitempty"`

	// Short is the short description shown in the 'help' output.
	Short string `json:"short,omitempty"`

	// Long is the long message shown in the 'help <this-fn>' output.
	Long string `json:"long,omitempty"`

	// Example is examples of how to use the fn.
	Example string `json:"example,omitempty"`

	// Do are steps that run serially
	Do Do `json:"do,omitempty"`

	// Dir is the directory in which steps will be executed from (default: fnfile.yml directory)
	// This dir is available as a context to sub steps, and thus, those steps can use it to make decisions,
	// if specifying their own directory as relative, it will be relative to this.
	Dir string `json:"dir,omitempty"`

	// Env is a map of environment variables that are available to all steps in the fn.
	// You can also set environment variables for the entire fnfile or an individual step.
	//
	// When more than one environment variable is defined with the same name (in different locations),
	// FnDef uses the most specific environment variable.
	//
	// For example, an environment variable defined in a step will override fn and global (fnfile) variables
	// with the same name, while the step executes.
	// An environment variable defined for a fn will override a global (fnfile) variable
	// with the same name, while the fn executes.
	Env Vars `json:"env,omitempty"`

	// SerialGroups is an array of arbitrary label-like strings. Executions of this fn
	// and other fns referencing the same tags will be serialized.
	SerialGroups SerialGroups `json:"serialGroups,omitempty"`

	// Matrix is a step/fn hook to define a matrix of step/fn configurations.
	//
	// A matrix allows you to create multiple steps/fns by performing variable substitution
	// in a single step/fn definition.
	//
	// When defined on a fn, it dynamically creates several fns, suffixing the fn name with the matrix values.
	//
	// Each individual fn can be called. The original fn becomes a "virtual fn" that "needs" the matrix of fns.
	// Allowing you to call all matrix fns from the single "parent" virtual fn.
	//
	// For example, you can use a matrix to create fns for more than one supported version of a programming language,
	// variable values, or tool, etc. A matrix reuses the step/fn's configuration
	// and creates a step/fn for each matrix you configure.
	//
	// Example
	//
	//	fns:
	//	  echo:
	//		matrix:
	//		- env: ["dev", "staging", "prod"]
	//		steps:
	//		- run: "echo {{.Matrix.env}}"
	//
	// fns defined are:
	//  echo
	//  echo:dev
	//  echo:staging
	//  echo:prod
	Matrix Matrix `json:"matrix,omitempty"`

	// Timeout is the bounding time limit (duration) for the fn before signaling for termination via SIGINT.
	Timeout Duration `json:"Timeout,omitempty"`
}

type FnDefs

type FnDefs map[string]FnDef

func UnmarshalFnDefs

func UnmarshalFnDefs(data []byte) (FnDefs, error)

func (*FnDefs) UnmarshalJSON

func (f *FnDefs) UnmarshalJSON(data []byte) (err error)

type FnFile

type FnFile struct {
	// Version is the version of the Fn schema
	// It is the first thing that is parsed by Task in order to inform how the rest of the file should be parsed.
	Version string `json:"version,omitempty"`

	// Features are flags for fn
	// It enables users to change the behavior of fn by enabling/disabling features of the engine
	Features Features `json:"features,omitempty"`

	// Globals are variables that are available from any fn
	Globals Vars `json:"globals,omitempty"`

	// Includes allows other Fnfiles to be included in this one. Each other include is becomes "namespaced".
	// More on namespacing later...
	Includes Includes `json:"includes,omitempty"`

	// Def is a set of function definitions
	Fns FnDefs `json:"fns,omitempty"`
}

type Fns

type Fns []Fn

func UnmarshalFns

func UnmarshalFns(data []byte) (Fns, error)

func (*Fns) UnmarshalJSON

func (fns *Fns) UnmarshalJSON(data []byte) (err error)

type Gen

type Gen struct {
	Files FileGlobs `json:"files"`
}

type GivenUp

type GivenUp struct {
	// contains filtered or unexported fields
}

func (GivenUp) Error

func (g GivenUp) Error() string

type IfSpec

type IfSpec struct {
	StepMeta
}

type Include

type Include struct {
	Filename  string `json:"filename"`
	Checksum  string `json:"checksum"`
	Algorithm string `json:"algorithm"`
	// Always, IfNotPresent, Never
	PullPolicy  PullPolicy `json:"pullPolicy"`
	PullTimeout Duration   `json:"pullTimeout"`
	Namespace   string     `json:"namespace"`
}

type Includes

type Includes []Include

type Input

type Input struct {
	Name        string `json:"-"`
	Description string `json:"description,omitempty"`
	Required    bool   `json:"required,omitempty"`
	Default     string `json:"default,omitempty"`
}

type Inputs

type Inputs map[string]Input

type KeyValues

type KeyValues map[string]set.Set[string]

type Matrix

type Matrix struct {
	StepMeta

	KVs KeyValues `json:"kvs,omitempty"`

	// Include enables different matrix "shapes" aside from the expected NxM table produced from KVs.
	// Each key:value pair will be added to each of the matrix combinations, but only if the keys are unique (not part of the original matrix).
	// For any unoriginal keys, new matrix combinations will be created.
	Include KeyValues `json:"include,omitempty"`
}

Matrix is a step/fn hook to define a matrix of step/fn configurations.

A matrix allows you to create multiple steps/tasks by performing variable substitution in a single step/fn definition.

When defined on a StepMeta, it dynamically creates several steps. Each step is inlined, and are run serially. StepMeta ordering is based on the order of each provided matrix. Example

	task:
	  echo:
		matrix:
		- env: ["dev", "staging", "prod"]
     - ham: ["bacon", "eggs"]
		steps:
		- run: "echo {{.Matrix.env}} {{.Matrix.ham}}"

Steps created defined are:

  • echo "dev bacon"
  • echo "dev eggs"
  • echo "staging bacon"
  • echo "staging eggs"
  • echo "prod bacon"
  • echo "prod eggs"

func UnmarshalMatrix

func UnmarshalMatrix(data []byte) (Matrix, error)

func (Matrix) Handle

func (m Matrix) Handle(w ResponseWriter, c *FnContext)

func (*Matrix) UnmarshalJSON

func (m *Matrix) UnmarshalJSON(data []byte) (err error)

type Parallel

type Parallel struct {
	StepMeta

	Steps    Steps `json:"steps"`
	FailFast bool  `json:"failFast,omitempty"`
	Limit    int   `json:"limit,omitempty"`
}

func UnmarshalParallel

func UnmarshalParallel(data []byte) (Parallel, error)

func (Parallel) Handle

func (p Parallel) Handle(w ResponseWriter, c *FnContext)

func (*Parallel) UnmarshalJSON

func (p *Parallel) UnmarshalJSON(data []byte) (err error)

type Param

type Param Variable

func ParamFromString

func ParamFromString(val string) Param

func (*Param) UnmarshalJSON

func (p *Param) UnmarshalJSON(data []byte) error

type Params

type Params map[string]Param

func (*Params) UnmarshalJSON

func (p *Params) UnmarshalJSON(data []byte) error

type PullPolicy

type PullPolicy string
const (
	Always       PullPolicy = "Always"
	IfNotPresent PullPolicy = "IfNotPresent"
	Never        PullPolicy = "Never"
)

type ResponseWriter

type ResponseWriter interface {
	Defer(StepHandler)
	OutWriter() io.Writer
	ErrOutWriter() io.Writer
	Error(error)
	ErrorOrNil() error
}

func WithNewDeferrals

func WithNewDeferrals(parent ResponseWriter) (ResponseWriter, *[]StepHandler)

type ReturnSpec

type ReturnSpec struct {
	StepMeta
}

ReturnSpec is a step hook which allows a fn to return early (skipping subsequent steps) just like a `return` statement in Go.

func UnmarshalReturn

func UnmarshalReturn(data []byte) (ReturnSpec, error)

func (ReturnSpec) Handle

func (r ReturnSpec) Handle(_ ResponseWriter, c *FnContext)

func (*ReturnSpec) UnmarshalJSON

func (r *ReturnSpec) UnmarshalJSON(data []byte) (err error)

type RunOption

type RunOption string

func (*RunOption) UnmarshalJSON

func (r *RunOption) UnmarshalJSON(data []byte) error

type SerialGroups

type SerialGroups []string

func (*SerialGroups) UnmarshalJSON

func (t *SerialGroups) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type Sh

type Sh struct {
	StepMeta
	// Run defines a shell command.
	Run string `json:"run,omitempty"`
	// Dir is the desired working directory in which this command should execute in.
	Dir string `json:"dir,omitempty"`
}

func UnmarshalSh

func UnmarshalSh(data []byte) (Sh, error)

UnmarshalSh attempts to unmarshal to a string to generate a simple Sh step (only the run field) otherwise attempts a full unmarshal to Sh step returns an error if neither is possible

func (Sh) Handle

func (sh Sh) Handle(w ResponseWriter, c *FnContext)

func (*Sh) UnmarshalJSON

func (sh *Sh) UnmarshalJSON(data []byte) (err error)

func (Sh) Validate

func (sh Sh) Validate() error

type Src

type Src struct {
	Files FileGlobs `json:"files"`
}

type StdResponseWriter

type StdResponseWriter struct {
	// contains filtered or unexported fields
}

func NewStdResponseWriter

func NewStdResponseWriter(out, errOut io.Writer) *StdResponseWriter

func (*StdResponseWriter) Defer

func (w *StdResponseWriter) Defer(h StepHandler)

func (*StdResponseWriter) ErrOutWriter

func (w *StdResponseWriter) ErrOutWriter() io.Writer

func (*StdResponseWriter) Error

func (w *StdResponseWriter) Error(err error)

func (*StdResponseWriter) ErrorOrNil

func (w *StdResponseWriter) ErrorOrNil() error

func (*StdResponseWriter) OutWriter

func (w *StdResponseWriter) OutWriter() io.Writer

type Step

type Step interface {
	Handle(w ResponseWriter, c *FnContext)
}

func UnmarshalDeferStep

func UnmarshalDeferStep(data []byte) (Step, error)

func UnmarshalDoStep

func UnmarshalDoStep(data []byte) (Step, error)

func UnmarshalDynamicStep

func UnmarshalDynamicStep(data []byte) (Step, error)

func UnmarshalFnStep

func UnmarshalFnStep(data []byte) (Step, error)

func UnmarshalFromStepName

func UnmarshalFromStepName(stepName StepName, data []byte) (Step, error)

func UnmarshalKeyedStep

func UnmarshalKeyedStep(data []byte) (Step, error)

func UnmarshalMatrixStep

func UnmarshalMatrixStep(data []byte) (Step, error)

func UnmarshalParallelStep

func UnmarshalParallelStep(data []byte) (Step, error)

func UnmarshalReturnStep

func UnmarshalReturnStep(data []byte) (Step, error)

func UnmarshalShStep

func UnmarshalShStep(data []byte) (Step, error)

func UnmarshalStep

func UnmarshalStep(data []byte) (Step, error)

type StepHandler

type StepHandler interface {
	Handle(w ResponseWriter, c *FnContext)
}

type StepHandlerFunc

type StepHandlerFunc func(w ResponseWriter, c *FnContext)

func (StepHandlerFunc) Handle

func (f StepHandlerFunc) Handle(w ResponseWriter, c *FnContext)

type StepMeta

type StepMeta struct {
	// Name is the user defined name of the step. Defaults to "anonymous"
	Name string `json:"-"`
	// Locals are variables available to this step and all child steps (like a closure)
	Locals Vars `json:"vars,omitempty"`
	// Timeout is the bounding time limit (duration) for  before signaling for termination
	Timeout Duration `json:"timeout,omitempty"`
}

type StepName

type StepName string
const (
	DeferStep    StepName = "defer"
	DoStep       StepName = "do"
	FnStep       StepName = "fn"
	MatrixStep   StepName = "matrix"
	ParallelStep StepName = "parallel"
	ReturnStep   StepName = "return"
	ShStep       StepName = "sh"
	DynamicStep  StepName = "dynamic"
)

type StepOutcomeCondition

type StepOutcomeCondition struct {
	IfSpec
}

type StepUnmarshaller

type StepUnmarshaller func(data []byte) (Step, error)

type StepVisitor

type StepVisitor struct {
	VisitDefer    func(d DeferSpec)
	VisitDo       func(do Do)
	VisitFnStep   func(fn Fn)
	VisitMatrix   func(m Matrix)
	VisitParallel func(p Parallel)
	VisitReturn   func(r ReturnSpec)
	VisitSh       func(sh Sh)
}

type Steps

type Steps []Step

func UnmarshalSteps

func UnmarshalSteps(data []byte) (Steps, error)

func (*Steps) UnmarshalJSON

func (steps *Steps) UnmarshalJSON(data []byte) error

type ThreadSafeMultiError

type ThreadSafeMultiError struct {
	*multierror.Error
	// contains filtered or unexported fields
}

func (*ThreadSafeMultiError) Append

func (m *ThreadSafeMultiError) Append(errs ...error)

type Variable

type Variable struct {
	Name   string `json:"-"`
	Static string `json:"static,omitempty"`
	Tpl    string `json:"tpl,omitempty"`
	Sh     Sh     `json:"sh,omitempty"`
}

func VariableFromString

func VariableFromString(val string) Variable

func (*Variable) UnmarshalJSON

func (v *Variable) UnmarshalJSON(data []byte) error

type Vars

type Vars map[string]Variable

func (*Vars) UnmarshalJSON

func (v *Vars) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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