sinks

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: 17 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 sinks writes the in-flight tree to its destination.

Order matters and is set by the recipes: Filesystem, then VersionStamp, then GitBranch. Stamping after the commit would record a version that never shipped, and stamping into this repository rather than the pack repo is what made the sync non-convergent before (V49) -- the bump went into the runner's throwaway checkout and every run saw the same stale value.

Index

Constants

View Source
const (
	LicenceStatusCopied       = "copied"
	LicenceStatusMissing      = "missing"
	LicenceStatusHandSupplied = "hand-supplied"
)

The status values LicenceTexts reports in its metric.

View Source
const (
	DefaultBranch        = "chore/sync-upstream-{version}"
	DefaultCommitSubject = "chore(upstream): bump {pack} to v{new}"
	DefaultCommitBody    = "Automated sync from upstream {pack} {old} -> {new}.\n\n" +
		"Generated by ichava/icon-sets-sync. See docs/maintainer-sync.md in that repository."
)

Defaults matching the Python templates.

View Source
const FilesDir = "resources/assets/svg/files"

FilesDir is where a pack keeps its SVGs, relative to its root: one folder per set or variant, or the SVGs themselves for a flat pack.

View Source
const HandSuppliedMarker = "source.md"

HandSuppliedMarker is the file whose presence makes a licence directory hand-maintained. It records where the hand-supplied text came from. The name is a lowercase slug, the estate's rule for file names, which the sim-standards pre-commit hook enforces on Markdown.

Variables

View Source
var ErrLicenceChanged = errors.New("licence changed")

ErrLicenceChanged marks a sync refused because the upstream's licence text no longer matches the licence the pack declares. Callers test for it with errors.Is to report a licence change apart from any other failure.

View Source
var ErrNeedsReview = errors.New("needs review")

ErrNeedsReview is what a guard returns when a refresh would take shipped icons away: the run stops for a person to decide, which is not a failure of the tool. errors.Is(err, ErrNeedsReview) holds for every *ReviewError.

Functions

func LicenceIDs added in v0.1.3

func LicenceIDs() []string

LicenceIDs lists the SPDX ids a pack may declare, sorted.

Types

type Discard

type Discard struct {
	pipeline.SinkKind
}

Discard counts the SVGs a pipeline would have written, and writes nothing.

A pipeline needs at least one sink to run. A dry run of a pack whose only sink commits has none left once the committing sinks are dropped, and failing it there would make --dry-run useless for exactly the packs a person most wants to inspect before letting them commit.

func (Discard) Execute

func (Discard) Execute(ctx *pipeline.Context) error

func (Discard) Name

func (Discard) Name() string

type Filesystem

type Filesystem struct {
	pipeline.SinkKind

	// Root is the destination, with {pack_root} and {version} interpolated.
	Root string

	// Incremental keeps what is already there. Off by default, which means
	// the destination is wiped first -- that is what removes an icon upstream
	// has deleted. An incremental sink would leave it in the pack forever.
	Incremental bool

	// MinRetention refuses to replace a populated destination with
	// substantially fewer files, as a fraction of what is already there.
	// Zero disables the check.
	//
	// Because the wipe is the point, it is also the hazard. Observed while
	// building the aggregator refresh: iconoir's upstream reorganised into
	// per-weight directories, so a refresh matching one of them would have
	// replaced 1,671 committed icons with 1,383 -- deleting 288 without
	// anything failing. A pack losing a sixth of a set to an upstream
	// reshuffle should stop the run and ask, not proceed quietly on a Monday
	// morning cron.
	MinRetention float64

	// RefuseRemovals fails the sink, before the wipe, when any icon the
	// destination ships today is absent from the incoming tree. MinRetention
	// only catches a large shrink by count; this catches one icon, and a swap
	// of one for another that leaves the count unchanged. Off by default.
	RefuseRemovals bool

	// Force lets RefuseRemovals through, for an upstream that really did retire
	// icons. The removals are logged either way.
	Force bool

	Log *slog.Logger
}

Filesystem copies the refreshed SVGs into the pack repo.

func (Filesystem) Execute

func (s Filesystem) Execute(ctx *pipeline.Context) error

func (Filesystem) Name

func (Filesystem) Name() string

type GitBranch

type GitBranch struct {
	pipeline.SinkKind

	RepoRoot      string
	Branch        string
	CommitSubject string
	CommitBody    string
	Base          string
	OpenPR        bool

	Git *gitx.Git
	Log *slog.Logger
}

GitBranch commits the refreshed pack and opens a pull request.

func (GitBranch) Execute

func (s GitBranch) Execute(ctx *pipeline.Context) error

func (GitBranch) Name

func (GitBranch) Name() string

type KeptCommitError added in v0.1.3

type KeptCommitError struct {
	Branch string
	Commit gitx.Commit
	Err    error
}

KeptCommitError is a commit a person added to the sync's branch that no longer applies on top of the new sync. Nothing is pushed, so the pull request still has it; the run stops for a person (errors.Is ErrNeedsReview).

func (*KeptCommitError) Error added in v0.1.3

func (e *KeptCommitError) Error() string

func (*KeptCommitError) Is added in v0.1.3

func (e *KeptCommitError) Is(target error) bool

func (*KeptCommitError) Unwrap added in v0.1.3

func (e *KeptCommitError) Unwrap() error

type LicenceTexts added in v0.1.2

type LicenceTexts struct {
	pipeline.SinkKind

	Root string
	Set  string

	// MissingReason lets a set whose upstream ships no licence file refresh
	// anyway, with the reason recorded where it is configured (a manifest-pack set's
	// licence_missing). The set's licence directory is then removed rather than
	// left holding a text that no longer matches, and the gap is logged and
	// reported as a metric on every run, unless the directory is hand-supplied
	// (holds a source.md), which satisfies the exception.
	MissingReason string

	// Licence is the SPDX id the pack declares for this upstream. When set,
	// the upstream's licence text must still be that licence, or the run
	// fails before the existing texts are touched: a relicensed upstream is a
	// decision for a person, not something a scheduled sync copies in.
	Licence string

	// SHA256 is the digest one of the upstream's licence files must have.
	// When set, a sync whose upstream licence text changed by a byte fails
	// before the existing texts are touched, as a changed Licence does.
	SHA256 string
}

LicenceTexts writes the upstream's own licence and notice files, verbatim, into the pack beside the icons they cover.

The files are the ones FindLicences recorded at the root of the fetched tree, copied byte for byte under their upstream names. Never a template: the text that satisfies MIT's "this permission notice shall be included" is the upstream's own, copyright line and all.

Root is the destination for one set, with {pack_root} and {version} interpolated; the recipes use resources/assets/svg/licenses/<set>, which is not export-ignored, so the texts ship in every dist archive with the icons. The directory is replaced on each run, so a NOTICE upstream drops is dropped here too.

A directory holding a source.md is hand-maintained, and the sink never deletes or overwrites it. source.md is where a maintainer records where a hand-supplied text came from, for a set whose upstream ships none; replacing that directory on a scheduled run would destroy the only copy of the text in the pack. Such a set is reported as hand-supplied rather than missing, and a licence_missing exception it satisfies stops warning. If upstream later starts shipping licence files for that set, the folder is still kept and the run warns that upstream now ships its own, so a human reconciles the two: the hand-supplied text may be the better one (a fuller copyright line), and only a person can tell, so the sink neither switches silently nor fails a scheduled run over it.

An upstream with no licence file at its root fails the run, naming the set. Shipping icons whose licence text cannot be found is the defect this sink exists to end, so it is not reduced to a warning on a scheduled job.

func (LicenceTexts) Execute added in v0.1.2

func (s LicenceTexts) Execute(ctx *pipeline.Context) error

func (LicenceTexts) Name added in v0.1.2

func (LicenceTexts) Name() string

type Removal added in v0.1.3

type Removal struct {
	Path      string `json:"path"`
	RenamedTo string `json:"renamed_to,omitempty"`
	// SameAs is set instead when the same bytes stay at a path that ships
	// today too: a duplicate dropped, not a rename (OpenMoji's black flags
	// share one outline, so content alone cannot say which one moved).
	SameAs string `json:"same_as,omitempty"`
}

Removal is one icon the pack ships today that a refresh would take away. RenamedTo is the incoming path of a byte-identical file, when there is one: upstream moved or renamed the icon rather than retiring it.

type Review added in v0.1.3

type Review struct {
	Target   string    `json:"target"`
	Reason   string    `json:"reason,omitempty"`
	Message  string    `json:"message"`
	Removals []Removal `json:"removals,omitempty"`
}

Review is a dry run's record of what a real run would refuse.

func ReviewOf added in v0.1.3

func ReviewOf(metrics map[string]any) (Review, bool)

ReviewOf reads the review a Filesystem sink recorded in a pipeline's metrics, if any.

type ReviewError added in v0.1.3

type ReviewError struct {
	Target   string
	Removals []Removal
	// Reason is set by a guard that refuses on a count rather than per icon
	// (MinRetention); Removals may then be empty.
	Reason string
}

ReviewError is a guard's refusal, with every icon it concerns.

func (*ReviewError) Error added in v0.1.3

func (e *ReviewError) Error() string

func (*ReviewError) Is added in v0.1.3

func (e *ReviewError) Is(target error) bool

func (*ReviewError) Removed added in v0.1.3

func (e *ReviewError) Removed() int

func (*ReviewError) Renamed added in v0.1.3

func (e *ReviewError) Renamed() int

Renamed and Removed count the two kinds.

type StatedFacts added in v0.1.3

type StatedFacts struct {
	pipeline.SinkKind

	Pack *config.PackConfig
	Git  *gitx.Git
	Log  *slog.Logger
}

StatedFacts keeps the figures a pack states about itself in step with what a sync has just written: its icon count, in total and per set folder, and the version it vendors, wherever README.md, composer.json and the pack's tests state them.

The packs' guards pin those figures on purpose, so a silently shrunk or grown set fails. Nothing moved the pins with the assets, so every refresh that changed a count opened red and was fixed by hand: tabler 3.51.0, carbon 11.92.0, simple-icons 16.37.0 and lucide 1.72.0 on 2026-11-11. The licence check's version is VersionStamp's (stampLicenceCheck), not this.

It runs before VersionStamp, so the version file still names the previous version, and reads the previous counts from git HEAD, the tree the sync started from. Only exact, whole occurrences of a previous figure are rewritten, and only in those files. A count under ten is left alone, being too likely to be some other number, and so is a previous figure two facts share. A previous figure no file states is reported, never guessed at.

func (StatedFacts) Execute added in v0.1.3

func (s StatedFacts) Execute(ctx *pipeline.Context) error

func (StatedFacts) Name added in v0.1.3

func (StatedFacts) Name() string

type VersionStamp

type VersionStamp struct {
	pipeline.SinkKind

	Pack *config.PackConfig
	Log  *slog.Logger
}

VersionStamp records the fetched version in the pack repo's own config.

Into the pack repo, never back into this one. The GitBranch sink commits it alongside the assets, so the version and the SVGs it describes move in one commit and the next run compares against what actually shipped.

func (VersionStamp) Execute

func (s VersionStamp) Execute(ctx *pipeline.Context) error

func (VersionStamp) Name

func (VersionStamp) Name() string

Jump to

Keyboard shortcuts

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