resolver

package
v1.90.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 12 Imported by: 2

Documentation

Overview

Package resolver contains a git tag aware version resolver that supports channels to determine the latest version.

Index

Constants

View Source
const StableChannel = "stable"

StableChannel is the default channel used when a version doesn't contain a channel.

Variables

View Source
var (
	// ErrNoVersions is returned when no versions are found
	ErrNoVersions = errors.New("no version found matching criteria")
)

This block contains error types for the resolver package.

View Source
var GetVersions = getVersions

GetVersions returns all known channels and the versions that are available for each channel.

Note: token is _optional_, if you do not wish to authenticate with your VCS provider you can pass an empty string.

Functions

func Sort

func Sort(versions []Version)

Sort sorts a slice of versions

Types

type Criteria

type Criteria struct {
	// URL is the URL to the repository to check for updates.
	URL string

	// Channel is the channel to use for determining the latest version.
	// Leave empty to use the StableChannel.
	Channel string

	// Constraints are the semver constraint(s) to use for determining the latest version.
	// See: https://pkg.go.dev/github.com/Masterminds/semver/v3#hdr-Checking_Version_Constraints_and_Comparing_Versions
	Constraints []string

	// AllowBranches is a flag to allow branches to be considered as versions, branches
	// will be represented as their own channel.
	AllowBranches bool
}

Criteria is the criteria used to determine the latest version

type Version

type Version struct {

	// Mutable denotes if this version is a reference pointing to a specific
	// sha that can't be compared as a semantic version. When encountering a
	// mutable version, it should always be used over a semantic version as
	// there is no way to compare the two.
	Mutable bool

	// Branch is the branch that the version is on, branches are special
	// versions that are always mutable.
	Branch string

	// Tag is the git tag that represents the version.
	Tag string `yaml:"version"`

	// Commit is the git commit that this tag refers to.
	Commit string `yaml:"commit"`

	// Channel is the channel that this version is associated with.
	Channel string `yaml:"channel"`
	// contains filtered or unexported fields
}

Version is a resolved version from a git repository

func NewVersion added in v1.53.0

func NewVersion(ref string, isBranch bool, hash string) (*Version, error)

NewVersion creates a new version from a tag and commit.

func NewVersionFromVersionString added in v1.53.1

func NewVersionFromVersionString(ver string) (*Version, error)

NewVersionFromVersionString creates a Version from a version string returned from v.String()

Note: This is lossy, for non-mutable versions it will not have a commit hash and it cannot determine a branch vs. a mutable version.

func Resolve

func Resolve(ctx context.Context, token cfg.SecretData, c *Criteria) (*Version, error)

Resolve returns the latest version that satisfies the criteria

Note: token is _optional_, if you do not wish to authenticate with your VCS provider you can pass an empty string.

Criteria:

Constraints are supported as per the underlying semver library here: https://pkg.go.dev/github.com/Masterminds/semver/v3#hdr-Checking_Version_Constraints_and_Comparing_Versions

If a channel is provided, without a constraint, the latest version of that channel will be returned if it's greater than the `stable` channel (if present). As a special case, if a channel's latest version is mutable, that version will always be returned over any constraint.

Constraints, by default, do not include a pre-releases or allow selecting specific pre-releases tracks in the semver library used. In order to support this we parse the constraints to determine the allowed channels. By default `stable` is always considered, with whatever pre-release (e.g. `>=1.0.0-alpha` -> `alpha`) is specified in the pre-release constraint being added to the allowed channels. If a channel is specified, it is also added to the allowed channels. Due to this '&&' and '||' are not supported in constraints.

func (*Version) Equal added in v1.53.1

func (v *Version) Equal(other *Version) bool

Equal returns true if the version is equal to the other

func (*Version) GitRef added in v1.53.0

func (v *Version) GitRef() string

GitRef returns the git ref for the version if there is one

func (*Version) LessThan added in v1.53.1

func (v *Version) LessThan(other *Version) bool

LessThan returns true if the version is less than the other

func (*Version) String

func (v *Version) String() string

String returns the user-friendly representation of a version, e.g. when using a version that came from a mutable tag use the commit hash+channel as opposed to just the tag.

type Versions

type Versions []Version

Versions represents multiple versions.

func (Versions) Len

func (s Versions) Len() int

Len returns length of version collection

func (Versions) Less

func (s Versions) Less(i, j int) bool

Less checks if version at index i is less than version at index j

func (Versions) Swap

func (s Versions) Swap(i, j int)

Swap swaps two versions inside the collection by its indices

Jump to

Keyboard shortcuts

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