Documentation
¶
Overview ¶
Package resolver implements a way to resolve versions of software based on the provided criteria. The ideal use case is for package managers or anything else that needs ranges. Versions must meet semantic versioning requirements or otherwise be a branch/commit SHA.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrUnableToSatisfy = errors.New("no versions found that satisfy criteria")
ErrUnableToSatisfy is returned when no versions are found that satisfy the provided criteria.
Functions ¶
This section is empty.
Types ¶
type Criteria ¶
type Criteria struct {
// Constraint is a semantic versioning constraint that the version
// must satisfy.
//
// Example: ">=1.0.0 <2.0.0"
Constraint string
// Branch is the branch that the version must point to. This
// constraint will only be satisfied if the branch currently points to
// the commit being considered.
//
// If a branch is provided, it will always be used over other
// versions. For this reason, top-level modules should only ever use
// branches.
Branch string
// contains filtered or unexported fields
}
Criteria represents a set of criteria that a version must satisfy to be able to be selected.
func (*Criteria) Check ¶
Check returns true if the version satisfies the criteria. If a prerelease is included then the provided criteria will be mutated to support pre-releases as well as ensure that the prerelease string matches the provided version. If a branch is provided, then the criteria will always be satisfied unless the criteria is looking for a specific branch, in which case it will be satisfied only if the branches match.
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver is an instance of a version resolver that resolves versions based on the provided criteria. Version lists are fetched exactly once and are cached for the lifetime of the resolver.
func (*Resolver) Resolve ¶
func (r *Resolver) Resolve(ctx context.Context, uri string, criteria ...*Criteria) (*Version, error)
Resolve returns the latest version matching the provided criteria. If multiple criteria are provided, the version must satisfy all of them. If no versions are found, an error is returned.
TODO(jaredallard): Return resolution errors as a type that can be unwrapped for getting information about why it failed.
type Version ¶
type Version struct {
// Commit is the underlying commit hash for this version.
Commit string `yaml:"commit,omitempty"`
// Tag is the underlying tag for this version, if set.
Tag string `yaml:"tag,omitempty"`
// Virtual denotes that a version does not actually relate to anything
// in a Git repository. This is mainly meant for testing or scenarios
// where you want to inject something in that is not a real version.
//
// This field is never set by the resolver in this package.
Virtual string `yaml:"virtual,omitempty"`
// Branch is the underlying branch for this version, if set.
Branch string `yaml:"branch,omitempty"`
// contains filtered or unexported fields
}
Version represents a version found in a Git repository. Versions are only discovered if a tag or branch points to a commit (individual commits will never be automatically discovered unless they are manually passed in).