pipeline

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 5 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"
)

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

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.

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

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

func (p *Pipeline) Run() (Result, error)

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

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