pipeline

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 7 Imported by: 0 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 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

View Source
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"

	// KeyLicenceFiles is the newline-separated list of upstream licence files
	// FindLicences found at the root of the fetched tree, as absolute paths to
	// copies it keeps in the working directory, so a stage that rebuilds the
	// fetched tree cannot delete them.
	// Present and empty means it looked and found none.
	KeyLicenceFiles = "licence_files"

	// KeyUpstreamRoot is the root of the fetched tree as the source left it,
	// recorded by FindLicences before anything narrows it, so a stage reading
	// an upstream data file (Exclude's metadata) still finds it.
	KeyUpstreamRoot = "upstream_root"
)

Well-known Extras keys. These are the contract between stages; the accessors below exist so a typo cannot silently produce a missing value.

View Source
const (
	ConfigPack       = "pack"
	ConfigPackRoot   = "pack_root"
	ConfigOldVersion = "old_version"

	// ConfigDryRun is true on every pipeline a dry run builds. The sinks that
	// write into the pack checkout (Filesystem, LicenceTexts) read it and
	// report what they would write instead of writing it, so a dry run leaves
	// the pack byte-identical, tracked and untracked files alike.
	ConfigDryRun = "dry_run"
)

Well-known Config keys, supplied by the recipes.

Variables

View Source
var ErrRecipePending = errors.New("recipe pending")

ErrRecipePending is returned for a pack whose recipe has not been written.

No recipe returns it today: every pack in config/ has one, and the aggregator pack runs the manifest-pack recipe. icon-sets-bundled's sync-upstream.yml used to grep the run output for "recipe pending" and turn the failure into a green no-op; that wrapper was removed in icon-sets-bundled#95, so nothing outside this module reads the wording now. It stays so a future pack added before its recipe still fails with a clear message rather than a nil pipeline.

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
	// contains filtered or unexported fields
}

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) ConfigBool added in v0.1.3

func (c *Context) ConfigBool(key string) bool

ConfigBool returns a bool-valued config key, or false when absent.

func (*Context) ConfigString

func (c *Context) ConfigString(key string) string

ConfigString returns a string-valued config key, or "" when absent. Callers that need to distinguish absent from empty should read Config directly.

func (*Context) Context added in v0.1.1

func (c *Context) Context() context.Context

Context returns the run's context.Context. A stage executed outside a pipeline (a test building a Context by hand) gets context.Background().

func (*Context) DryRun added in v0.1.3

func (c *Context) DryRun() bool

DryRun reports whether this run must leave the pack checkout untouched.

func (*Context) FetchedPath

func (c *Context) FetchedPath() (string, bool)

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

func (c *Context) FetchedVersion() (string, bool)

FetchedVersion is the upstream version a source actually retrieved. The version stamp and the git sink both key off it.

func (*Context) Logger added in v0.1.1

func (c *Context) Logger() *slog.Logger

Logger returns the logger a stage should write to when it has none of its own: the pipeline's, else slog.Default().

func (*Context) Metric

func (c *Context) Metric(stage string, values map[string]any)

Metric records a per-stage counter under a namespaced key.

func (*Context) SetFetchedPath

func (c *Context) SetFetchedPath(path string)

SetFetchedPath records the extracted tree. SubsetTo rewrites it to a subdirectory, which is how a source's `source_path` is honoured.

func (*Context) SetFetchedVersion

func (c *Context) SetFetchedVersion(v string)

SetFetchedVersion records the retrieved version.

func (*Context) SetString

func (c *Context) SetString(key, value string)

SetString records a string-valued extra.

func (*Context) String

func (c *Context) String(key string) (string, bool)

String returns a string-valued extra, and whether it was present as one.

type Observer added in v0.1.1

type Observer interface {
	StageStarted(pipeline, stage string)
	// StageFinished carries a snapshot of the run's metrics after the stage
	// and the stage's error, nil on success.
	StageFinished(pipeline, stage string, metrics map[string]any, err error)
}

Observer is told when each stage starts and finishes. It exists so a front-end can draw stage progress from typed events rather than by parsing log lines. Calls arrive on the goroutine running the pipeline.

type Pipeline

type Pipeline struct {
	// contains filtered or unexported fields
}

Pipeline is the fluent builder and runner.

func Named

func Named(name string) *Pipeline

Named starts a pipeline.

func (*Pipeline) Config

func (p *Pipeline) Config(kv map[string]any) *Pipeline

Config merges keys any stage can read through Context.Config.

func (*Pipeline) ConfigValue added in v0.1.3

func (p *Pipeline) ConfigValue(key string) (any, bool)

ConfigValue returns one config key as the stages will see it, so a caller can check what a recipe put there without running the pipeline.

func (*Pipeline) Logger

func (p *Pipeline) Logger(l *slog.Logger) *Pipeline

Logger replaces the logger. The TUI swaps in a handler that routes stage lines into the run view instead of stderr.

func (*Pipeline) Name

func (p *Pipeline) Name() string

Name returns the pipeline's name.

func (*Pipeline) Observer added in v0.1.1

func (p *Pipeline) Observer(o Observer) *Pipeline

Observer sets the stage observer. Nil leaves none.

func (*Pipeline) RunContext added in v0.1.1

func (p *Pipeline) RunContext(runCtx context.Context) (Result, error)

RunContext 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.

Cancelling ctx stops the run too: it is checked before every stage, and stages hand it to their subprocesses and downloads. A cancelled run is a failed result whose Err is ctx.Err(), naming the stage it did not start, so a caller can tell a cancel from a fault with errors.Is.

func (*Pipeline) Sink

func (p *Pipeline) Sink(s Sink) *Pipeline

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

func (p *Pipeline) Source(s Source) *Pipeline

Source sets the single source. Setting it twice is an error, surfaced by Run.

func (*Pipeline) Stages

func (p *Pipeline) Stages() []Stage

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) Transform

func (p *Pipeline) Transform(t Transform) *Pipeline

Transform appends a transform. Any number is valid.

func (*Pipeline) WorkingDir

func (p *Pipeline) WorkingDir(path string) *Pipeline

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.

func (Result) Error

func (r Result) Error() string

Error returns the failure as a string, or "" on success. It is the direct equivalent of Python's PipelineResult.error.

func (Result) Headline added in v0.1.3

func (r Result) Headline() string

Headline is the one line a person reads for this result: the filesystem sink's counts when there was one, otherwise "finished", or the failure. Summary is the machine payload; printing it with %v produced the "done -- map[error: extras:map[..." line that R3 replaced.

func (Result) Summary

func (r Result) Summary() map[string]any

Summary is the map the CLI prints. Byte payloads are dropped rather than dumped, matching Python.

type Sink

type Sink interface {
	Stage
	// contains filtered or unexported methods
}

Sink writes the in-flight tree to its destination.

type SinkKind

type SinkKind struct{}

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 Stage

type Stage interface {
	Name() string
	Execute(ctx *Context) error
}

Stage is one step. Implementations are a Source, a Transform or a Sink.

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{}

Jump to

Keyboard shortcuts

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