Documentation
¶
Overview ¶
Package release provides the shared release model (Release, ReleaseAsset) and a Provider factory that resolves the correct VCS backend (GitHub or GitLab) from tool configuration for use by the self-update system.
Index ¶
Constants ¶
const ( SourceTypeGitHub = "github" SourceTypeGitLab = "gitlab" SourceTypeBitbucket = "bitbucket" SourceTypeGitea = "gitea" SourceTypeCodeberg = "codeberg" SourceTypeDirect = "direct" )
SourceType constants identify the built-in release provider types. Any string is accepted by the registry; downstream consumers may define their own constants for custom providers.
Variables ¶
var ( // ErrProviderNotFound is returned by Lookup when no factory has been // registered for the requested source type. ErrProviderNotFound = errors.New("no release provider registered for source type") // ErrNotSupported is returned by provider methods that are not applicable // for the underlying platform (e.g. ListReleases on Bitbucket). ErrNotSupported = errors.New("operation not supported by this release provider") // ErrVersionUnknown is returned by the direct provider when neither // version_url nor pinned_version is configured and a version check is // requested. ErrVersionUnknown = errors.New("cannot determine latest version: configure version_url or pinned_version in Params") )
Functions ¶
func Register ¶
func Register(sourceType string, factory ProviderFactory)
Register associates a source type string with a ProviderFactory. Safe to call concurrently. Intended to be called from init() functions or early in main() before any Lookup call. Calling Register with an already-registered type overwrites the previous factory.
func RegisteredTypes ¶
func RegisteredTypes() []string
RegisteredTypes returns a sorted slice of all currently registered source type strings. Used for generating user-facing error messages.
Types ¶
type ChecksumProvider ¶
type ChecksumProvider interface {
// DownloadChecksumManifest returns the raw bytes of the checksums
// manifest for the given release. maxBytes caps the response so
// a hostile server cannot stream indefinitely; implementations
// return an error wrapping [ErrNotSupported] or a provider-
// specific size error when the response exceeds the bound.
//
// Returns [ErrNotSupported] when the provider is configured in a
// way that disables checksum retrieval (e.g. the Direct
// provider's `checksum_url_template` param is empty). The caller
// treats [ErrNotSupported] exactly like "provider does not
// implement this interface" — fall back to asset-by-name lookup
// if one is available, otherwise respect the require_checksum
// policy.
DownloadChecksumManifest(ctx context.Context, rel Release, maxBytes int64) ([]byte, error)
}
ChecksumProvider is an OPTIONAL interface implemented by release providers that can fetch a checksums manifest by means other than a standard release-asset download. The canonical case is the Direct provider's `checksum_url_template` param, which composes a URL from a template that may point outside the release-asset listing entirely.
The update flow does a type assertion at runtime — providers that do not implement this interface fall back to the default behaviour of locating `checksums.txt` by filename within the release's asset list. This keeps third-party Provider implementations source-compatible: they gain the feature by opting in, not by implementing a new required method.
type Provider ¶
type Provider interface {
GetLatestRelease(ctx context.Context, owner, repo string) (Release, error)
GetReleaseByTag(ctx context.Context, owner, repo, tag string) (Release, error)
ListReleases(ctx context.Context, owner, repo string, limit int) ([]Release, error)
DownloadReleaseAsset(ctx context.Context, owner, repo string, asset ReleaseAsset) (io.ReadCloser, string, error)
}
Provider defines the operations a release backend must support.
type ProviderFactory ¶
type ProviderFactory func(source ReleaseSourceConfig, cfg config.Containable) (Provider, error)
ProviderFactory is a function that constructs a release.Provider from a ReleaseSourceConfig and a Viper configuration subtree.
func Lookup ¶
func Lookup(sourceType string) (ProviderFactory, error)
Lookup returns the ProviderFactory registered for the given source type. Returns ErrProviderNotFound if no factory has been registered for that type.
type Release ¶
type Release interface {
GetName() string
GetTagName() string
GetBody() string
GetDraft() bool
GetAssets() []ReleaseAsset
}
Release defines the common abstraction for a software release.
type ReleaseAsset ¶
ReleaseAsset defines the common abstraction for a release asset.
type ReleaseSourceConfig ¶
type ReleaseSourceConfig struct {
Type string
Host string
Owner string
Repo string
Private bool
// Params holds provider-specific configuration key/value pairs.
// Keys use snake_case. Valid keys are documented per provider.
Params map[string]string
}
ReleaseSourceConfig carries the information a ProviderFactory needs to construct its client. It is populated from props.ReleaseSource, and exists as a separate type to avoid a circular import between pkg/vcs/release and pkg/props.