Documentation
¶
Index ¶
- func IsTruthy(input any) bool
- func Mutate(input string, mutations ...Mutation) (string, error)
- func MutateYamlNode(node *yaml.Node, mutations ...Mutation) error
- func RewriteSubExpression(in string, forceFormat bool) string
- type Config
- type DefaultStatusCheck
- type ErrorMode
- type EvaluationEnvironment
- type Interpreter
- type InvalidJobOutputReferencedError
- type InvalidMatrixDimensionReferencedError
- type JobOutputsWrapper
- type MatrixWrapper
- type Mutation
- type Needs
- type NeedsWrapper
- type VariableAccessMutator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Mutate ¶ added in v12.2.0
Given a workflow string which may contain an expression, apply an expression `Mutation` to the string and return a new one. Mutations have the capability to replace parts of the abstract-syntax-tree (AST) for the expression with new contents, allowing for sophisticated changes to the expression.
As the expressions within the string are parsed into an AST, mutated, and then re-rendered from the new AST to text, arbitrary formatting changes may occur, particularly with whitespace. For example, a function call like `format('id={0}',123)` will be returned with a space between function parameters, even if a mutator didn't change this function.
func MutateYamlNode ¶ added in v12.2.0
Where `Mutate` operates on a single expression string, `MutateYamlNode` will iterate through an entire yaml tree and perform the mutations on all string values found within.
func RewriteSubExpression ¶ added in v12.2.0
The expression parsing library that runner uses to evaluate workflow expressions (eg. `${{ ... }}`) doesn't support a string which is partially text and partially expression, like `Hello ${{ vars.world }}!`. `RewriteSubExpression` converts a string in this format into a single expression evaluation, such as `format('Hello {0}!', vars.world)`. The return value may still be `${{ ... }}` delimited.
Types ¶
type DefaultStatusCheck ¶
type DefaultStatusCheck int
const ( DefaultStatusCheckNone DefaultStatusCheck = iota DefaultStatusCheckSuccess DefaultStatusCheckAlways DefaultStatusCheckCanceled DefaultStatusCheckFailure )
func (DefaultStatusCheck) String ¶
func (dsc DefaultStatusCheck) String() string
type EvaluationEnvironment ¶
type EvaluationEnvironment struct {
Github *model.GithubContext
Env map[string]string
Job *model.JobContext
Jobs *map[string]*model.WorkflowCallResult
Steps map[string]*model.StepResult
Runner map[string]any
Secrets map[string]string
Vars map[string]string
Strategy map[string]any
Matrix map[string]any
Needs map[string]Needs
Inputs map[string]any
HashFiles func([]reflect.Value) (any, error)
ErrorMode ErrorMode
}
type Interpreter ¶
type Interpreter interface {
Evaluate(input string, defaultStatusCheck DefaultStatusCheck) (any, error)
}
func NewInterpreter ¶
func NewInterpreter(env *EvaluationEnvironment, config Config) Interpreter
type InvalidJobOutputReferencedError ¶ added in v12.1.1
func (*InvalidJobOutputReferencedError) Error ¶ added in v12.1.1
func (e *InvalidJobOutputReferencedError) Error() string
type InvalidMatrixDimensionReferencedError ¶ added in v12.1.1
func (*InvalidMatrixDimensionReferencedError) Error ¶ added in v12.1.1
func (e *InvalidMatrixDimensionReferencedError) Error() string
type JobOutputsWrapper ¶ added in v12.1.1
type MatrixWrapper ¶ added in v12.1.1
type Mutation ¶ added in v12.2.0
type Mutation interface {
// Given a single AST node, return either `nil` to allow the original node to be used, or a new `ExprNode` to
// replace it in the AST.
SingleNodeMutation(exprNode actionlint.ExprNode) (actionlint.ExprNode, error)
}
Mutations are provided to `Mutate` to change an expression.
type NeedsWrapper ¶ added in v12.1.0
type VariableAccessMutator ¶ added in v12.2.0
type VariableAccessMutator struct {
// Variable to trigger the mutator upon. If set to `needs`, for example, then `needs.hello` will trigger
// `Rewriter`.
Variable string
// Rewrite routine to use. `property` will be an AST node representing the property accessed. Typically you would
// not want to inspect inside the contents of the `property` as it could be any type of AST from a simple string
// literal to a function call.
Rewriter func(property actionlint.ExprNode) actionlint.ExprNode
}
VariableAccessMutator is used to rewrite access to top-level variables (contexts, in the runner terminology). When a variable matching the name `Variable` is accessed, invoke the Rewriter function to get a replacement `ExprNode`. Both access to a variable with an object dereference (eg. `var.foo`) and an index-style access (`var.['foo']`) is supported for mutation. Note that because index-style access is supported, the mutator does not know the specific value of the property name being accessed -- it could be computed or derived from another property (`var[other-var.something]`).
func (*VariableAccessMutator) SingleNodeMutation ¶ added in v12.2.0
func (vam *VariableAccessMutator) SingleNodeMutation(exprNode actionlint.ExprNode) (actionlint.ExprNode, error)