actions

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: BSD-3-Clause Imports: 0 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.

README

actions

go-vcs actions

Go Reference License CI Landing Docs

GitHub Actions workflow engine and gitea-runner protocol server. Part of go-vcs, a light, secure Git forge.

Status: v0.1.0, the first release. This is milestone 5 of the design: workflow parsing and planning (matrix, needs, expressions) and the server side of the gitea-runner protocol, reusable without the forge. The gitea-runner protocol server is not started.

Part State
expr, the ${{ }} expression evaluator available (one work budget per template, counted in bytes; per-tenant caps on hashFiles)
workflow, the workflow YAML parser available
the planner, plan (triggers, path filters, matrix, needs) available
conformance suite (conformance/, against act v0.2.99) available
gitea-runner protocol server not started

Measured cost of the planner

One EventMeter per event meters path filters whatever the number of workflows. An ordinary push, real change first or no file matching (first measurement, in plan's round 5):

patterns x files x bytes units, match first units, whole list read time
50 x 3000 x 180 1,885 900,850 2.1 ms
100 x 3000 x 90 3,735 1,801,700 4.2 ms
200 x 3000 x 58 7,535 3,603,500 8.6 ms
200 x 1000 x 120 7,535 1,203,500 3.0 ms

All are accepted. The ceiling (EventCeiling, 2^28 units) is about 0.8 s of one core at 2.9 ns a unit; spending all of it took 1.5 to 3.4 s at a load of 60, so those are upper bounds, and a quiet-machine run is a follow-up. 50 hostile workflows on one push were refused at the ceiling in 480 ms of CPU (load 18 to 21, also an upper bound), where per-workflow budgets had cost 132.7 s.

Known follow-ups

Recorded in the bodies of #5, #6 and #7; none blocks v0.1.0.

  • plan: release/[ is accepted by act and refused by us at parse time; the meter is per event, and a cumulative meter across ShouldRun calls is not built; NewEventMeter can still be called once per workflow (the one-meter-per-event rule is documented, not enforced); the ceiling time has not been re-measured at low load; TestRound11OrdinaryPushesAreAcceptedAndCheap has a loose 200 ms bound (54.8 ms on a hosted runner); timeout-minutes is an integer, so a masked value that reads as one is the timeout and is not replaced there.
  • conformance: the corpus has no table-path patterns (**/*.go, ?, +); its 400 corpus results are discarded (only the five pattern workflows under testdata/patterns assert an answer); the module has no govulncheck, 386 or race job in CI.
  • expr, fairness: 4 tenants with 64 calls in flight each exhaust the global 256 and deny every other tenant. A per-tenant share of the backstop, or a reserved slice for tenants below their cap, is the fix.
  • expr, host contexts: a context []string of 1M elements is refused at the default budget (16.7M units) while the same data as []any costs 1M units. The recommendation is to normalise host contexts once per Env, outside the document budget, under a ceiling the host sets.

expr: the expression language

github.com/go-vcs/actions/expr lexes, parses and evaluates the ${{ }} language of GitHub Actions, with no forge knowledge. Contexts (github, env, vars, job, jobs, steps, runner, secrets, strategy, matrix, needs, inputs) are passed in as JSON-shaped values; hashFiles and the status functions (success, failure, always, cancelled) are interfaces the caller implements.

v, err := expr.Evaluate("contains(github.event.labels.*.name, 'bug') && matrix.os == 'linux'",
	&expr.Env{Contexts: map[string]any{"github": ev, "matrix": m}})
tp, _ := expr.ParseCondition("${{ failure() }}", expr.Limits{})
ok, err := tp.EvalCondition(env) // implicit success() && when no status function

Semantics follow the GitHub documentation (coercion, case-insensitive string comparison and property names, .* filters, truthiness) and were read against nektos/act's pkg/exprparser.

Bounds (all overridable, none removable; each has a test proving the refusal): expression length 21000 bytes, AST depth 100 (also bounds parser and evaluator recursion), results 1 MiB, fromJSON input 64 KiB / depth 32 / 10000 values, template 256 KiB / 256 expressions, and a cumulative work budget per evaluation (MaxWork, 16M units, the step bound: a charge is proportional to the bytes touched, never to the count of items: every node visited, key byte hashed, compared or sorted, element flattened and byte copied costs a unit, so iteration that allocates nothing is bounded too; one budget covers a whole template) and a wall-clock deadline (MaxTime, 2 s, read at the charge points) behind it. A pointer that points at itself in a context reads as null. hashFiles runs under the same deadline (a call that outlives it is abandoned and the evaluation refused). A HashFiler receives a context.Context that is cancelled at the deadline and MUST honour it: a call that ignores it keeps running (abandoned), and once a tenant (Env.Tenant; Envs without one share a tenant) has 16 such abandoned calls running its hashFiles is refused with a "saturated" error until some return (slow calls that honour the context are not counted; a tenant has at most 64 calls in flight, so at most 64 abandoned, and 256 in flight process-wide is the hard backstop; a tenant's own cap does not reach another tenant, but the 256 backstop is shared: 4 tenants with 64 calls each in flight exhaust it and every other tenant is then refused, so per-tenant isolation holds only while at most 3 tenants are saturated). Typed slices and maps in a context are charged by the bytes converting them copies, and the budget is tested on a 32-bit int in CI. Typed context values are converted once per evaluation, charged per node. toJSON stops writing at the result bound while it walks the value. Case folding is ASCII only (GitHub folds Unicode, so 'É' == 'é' is false here) and one mapping for ==, <, contains, startsWith, endsWith and property names; format placeholders are plain decimal indexes ({00} is refused); when several keys match a property case-insensitively, the smallest key wins. startsWith, endsWith and contains are false for arrays and objects used as text. Errors name positions and source tokens, never evaluated values: a secret flowing through an expression cannot reach an error message (tested). Fuzz targets: FuzzParse, FuzzEvaluate, FuzzTemplate, FuzzDecodeJSON, FuzzTyped, FuzzEvalCondition (a committed corpus under expr/testdata/fuzz, and a short -fuzz run of each in CI), seeded from expr/testdata/seeds.txt.

workflow: the workflow file parser

github.com/go-vcs/actions/workflow turns a workflow YAML file into typed Go values (Workflow, Job, Step, Matrix, Event with its branch, tag and path filters, workflow_dispatch inputs, schedule, containers, services, reusable-workflow calls). Fields that may hold ${{ }} stay raw strings, but their syntax is checked at parse time (and every if: as a condition), so a malformed expression is refused with a line number before any run starts.

w, err := workflow.Parse(data, workflow.Limits{})
for _, id := range w.JobOrder { j := w.Jobs[id]; _ = j.Needs }

Strict by design: unknown keys, duplicate keys, a second YAML document, a step with both or neither of uses and run, an unknown or self needs, and branches together with branches-ignore (same for tags and paths) are errors. Anchors, aliases and << merge keys are supported.

Bounds (overridable, none removable; each has a test that proves the refusal and one that accepts the value just under it): 256 KiB of input (the YAML decoder allocates up to about 250 times what it reads), YAML depth 64, 100000 nodes counted after alias expansion (a billion-laughs document of under 4 KiB is refused), 2 MiB of scalar bytes counted after alias expansion (an aliased scalar is charged at every alias), 256 KiB per scalar, finite numbers only (.nan and .inf are refused), 256 jobs, 1000 steps per job, 32 matrix axes, 1000 values per axis. Errors carry a line and never a scalar value. Credentials.Password of a container is redacted by String, GoString, JSON and text marshalling, so a dump of a parsed workflow cannot print it (tested). Fuzz target FuzzParse, seeded from workflow/testdata/seeds.

plan: triggers, matrix and job order

github.com/go-vcs/actions/plan decides what a parsed workflow does for an event and in which order, and runs nothing.

pl := plan.New(w, plan.Options{Contexts: ctxs, Mask: []string{token}})
ev := plan.Event{Name: "push", Ref: "refs/heads/main", Files: changed}
m := plan.NewEventMeter(ev, pl) // ONE meter per event, whatever the number of workflows
defer m.Close()
ok, err := pl.MatchesIn(m, ev)
err = pl.Resolve()  // or: p, err := plan.Build(w, opts), which is New + Resolve
fmt.Print(pl) // one deterministic line per job instance
  • One Plan has ONE work budget (Limits.MaxWork, default 16M units). New is the only constructor of it, and Matches, Glob, Filter, Resolve, Expand and Job.ShouldRun are methods that all draw on it (the event matches, MatchesIn, GlobIn and FilterIn, take the EventMeter of the event instead: no match can be made without one): asking again never buys more work, and a spent budget answers ErrBudget with ok=false. A job that no plan made has no budget and is refused by ShouldRun.

  • Matches applies branches, tags, *-ignore, paths, activity types (with GitHub's defaults for pull_request), schedule and workflow_dispatch; ResolveInputs checks dispatch inputs (type, choice, required, default).

  • Glob and Filter implement the GitHub filter syntax (*, **, ?, +, [...], ! negation, last match wins). Matching never backtracks without bound: a literal prefix and suffix reject first, a middle with one kind of star runs Cox's single-restart star loop, and a middle with repetitions (or both star kinds) a linear table. A [...] class is compiled to a 256-bit set when the pattern is parsed, so a byte is one lookup however many ranges the class has and a unit is the same time everywhere. A class holds ASCII bytes only: a byte above 0x7f in one ([é]) is a parse error, not a class that matches nothing. Pattern 1024 bytes, subject 4096 bytes. The work of an EVENT is metered once, whatever the number of workflows (NewEventMeter, Plan.MatchesIn; a nil or zero meter is an error): 1 MiB + 256 units a byte of event and workflow, at most 2^28 units. A unit is 2.9 ns at most on the reference machine (the star loop, the slowest shape measured; a call costs 12 ns and is charged 6 units), so the ceiling is about 0.8 s of one core there; a hosted runner is 2 to 4 times slower, and spending the whole ceiling took 1.5 to 3.4 s at a load of 60 (TestRound13CeilingTime, TestRound13UnitCostIsAnchored). A match is charged what it examined, so an ordinary push (200 patterns, 3000 files) costs a few thousand units; what exceeds the meter is refused with ErrBudget, never read as "no match". Duplicate filter patterns are removed when the workflow is parsed (Limits.MaxFilterBytes, 32 KiB of distinct patterns). Above 3000 changed files the filter is taken as matched and the workflow runs: GitHub cuts the diff at 3000 files and documents that a workflow whose match is not in them does not run, so skipping on a list we were handed whole would be a silent skip.

  • Build expands each matrix (include, exclude, fromJSON for the whole matrix, an axis or the entries), orders jobs by needs (cycles are named, ties keep declaration order) and resolves name, runs-on, fail-fast, max-parallel, timeout-minutes. At most 256 combinations per job (checked before they are built, and again after include) and 4096 job instances. A matrix that reads needs outputs is returned Deferred; call Expand again once they are known. Job.ShouldRun(results, contexts) evaluates if: against the results of the needed jobs, with an implied success(), on the budget of the plan that made the job.

  • Secrets: the secrets context is never read, whatever is passed, and every evaluated string has the Mask values replaced by ***. Errors name inputs and keys, never values (tested on the plan dump, its JSON and the errors).

Where GitHub documents no order, ours is: an object-valued matrix expression has its axes sorted by name; keys an include entry adds to a new combination are sorted. Fuzz targets FuzzGlob and FuzzBuild.

conformance: against act

conformance/ is a nested module (so act and its dependencies never reach a user of the library) that evaluates 138 expressions and parses 400 real workflow files from our organisations with both github.com/nektos/act v0.2.99 and this library. Jobs, events, needs and matrix sizes must agree; every other difference is listed in knownExpr with its reason (seven today: act's .* on objects, status functions without a job context, null != null, comparisons of objects and arrays) and a listed difference that disappears fails the test. COLLECT_ROOT=<dir of clones> go test -run TestCollectCorpus renews the corpus. Run it with cd conformance && go test ./....

Documentation

Overview

Package actions will hold the GitHub Actions workflow engine (parsing and planning: matrix, needs, expressions) and the server side of the gitea-runner protocol, reusable without the go-vcs forge.

It is not started: see https://github.com/go-vcs/forge/blob/main/docs/design.md, milestone 5.

Directories

Path Synopsis
Package plan decides which workflows an event triggers and turns a parsed workflow into an ordered plan of job instances: filter matching, matrix expansion, dependency ordering and the job-level conditions.
Package plan decides which workflows an event triggers and turns a parsed workflow into an ordered plan of job instances: filter matching, matrix expansion, dependency ordering and the job-level conditions.
Package workflow parses GitHub Actions workflow files into typed Go values, under hard bounds on size, depth and YAML alias expansion.
Package workflow parses GitHub Actions workflow files into typed Go values, under hard bounds on size, depth and YAML alias expansion.

Jump to

Keyboard shortcuts

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