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 ¶
const MaxEventName = 64
MaxEventName bounds the name of a trigger event (GitHub's longest is 31).
Variables ¶
This section is empty.
Functions ¶
func CheckFilter ¶
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 ¶
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 ¶
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) MarshalJSON ¶
func (c Credentials) MarshalJSON() ([]byte, error)
MarshalJSON redacts the password.
func (Credentials) MarshalText ¶
func (c Credentials) MarshalText() ([]byte, error)
MarshalText redacts the password.
type Error ¶
Error is a parse error with a position. Its text names keys and kinds, never a scalar value taken from the document.
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.
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 ¶
Parse parses workflow YAML. The first YAML document is the workflow; a second one is refused.
func ParseNode ¶ added in v0.2.0
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.