Documentation
¶
Overview ¶
Package pipeline composes one source, zero or more transforms and one or more sinks, and walks them in order threading a shared context between them.
Ported from core/pipeline.py. Two things differ deliberately, both noted at the point they occur: Python's Source/Transform/Sink were pure runtime markers and are real types here, and a Go error carries no exception class name, so the failing stage is recorded as its own field rather than being spliced into the message.
Index ¶
- Constants
- Variables
- type Context
- func (c *Context) ConfigString(key string) string
- func (c *Context) FetchedPath() (string, bool)
- func (c *Context) FetchedVersion() (string, bool)
- func (c *Context) Metric(stage string, values map[string]any)
- func (c *Context) SetFetchedPath(path string)
- func (c *Context) SetFetchedVersion(v string)
- func (c *Context) SetString(key, value string)
- func (c *Context) String(key string) (string, bool)
- type Pipeline
- func (p *Pipeline) Config(kv map[string]any) *Pipeline
- func (p *Pipeline) Logger(l *slog.Logger) *Pipeline
- func (p *Pipeline) Name() string
- func (p *Pipeline) Run() (Result, error)
- func (p *Pipeline) Sink(s Sink) *Pipeline
- func (p *Pipeline) Source(s Source) *Pipeline
- func (p *Pipeline) Stages() []Stage
- func (p *Pipeline) Transform(t Transform) *Pipeline
- func (p *Pipeline) WorkingDir(path string) *Pipeline
- type Result
- type Sink
- type SinkKind
- type Source
- type SourceKind
- type Stage
- type Transform
- type TransformKind
Constants ¶
const ( KeyFetchedPath = "fetched_path" KeyFetchedVersion = "fetched_version" KeyFetchedSource = "fetched_source" KeyCLDRPath = "cldr_path" KeyCLDRText = "cldr_text" KeyCLDRVersion = "cldr_version" KeyCLDRRecords = "cldr_records" KeyFilesystemTgt = "filesystem_target" KeyGitBranch = "git_branch" KeyGitSHA = "git_sha" KeyPRURL = "pr_url" )
Well-known Extras keys. These are the contract between stages; the accessors below exist so a typo cannot silently produce a missing value.
const ( ConfigPack = "pack" ConfigPackRoot = "pack_root" ConfigOldVersion = "old_version" )
Well-known Config keys, supplied by the recipes.
Variables ¶
var ErrRecipePending = errors.New("recipe pending")
ErrRecipePending is returned for a pack whose recipe has not been written.
The string is a contract, not a message. icon-sets-bundled's sync-upstream.yml greps the run output for "recipe pending" and converts the failure into a green run with a ::notice::, because that pack's `iconify` recipe genuinely does not exist yet. Change the wording and that workflow starts failing a scheduled job that is meant to be a documented no-op.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
PipelineName string
WorkingDir string
// Config is the overlay supplied by the builder's Config method. Stages
// read each other's keys, so namespace anything ambiguous.
Config map[string]any
// Extras is free-form scratch space and the real coupling between stages:
// a source drops its extracted tree under FetchedPath, and every transform
// and sink picks it up from there. The well-known keys have typed accessors
// below -- prefer those, because a misspelt string key fails at runtime and
// an accessor fails at compile time.
Extras map[string]any
// Metrics is per-stage counters. The reporter reads this.
Metrics map[string]any
}
Context is the state threaded through every stage of one run.
Stages mutate Extras to hand data forward. The pipeline guarantees WorkingDir exists for the duration of the run and removes it afterwards when it created it -- so a sink must copy out of it, never move.
func (*Context) ConfigString ¶
ConfigString returns a string-valued config key, or "" when absent. Callers that need to distinguish absent from empty should read Config directly.
func (*Context) FetchedPath ¶
FetchedPath is the extracted tree a source produced. Every transform and the filesystem sink read it; a stage that needs it and does not find it must fail rather than silently do nothing.
func (*Context) FetchedVersion ¶
FetchedVersion is the upstream version a source actually retrieved. The version stamp and the git sink both key off it.
func (*Context) SetFetchedPath ¶
SetFetchedPath records the extracted tree. SubsetTo rewrites it to a subdirectory, which is how a source's `source_path` is honoured.
func (*Context) SetFetchedVersion ¶
SetFetchedVersion records the retrieved version.
type Pipeline ¶
type Pipeline struct {
// contains filtered or unexported fields
}
Pipeline is the fluent builder and runner.
func (*Pipeline) Logger ¶
Logger replaces the logger. The TUI swaps in a handler that routes stage lines into the run view instead of stderr.
func (*Pipeline) Run ¶
Run executes the stages in order and returns the result.
A stage failure stops the run -- the remaining stages do not execute, which is what keeps a sink from committing assets a transform failed to produce.
func (*Pipeline) Sink ¶
Sink appends a sink. Any number is valid; the order is load-bearing -- filesystem, then version stamp, then git branch, so the version that is committed is the version that shipped.
func (*Pipeline) Source ¶
Source sets the single source. Setting it twice is an error, surfaced by Run.
func (*Pipeline) Stages ¶
Stages returns the stages in execution order. The TUI reads this to draw a row per stage before the run starts, so a pending stage is visible rather than appearing only once it begins.
func (*Pipeline) WorkingDir ¶
WorkingDir overrides the per-run temporary directory. A caller-supplied directory is left in place afterwards; one the pipeline created is removed.
type Result ¶
type Result struct {
PipelineName string
Success bool
Metrics map[string]any
Extras map[string]any
// Err is the failure, or nil. Python formatted this as
// "RuntimeError: boom"; Go errors carry no class name, so the message
// stands alone and the stage that raised it is recorded separately.
Err error
// FailedStage names the stage that returned Err, empty on success.
FailedStage string
}
Result is what a run returns.
type Sink ¶
type Sink interface {
Stage
// contains filtered or unexported methods
}
Sink writes the in-flight tree to its destination.
type Source ¶
type Source interface {
Stage
// contains filtered or unexported methods
}
Source fetches assets and drops them under Context.WorkingDir.
Python made Source/Transform/Sink empty subclasses of Stage, which the runner then treated identically -- they bought nothing but documentation. Here they are distinct, so passing a sink where a source belongs does not compile. Embed the matching Kind struct to declare which one a stage is.
type SourceKind ¶
type SourceKind struct{}
SourceKind, TransformKind and SinkKind are embedded to declare a stage's role.
type Transform ¶
type Transform interface {
Stage
// contains filtered or unexported methods
}
Transform mutates the in-flight tree under Context.FetchedPath.
type TransformKind ¶
type TransformKind struct{}