workflow

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: BSD-3-Clause Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package workflow parses GitHub Actions workflow files into typed Go values, under hard bounds on size, depth and YAML alias expansion. It has no forge knowledge and runs nothing.

Every string that may carry a ${{ }} expression is kept raw (and checked for expression syntax at parse time); evaluating them is the planner's and the runner's job.

Index

Constants

View Source
const MaxEventName = 64

MaxEventName bounds the name of a trigger event (GitHub's longest is 31).

Variables

View Source
var (
	ErrNodeLimit          = errors.New("workflow: node limit")
	ErrExpandedBytesLimit = errors.New("workflow: expanded bytes limit")
)

ErrNodeLimit and ErrExpandedBytesLimit are matched with errors.Is against the refusal of Limits.MaxNodes and Limits.MaxExpandedBytes. They are set by the parser where the limit trips, never read back from the text of a message, which quotes names the document chose.

Functions

func CheckFilter

func CheckFilter(patterns []string, positive bool) error

CheckFilter validates a filter list as the planner reads it, so that a workflow whose filter can never be matched is refused when it is parsed and not when an event arrives. positive is true for branches, tags and paths: a list of only negated patterns can never match there.

func SortedKeys

func SortedKeys[V any](m map[string]V) []string

SortedKeys returns the keys of m in order, for deterministic output.

Types

type Concurrency

type Concurrency struct {
	Group            string
	CancelInProgress string // "true", "false" or an expression
}

Concurrency groups runs; Group may hold expressions.

type Container

type Container struct {
	Image       string
	Credentials *Credentials
	Env         map[string]string
	Ports       []string
	Volumes     []string
	Options     string
}

Container describes a job container or a service container: data only.

type Credentials

type Credentials struct {
	Username string
	Password string
}

Credentials for a registry. The password is redacted by String, GoString, and JSON/text marshalling, so a dump of a workflow never carries it.

func (Credentials) GoString

func (c Credentials) GoString() string

GoString redacts the password.

func (Credentials) MarshalJSON

func (c Credentials) MarshalJSON() ([]byte, error)

MarshalJSON redacts the password.

func (Credentials) MarshalText

func (c Credentials) MarshalText() ([]byte, error)

MarshalText redacts the password.

func (Credentials) String

func (c Credentials) String() string

String redacts the password.

type Defaults

type Defaults struct {
	Shell            string
	WorkingDirectory string
}

Defaults are the run defaults.

type Error

type Error struct {
	Line, Col int
	Msg       string
	// contains filtered or unexported fields
}

Error is a parse error with a position. Its text names keys and kinds, never a scalar value taken from the document.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Is added in v0.4.0

func (e *Error) Is(target error) bool

Is reports whether e is the refusal of the work limit target names.

type Event

type Event struct {
	Types          []string
	Branches       []string
	BranchesIgnore []string
	Tags           []string
	TagsIgnore     []string
	Paths          []string
	PathsIgnore    []string
	Workflows      []string          // workflow_run
	Crons          []string          // schedule
	Inputs         map[string]*Input // workflow_dispatch, workflow_call
	InputOrder     []string          // declaration order of Inputs
	Line           int
}

Event is the configuration of one trigger. Filters hold glob patterns.

type Input

type Input struct {
	Description string
	Required    bool
	Default     string
	HasDefault  bool
	Type        string
	Options     []string
}

Input is a workflow_dispatch or workflow_call input.

type Job

type Job struct {
	ID              string
	Name            string
	RunsOn          []string // labels; one element may be an expression
	RunsOnGroup     string
	Needs           []string
	If              string
	Env             map[string]string
	Outputs         map[string]string
	Strategy        *Strategy
	Steps           []*Step
	TimeoutMinutes  string // number or expression, raw
	ContinueOnError string // true, false or an expression, raw
	Container       *Container
	Services        map[string]*Container
	ServiceOrder    []string
	Permissions     *Permissions
	Concurrency     *Concurrency
	Defaults        Defaults
	Environment     string
	Uses            string            // reusable workflow call
	With            map[string]string // reusable workflow inputs
	Secrets         map[string]string // reusable workflow secrets; "inherit" in SecretsInherit
	SecretsInherit  bool
	Line            int
}

Job is one job. Expression-capable fields are raw strings.

type Limits

type Limits struct {
	MaxBytes         int // size of the YAML text (default 256 KiB: the YAML decoder allocates up to ~290 times it, measured 72 MiB)
	MaxExpandedBytes int // bytes of scalars visited, aliases EXPANDED (default 2 MiB)
	MaxDepth         int // nesting of the YAML tree, aliases included (default 64)
	MaxNodes         int // YAML nodes visited, aliases EXPANDED (default 100000): the billion-laughs bound
	MaxScalar        int // bytes of one scalar (default 256 KiB)
	MaxJobs          int // jobs per workflow (default 256, GitHub's)
	MaxSteps         int // steps per job (default 1000)
	MaxMatrixAxes    int // axes per matrix (default 32)
	MaxAxisValues    int // values per axis, include or exclude entries (default 1000)
	MaxNeeds         int // entries of one needs list (default 256: a job cannot need more jobs than a workflow has)
	// MaxFilterBytes bounds the bytes of the DISTINCT filter patterns of the
	// whole workflow (default 32 KiB), counted once per list after the aliases
	// are expanded and the duplicates removed: 1000 aliases of one pattern are
	// one pattern. GitHub documents no limit on pattern text beyond the size of
	// the workflow file (itself capped by MaxBytes); 32 KiB of distinct pattern
	// text is far above what a hand-written filter holds, and bounds the work of
	// a filter at MaxFilterBytes x changed files.
	MaxFilterBytes int
	Expr           expr.Limits
}

Limits bounds what a workflow may cost. Zero fields take the defaults.

func DefaultLimits

func DefaultLimits() Limits

DefaultLimits are applied to zero fields.

type Matrix

type Matrix struct {
	Expr        string           // whole matrix is an expression
	Axes        map[string][]any // axis -> values
	AxisExprs   map[string]string
	AxisOrder   []string
	Include     []map[string]any
	Exclude     []map[string]any
	IncludeExpr string
	ExcludeExpr string
}

Matrix is a strategy.matrix. Expr is set when the whole matrix (or an axis) is a ${{ }} expression to be evaluated by the planner.

type Permissions

type Permissions struct {
	All    string            // "read-all", "write-all" or ""
	Scopes map[string]string // scope -> read | write | none
}

Permissions is either a blanket ("read-all", "write-all", "") or a scope map.

type Step

type Step struct {
	ID               string
	Name             string
	If               string
	Uses             string
	Run              string
	Shell            string
	WorkingDirectory string
	With             map[string]string
	WithOrder        []string
	Env              map[string]string
	TimeoutMinutes   string
	ContinueOnError  string
	Line             int
}

Step is one step: exactly one of Uses and Run is set.

type Strategy

type Strategy struct {
	Matrix      *Matrix
	FailFast    string // "", "true", "false" or an expression
	MaxParallel string // "" or a number or an expression
	Line        int
}

Strategy is a job's strategy.

type Workflow

type Workflow struct {
	// Size is the byte length of the YAML text the workflow was parsed from: the
	// unit a planner scales its work budget by (0 for a hand-built workflow).
	Size        int
	Name        string
	RunName     string
	On          map[string]*Event // keyed by event name (push, pull_request, ...)
	OnOrder     []string
	Env         map[string]string
	Permissions *Permissions
	Concurrency *Concurrency
	Defaults    Defaults
	Jobs        map[string]*Job
	JobOrder    []string // declaration order
}

Workflow is a parsed workflow file.

func Parse

func Parse(data []byte, lim Limits) (*Workflow, error)

Parse parses workflow YAML. The first YAML document is the workflow; a second one is refused.

func ParseNode added in v0.2.0

func ParseNode(root *yaml.Node, size int, lim Limits) (*Workflow, error)

ParseNode parses a workflow from an already-built YAML node tree: the entry point of a front end whose own syntax is not YAML (hclwf builds the tree from HCL). The tree goes through exactly the checks and bounds Parse applies to a decoded document, so two front ends cannot disagree about what a valid workflow is. root is the top-level mapping; size is the byte length of the source text, kept in Workflow.Size.

Jump to

Keyboard shortcuts

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