wharfyml

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package wharfyml contains code for parsing and validating .wharf-ci.yml files.

Index

Constants

View Source
const (
	// StageRunsIfSuccess runs the stage if all previous stages were successful.
	StageRunsIfSuccess = "success"
	// StageRunsIfFail runs the stage if one or more of the previous stages were
	// unsuccessful.
	StageRunsIfFail = "fail"
	// StageRunsIfAlways always runs the stage, regardless of the success state
	// of previous stages.
	StageRunsIfAlways = "always"
)

Variables

View Source
var (
	ErrInputNameCollision      = errors.New("input variable name is already used")
	ErrInputUnknownType        = errors.New("unknown input type")
	ErrUseOfUndefinedInput     = errors.New("use of undefined input variable")
	ErrInputChoiceUnknownValue = errors.New("default value is missing from values array")
)

Errors related to parsing environments.

View Source
var (
	ErrStepEmpty             = errors.New("missing a step type")
	ErrStepMultipleStepTypes = errors.New("contains multiple step types")
)

Errors related to parsing steps.

View Source
var (
	ErrInvalidRunCondition = errors.New("invalid run condition")
)

Errors related to parsing the run conditions.

View Source
var (
	ErrNoStepTypesRegistered = errors.New("no step types registered")
)

Errors related to parsing step types.

View Source
var (
	ErrStageEmpty = errors.New("stage is missing steps")
)

Errors related to parsing stages.

View Source
var (
	ErrStageEnvEmpty = errors.New("environment name cannot be empty")
)

Errors related to parsing environments.

View Source
var (
	ErrUseOfUndefinedEnv = errors.New("use of undefined environment")
)

Errors specific to parsing definitions.

Functions

func ParseVarFiles

func ParseVarFiles(currentDir string) (varsub.Source, errutil.Slice)

ParseVarFiles produces a varsub.Source of *yaml.Node values. The files it checks depends on your OS.

For GNU/Linux:

/etc/iver-wharf/wharf-cmd/wharf-vars.yml
$XDG_CONFIG_HOME/iver-wharf/wharf-cmd/wharf-vars.yml
(if $XDG_CONFIG_HOME is unset) $HOME/.config/iver-wharf/wharf-cmd/wharf-vars.yml

For Windows:

%APPDATA%\iver-wharf\wharf-cmd\wharf-vars.yml

For Darwin (Mac OS X):

$HOME/Library/Application Support/iver-wharf/wharf-cmd/wharf-vars.yml

In addition, this function also checks the current directory and parent directories above it, recursively, for a dotfile variant (.wharf-vars.yml):

./.wharf-vars.yml
../.wharf-vars.yml
../../.wharf-vars.yml
../../..(etc)/.wharf-vars.yml

Types

type Args

type Args struct {
	Env                string
	VarSource          varsub.Source
	SkipStageFiltering bool
	Inputs             map[string]any
	StepTypeFactory    StepTypeFactory
}

Args specify arguments used when parsing the .wharf-ci.yml file, such as what environment to use for variable substitution.

type Definition

type Definition struct {
	Inputs    Inputs
	Envs      map[string]Env
	Env       *Env
	Stages    []Stage
	VarSource varsub.Source
}

Definition is the .wharf-ci.yml build definition structure.

func Parse

func Parse(reader io.Reader, args Args) (def Definition, errSlice errutil.Slice)

Parse will parse the YAML content as a .wharf-ci.yml definition structure. Multiple errors may be returned, one for each validation or parsing error.

func ParseFile

func ParseFile(path string, args Args) (Definition, errutil.Slice)

ParseFile will parse the file at the given path. Multiple errors may be returned, one for each validation or parsing error.

func (*Definition) ListAllSteps

func (d *Definition) ListAllSteps() []Step

ListAllSteps aggregates steps from all stages into a single slice.

Makes Definition comply to the StepLister interface.

type Env

type Env struct {
	Source visit.Pos
	Name   string
	Vars   map[string]visit.VarSubNode
}

Env is an environments definition. Used in the root of the definition.

func (Env) VarSource

func (e Env) VarSource() varsub.Source

VarSource returns a varsub.Source compliant value of the environment variables.

type EnvRef

type EnvRef struct {
	Source visit.Pos
	Name   string
}

EnvRef is a reference to an environments definition. Used in stages.

type Input

type Input interface {
	InputTypeName() string
	InputVarName() string
	DefaultValue() any
	ParseValue(value any) (any, error)
	Pos() visit.Pos
}

Input is an interface that is implemented by all input types.

type InputChoice

type InputChoice struct {
	Source  visit.Pos
	Name    string
	Values  []string
	Default string
}

InputChoice represents a choice of multiple string inputs.

func (InputChoice) DefaultValue

func (i InputChoice) DefaultValue() any

DefaultValue returns the default value for this input variable.

func (InputChoice) InputTypeName

func (InputChoice) InputTypeName() string

InputTypeName returns the name of this input type.

func (InputChoice) InputVarName

func (i InputChoice) InputVarName() string

InputVarName returns the name of this input variable.

func (InputChoice) ParseValue

func (i InputChoice) ParseValue(value any) (any, error)

ParseValue will try to parse the value and return the input-compatible value for this input variable type, or returns an error if the type isn't valid.

func (InputChoice) Pos

func (i InputChoice) Pos() visit.Pos

Pos returns the position of where this variable was defined.

type InputNumber

type InputNumber struct {
	Source  visit.Pos
	Name    string
	Default float64
}

InputNumber represents a number (integer or float) input value.

func (InputNumber) DefaultValue

func (i InputNumber) DefaultValue() any

DefaultValue returns the default value for this input variable.

func (InputNumber) InputTypeName

func (InputNumber) InputTypeName() string

InputTypeName returns the name of this input type.

func (InputNumber) InputVarName

func (i InputNumber) InputVarName() string

InputVarName returns the name of this input variable.

func (InputNumber) ParseValue

func (i InputNumber) ParseValue(value any) (any, error)

ParseValue will try to parse the value and return the input-compatible value for this input variable type, or returns an error if the type isn't valid.

func (InputNumber) Pos

func (i InputNumber) Pos() visit.Pos

Pos returns the position of where this variable was defined.

type InputPassword

type InputPassword struct {
	Source  visit.Pos
	Name    string
	Default string
}

InputPassword represents a string (text) input value, but where the value should be concealed in user interfaces.

func (InputPassword) DefaultValue

func (i InputPassword) DefaultValue() any

DefaultValue returns the default value for this input variable.

func (InputPassword) InputTypeName

func (InputPassword) InputTypeName() string

InputTypeName returns the name of this input type.

func (InputPassword) InputVarName

func (i InputPassword) InputVarName() string

InputVarName returns the name of this input variable.

func (InputPassword) ParseValue

func (i InputPassword) ParseValue(value any) (any, error)

ParseValue will try to parse the value and return the input-compatible value for this input variable type, or returns an error if the type isn't valid.

func (InputPassword) Pos

func (i InputPassword) Pos() visit.Pos

Pos returns the position of where this variable was defined.

type InputString

type InputString struct {
	Source  visit.Pos
	Name    string
	Default string
}

InputString represents a string (text) input value.

func (InputString) DefaultValue

func (i InputString) DefaultValue() any

DefaultValue returns the default value for this input variable.

func (InputString) InputTypeName

func (InputString) InputTypeName() string

InputTypeName returns the name of this input type.

func (InputString) InputVarName

func (i InputString) InputVarName() string

InputVarName returns the name of this input variable.

func (InputString) ParseValue

func (i InputString) ParseValue(value any) (any, error)

ParseValue will try to parse the value and return the input-compatible value for this input variable type, or returns an error if the type isn't valid.

func (InputString) Pos

func (i InputString) Pos() visit.Pos

Pos returns the position of where this variable was defined.

type Inputs

type Inputs map[string]Input

Inputs is a map of Input field definitions, keyed on their names.

func (Inputs) DefaultsVarSource

func (i Inputs) DefaultsVarSource() varsub.Source

DefaultsVarSource returns a varsub.Source of the default values from this .wharf-ci.yml's input definitions.

type Stage

type Stage struct {
	Pos     visit.Pos
	Name    string
	Envs    []EnvRef
	EnvsPos visit.Pos
	Steps   []Step

	RunsIf StageRunsIf

	Node visit.MapItem
}

Stage holds the name, environment filter, and list of steps for this Wharf build stage.

func (Stage) ShouldSkip added in v0.9.0

func (s Stage) ShouldSkip(anyPreviousStageHasFailed bool) bool

ShouldSkip returns true if the stage should be skipped based on its run conditions.

type StageRunsIf added in v0.9.0

type StageRunsIf string

StageRunsIf is an enum of different run behaviors for a stage, dependent on previous stages.

type Step

type Step struct {
	Pos  visit.Pos
	Name string
	Type StepType
	Meta StepTypeMeta
}

Step holds the step type and name of this Wharf build step.

type StepType

type StepType interface {
	StepTypeName() string
}

StepType is an interface that is implemented by all step types.

type StepTypeFactory

type StepTypeFactory interface {
	NewStepType(stepTypeName, stepName string, v visit.MapVisitor) (StepType, errutil.Slice)
}

StepTypeFactory is a factory type that can create step types from a step type name. This type is expected to be implemented and injected into wharfyml to provide it with the step type definitons.

type StepTypeMeta

type StepTypeMeta struct {
	StepName string
	Source   visit.Pos
	FieldPos map[string]visit.Pos
}

StepTypeMeta contains metadata about a step type.

type VarFile

type VarFile struct {
	Path  string
	IsRel bool
}

VarFile is a place and kind definition of a variable file.

func ListPossibleVarsFiles

func ListPossibleVarsFiles(currentDir string) []VarFile

ListPossibleVarsFiles returns all paths where we look for wharf-vars.yml and .wharf-vars.yml files.

Returned paths include the filename.

The ordering of the returned filenames are in the order of which file should have priority over the other; with the file of highest priority that should override all the others, first.

func (VarFile) PrettyPath

func (f VarFile) PrettyPath(currentDir string) string

PrettyPath returns a formatted version of the path, based on if its relative, and using "~" as shorthand for the user's home directory.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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