Documentation
¶
Overview ¶
Package app holds the orchestration both front-ends call.
It exists because the CLI and the TUI must not be two implementations. The first attempt put these helpers in internal/cli and had the TUI import them, which produced an import cycle the moment the CLI needed to launch the TUI -- a useful accident, because it forced the shared layer to be named rather than left implicit in whichever package happened to define it first.
Index ¶
- Constants
- func AnyFailed(outcomes []Outcome) bool
- func ApplyWorkspace(pack *config.PackConfig, workspace string)
- func AuditBundled(ctx context.Context, opts AuditOptions) ([]manifestpack.Resolution, error)deprecated
- func AuditManifestPack(ctx context.Context, opts AuditOptions) ([]manifestpack.Resolution, error)
- func BuildStack(in StackInput) (settings.Stack, string, error)
- func CheckAll(ctx context.Context, packs []*config.PackConfig) []checker.Result
- func IsUsage(err error) bool
- func LoadPacks(configDir, only string) ([]*config.PackConfig, error)
- func LoadPacksIn(configDir, only, workspace string) ([]*config.PackConfig, error)
- func PackSettings(stack settings.Stack, pack *config.PackConfig) (settings.Resolved, error)
- func Problems(fs []Finding) int
- func Recipe(ctx context.Context, req RecipeRequest) (pipeline.Result, error)
- func ResolveSets(ctx context.Context, sets []string, filesRoot, workDir string, parallel int, ...) []manifestpack.Resolution
- func RunRecipe(ctx context.Context, pack *config.PackConfig, version string, ...) (pipeline.Result, error)
- type AuditOptions
- type Checker
- type Finding
- type Level
- type Outcome
- type RecipeRequest
- type RunFunc
- type StackInput
- type Status
- type SyncOptions
- type UsageError
Constants ¶
const BundledPack = ManifestPack
BundledPack is ManifestPack's former name, and the same value.
Deprecated: use ManifestPack. Earliest removal: 0.2.0.
const ManifestPack = "icon-sets-bundled"
ManifestPack is the registry slug of the aggregator pack the manifest-pack audit surveys.
Variables ¶
This section is empty.
Functions ¶
func ApplyWorkspace ¶
func ApplyWorkspace(pack *config.PackConfig, workspace string)
ApplyWorkspace resolves a relative pack_root against the workspace setting.
Every shipped config names an absolute /work/<pack>, which is where the Docker image sees the mounted checkouts. A relative root is for running the binary on a laptop against sibling checkouts without editing four configs.
func AuditBundled
deprecated
added in
v0.1.1
func AuditBundled(ctx context.Context, opts AuditOptions) ([]manifestpack.Resolution, error)
AuditBundled is AuditManifestPack's former name, and forwards to it.
Deprecated: use AuditManifestPack. Earliest removal: 0.2.0.
func AuditManifestPack ¶ added in v0.1.2
func AuditManifestPack(ctx context.Context, opts AuditOptions) ([]manifestpack.Resolution, error)
AuditManifestPack identifies, by measurement, which upstream each vendored set of the manifest pack came from. It is the body of `manifest-pack audit`, so the CLI and the web UI cannot survey differently. Results are sorted.
func BuildStack ¶ added in v0.1.1
func BuildStack(in StackInput) (settings.Stack, string, error)
BuildStack resolves the settings layers that do not vary by pack: the global config file, the environment, and the flag layer.
It is the body of the CLI's resolveState, moved here so the web UI resolves precedence through exactly the same code. Errors in the environment, the assignments or the overlay are *UsageError; a missing or malformed global config is a plain error.
func CheckAll ¶
CheckAll resolves upstream status for every pack, in order.
Sequential on purpose. Polling four registries concurrently would save a second or two and cost the deterministic output order that makes a CI log diffable between runs.
func LoadPacks ¶
func LoadPacks(configDir, only string) ([]*config.PackConfig, error)
LoadPacks loads one pack, or every pack in registry order.
Shared so the two front-ends cannot disagree about what "every pack" means.
func LoadPacksIn ¶
func LoadPacksIn(configDir, only, workspace string) ([]*config.PackConfig, error)
LoadPacksIn is LoadPacks with a relative pack_root resolved against workspace, so the checker reads the vendored version from the right tree.
func PackSettings ¶
PackSettings resolves one pack's settings over the run-wide stack.
The pack layer is the config's `settings` block. It is parsed here rather than at load time because the schema has already checked its shape, and only the settings package knows which keys are pack-scoped.
func Recipe ¶ added in v0.1.1
Recipe runs one pack's recipe at a version: the body of the `recipe` command, so the web UI runs it through the same checks. A missing version is a *UsageError; a pack with no sinks outside a dry run is refused before anything is fetched.
func ResolveSets ¶ added in v0.1.1
func ResolveSets(ctx context.Context, sets []string, filesRoot, workDir string, parallel int, pkg string, fetcher manifestpack.Fetcher) []manifestpack.Resolution
ResolveSets audits sets concurrently.
Each set is independent and dominated by a network fetch, so this is worthwhile -- dozens of sets fetched one at a time is minutes of waiting. Results are written into a fixed slot per set rather than appended, so the output order stays deterministic regardless of which finishes first.
func RunRecipe ¶
func RunRecipe(ctx context.Context, pack *config.PackConfig, version string, opts recipes.Options) (pipeline.Result, error)
RunRecipe builds a pack's pipelines and runs them in order.
Aborts on the first failure and returns that result, rather than running the rest: the emoji recipe's trailing pipeline commits whatever the three asset pipelines left on disk, so continuing past a failed fetch would commit a half-refreshed pack.
ctx reaches every stage, so cancelling it stops the pipeline in flight and skips the pipelines after it.
Types ¶
type AuditOptions ¶ added in v0.1.1
type AuditOptions struct {
ConfigDir string
Workspace string
// Set restricts the audit to one set. Package verifies one named npm
// package against it instead of guessing; it needs Set.
Set string
Package string
// WorkDir keeps the downloads. Empty means a temporary directory that is
// removed afterwards.
WorkDir string
// Parallel bounds the concurrent sets. Below 1 means the CPU count.
Parallel int
// Fetcher fetches candidate packages. Nil means npm.
Fetcher manifestpack.Fetcher
// Starting is called once the sets are known, before any fetch. May be nil.
Starting func(sets int, filesRoot string)
// SetDone is called as each set is resolved, in completion order, one
// call at a time. May be nil.
SetDone func(manifestpack.Resolution)
// Logger receives the resolver's lines. Nil means slog.Default().
Logger *slog.Logger
}
AuditOptions configures AuditManifestPack.
type Finding ¶ added in v0.1.1
Finding is one line of a validation report.
func ValidateConfigs ¶ added in v0.1.1
ValidateConfigs validates the registry and every pack it lists, the same checks `config validate` runs with no arguments, in the same order.
The global config is not covered: it has already been loaded, and so validated, by whoever built the stack.
func ValidatePack ¶ added in v0.1.1
ValidatePack checks one registered pack: that it loads against the schema, that its name matches its slug, that its settings block resolves, that a recipe can run it and, for a manifest-pack, that its set manifest loads. A pack with no sinks is a warning, not an error.
type Outcome ¶
type Outcome struct {
Pack string
Status Status
Current string
Latest string
DryRun bool
Result pipeline.Result
Err error
}
Outcome is one pack's result.
func Sync ¶
func Sync(ctx context.Context, packs []*config.PackConfig, opts SyncOptions) []Outcome
Sync refreshes every pack that is behind upstream (or every pack, with force), and returns one outcome per pack in input order.
Two things fail loudly here that the Python let pass:
- An upstream whose latest version cannot be resolved is a failure, not a skip. The Python printed a yellow line and exited 0, so a dead registry or a renamed package looked exactly like an up-to-date pack, every Monday, indefinitely.
- A pack that declares no sinks is a failure unless this is a dry run: it would fetch, transform, and then write nothing, and report success.
Neither stops the other packs. One dead registry must not hold back the rest of the run; it makes the run exit non-zero once the rest are done.
type RecipeRequest ¶ added in v0.1.1
type RecipeRequest struct {
Stack settings.Stack
Pack *config.PackConfig
ConfigDir string
// Version is the upstream version to fetch. Empty means the pack's
// current_version.
Version string
Logger *slog.Logger
Observer pipeline.Observer
}
RecipeRequest is one direct recipe run, skipping the upstream check.
type RunFunc ¶
type RunFunc func(ctx context.Context, pack *config.PackConfig, version string, opts recipes.Options) (pipeline.Result, error)
RunFunc builds and runs one pack's recipe.
type StackInput ¶ added in v0.1.1
type StackInput struct {
// GlobalPath is an explicit global config file. Empty means discover it
// the way GlobalConfigPath does (ICHAVA_GLOBAL_CONFIG, then XDG).
GlobalPath string
// Lookup reads the environment. Nil means os.LookupEnv. A server passes
// its own so a test can run it against a controlled environment.
Lookup func(string) (string, bool)
// Assignments are --set key=value pairs, the start of the flag layer.
Assignments []string
// Overlay applies the dedicated flags (--dry-run, --concurrency, a web
// form's toggles) on top of the assignments. It runs last, so a
// dedicated flag beats a --set of the same key, exactly as on the
// command line. An error it returns is a usage error. May be nil.
Overlay func(flags settings.Values) error
}
StackInput is what BuildStack needs to assemble the run-wide settings.
type SyncOptions ¶
type SyncOptions struct {
// Stack is the run-wide settings; each pack's own layer is merged in.
Stack settings.Stack
// ConfigDir is handed to the recipes (a manifest-pack's set manifest lives there).
ConfigDir string
// Concurrency bounds how many packs run at once. Below 1 means 1.
Concurrency int
Checker Checker
Run RunFunc
// Logger and Observer are handed to every pack's recipe; see
// recipes.Options. Nil means slog.Default() and no observer.
Logger *slog.Logger
Observer pipeline.Observer
// Starting and Done are called around each pack, from that pack's
// goroutine, for progress output. Either may be nil. Calls are
// serialised, so a reporter need not lock.
Starting func(pack *config.PackConfig, result checker.Result, dryRun bool)
Done func(Outcome)
}
SyncOptions configures Sync.
type UsageError ¶ added in v0.1.1
type UsageError struct{ Err error }
UsageError marks an error the caller made in what it asked for, as opposed to one the machine or a file produced. The CLI maps it onto exit code 2; the web UI onto a 400. Keeping the distinction here means neither front-end has to guess it from a message.
func (*UsageError) Error ¶ added in v0.1.1
func (e *UsageError) Error() string
func (*UsageError) Unwrap ¶ added in v0.1.1
func (e *UsageError) Unwrap() error