run

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Package run implements the logic behind the 'ar2 run' command.

A full backfill can't be done in one invocation, so each one takes a bounded amount of work and records what it did. The order decides what gets generated first, and it is deliberate: the registry is most useful when the packages people actually install are in it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Candidate

type Candidate struct {
	Name    string
	Package *state.Package
}

Candidate is one package to work on, in the order it should be worked on.

type Controller

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

Controller runs the loop.

func New

func New(gh *gogithub.Client, generator *generate.Generator, reg Registry, graphql GraphQL, verifier *verify.Verifier) *Controller

New creates a Controller.

The catalogue is not among what a run touches. A package belongs in it once its definition is on its branch, which is after the pull request carrying it merges and not before, so adding it is the reconciliation's job rather than the run's: 'ar2 index' lists the branches that have a definition and adds what the catalogue is missing. A run that added it as it went would leave an entry behind whenever a pull request didn't merge, describing a package nothing can install.

func (*Controller) Run

func (c *Controller) Run(ctx context.Context, logger *slog.Logger, input *Input) (int, error)

Run generates registry.json for up to Limit package versions.

It returns the number generated. Nothing is recorded: the next run asks aqua-registry-g2 what it holds, so whatever didn't make it in is picked up again.

The limit bounds versions attempted, not versions generated. Counting only what succeeded meant a package that fails for every version — a jar with no platform in its name, say — consumed no budget, so the run worked through all of its versions and then through every other package, spending an entire run's API calls on failures.

func (*Controller) SyncState

func (c *Controller) SyncState(ctx context.Context, logger *slog.Logger, s *state.State, pkgInfos map[string]*aquaregistry.PackageInfo) (bool, error)

SyncState adds the packages aqua-registry has gained since the state was built, and reports whether it changed.

The state is built once by 'ar2 init' and then only read. aqua-registry gains packages continuously, and one that isn't in the state is never ordered, so it is never processed at all: it would wait for the next init rather than for the next run. Adding it here costs one GraphQL request for however few packages are new.

Star counts of packages already in the state are left alone. They go stale, but a stale count only shifts the order slightly, and refreshing all of them is what 'ar2 init' is for.

type GraphQL

type GraphQL interface {
	EnableAutoMerge(ctx context.Context, pullRequestID string) error
	GetStars(ctx context.Context, repos []github.Repo) (map[string]int, map[string]string, error)
	FillForbiddenStars(ctx context.Context, stars map[string]int, reasons map[string]string)
	// Versions and Tags are the sweep: they say what each package's newest
	// versions are, fifty packages to a request.
	Versions(ctx context.Context, repos []github.Repo) (map[string][]string, map[string]string, error)
	Tags(ctx context.Context, repos []github.Repo) (map[string][]string, map[string]string, error)
}

GraphQL is the part of GitHub's GraphQL API a run uses.

EnableAutoMerge is what makes CI the gate: a pull request merges itself once the checks pass and stays open when they don't. The star counts are for the packages aqua-registry has gained since the state was built.

type Input

type Input struct {
	// Limit bounds how many package versions are generated in one run.
	Limit int
	// OutputDir is where registry.json files are written. When it is empty the
	// result goes into a pull request instead.
	OutputDir string
	// SkipPR writes the files out without creating a branch, a commit, or a pull
	// request.
	SkipPR bool
	// Verify extracts every asset to check files[].src against the archive.
	Verify bool
	// State is the state to read the order from and record progress into.
	State *state.State
	// PkgInfos are aqua-registry's definitions, keyed by package name.
	PkgInfos map[string]*aquaregistry.PackageInfo
	// RegistryRef is the aqua-registry ref the definitions were read from. A
	// package's aqua gr configuration is read from the same ref, so that the two
	// halves of a definition come from one state of that repository.
	RegistryRef string
	// BaseBranch is aqua-registry-g2's default branch, where the registry's own
	// configuration is.
	BaseBranch string
}

Input holds the parameters of a loop run.

type Registry

type Registry interface {
	Versions(ctx context.Context, logger *slog.Logger, pkgName string) (map[string]struct{}, error)
	PackagesInFlight(ctx context.Context) (map[string]struct{}, error)
	EnsurePackageBranch(ctx context.Context, pkgName string) (string, error)
	Version(ctx context.Context, pkgName, version string) (*aquag2.Registry, error)
	Config(ctx context.Context, pkgName string) (*aquag2.Config, error)
	RegistryConfig(ctx context.Context, ref string) (*g2.RegistryConfig, error)
	Commit(ctx context.Context, branch, parent, message string, files []*g2.File) error
	CreatePullRequest(ctx context.Context, pkgName, title, body string) (*gogithub.PullRequest, error)
}

Registry is aqua-registry-g2: what it holds, and how work is added to it.

Jump to

Keyboard shortcuts

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