Documentation
¶
Overview ¶
Package github self-updates a Go CLI binary from its GitHub releases. A tool describes itself with a Config and calls Update, which resolves the latest release, picks the asset matching the host OS/arch, downloads and extracts the binary, and installs it into a directory (default ~/.local/bin). Check reports whether a newer release exists without installing anything.
The release discovery, OS/arch asset matching, archive extraction, checksum validation, and rollback-safe replacement are done by github.com/creativeprojects/go-selfupdate; this package is a thin wrapper that gives a github-distributed tool the same Config/updater.Tool interface, clog UX, install-directory default, and notify integration as updater/brew and updater/goinstall. Private repositories work by piggybacking on the gh CLI's stored credentials (github.com/cli/go-gh) for the API token.
Index ¶
- func Check(ctx context.Context, cfg Config) error
- func Update(ctx context.Context, cfg Config, channel Channel) error
- type Channel
- type Config
- func (c Config) BinaryName() string
- func (c Config) Check(ctx context.Context) error
- func (c Config) DisplayName() string
- func (c Config) LatestRef(ctx context.Context, _ *http.Client) (string, error)
- func (c Config) Update(ctx context.Context, dev, _ bool) error
- func (c Config) VersionLink(v string) string
- type Option
- func WithBinary(binary string) Option
- func WithChecksumFile(name string) Option
- func WithEnterpriseURL(url string) Option
- func WithFilters(filters ...string) Option
- func WithInstallDirectory(dir string) Option
- func WithName(name string) Option
- func WithPrerelease() Option
- func WithSkipChecksum() Option
- func WithTokenEnv(env string) Option
- func WithUniversalArch(arch string) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Channel ¶
type Channel int
Channel selects which release Update installs.
func ChannelFor ¶
ChannelFor maps a --pre flag to a Channel; unset is Latest.
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config identifies the tool for a GitHub release-asset self-update. Build it with New: the info (a GitHub repo via Info.Repo or a github.com module) is required, and optional behaviour is set with the With* [Option]s. It satisfies updater.Tool for notify.
func New ¶ added in v0.2.0
New builds a Config for a GitHub release-asset self-update. info carries the GitHub repo (Info.Repo, or a github.com Info.Module) used to locate releases and build version links. Optional behaviour is configured with the With* [Option]s.
func (Config) BinaryName ¶
BinaryName is the executable/command name, defaulting to the repo (or module) name. It is also the name go-selfupdate looks for inside a downloaded archive.
func (Config) Check ¶ added in v0.2.7
Check implements updater.Updater.
func (Config) DisplayName ¶
DisplayName is the human-facing name used in messages, defaulting to the binary (and thus the repo) name when Name is unset.
func (Config) LatestRef ¶
LatestRef returns the latest release's tag, letting Config satisfy updater.Tool so a github-distributed tool feeds notify the same "latest" the updater installs. The client is unused: go-selfupdate manages its own HTTP.
func (Config) Update ¶ added in v0.2.7
Update implements updater.Updater; dev selects the newest prerelease and stable is ignored (Latest already is the latest stable release).
func (Config) VersionLink ¶
VersionLink renders v as a clickable link to its release or commit, delegating to the embedded clive.Info. It lets Config satisfy updater.Tool.
type Option ¶ added in v0.2.0
type Option func(*Config)
Option customises a Config built by New.
func WithBinary ¶ added in v0.2.0
WithBinary sets the executable name located inside a downloaded archive and installed into the install directory; it defaults to the repo (or module) name.
func WithChecksumFile ¶ added in v0.2.0
WithChecksumFile sets the name of the combined checksums asset verified against the download, for a release that names it other than goreleaser's default "checksums.txt". Ignored when checksum verification is skipped.
func WithEnterpriseURL ¶ added in v0.2.0
WithEnterpriseURL sets the API base URL of a GitHub Enterprise instance, e.g. "https://ghe.example.com/api/v3/"; releases and the gh token are then resolved for that host rather than github.com.
func WithFilters ¶ added in v0.2.0
WithFilters sets regexps matched against asset names, to disambiguate a release that publishes several assets for the same OS/arch. An asset must match one of them in addition to the OS/arch/extension matching.
func WithInstallDirectory ¶ added in v0.2.0
WithInstallDirectory sets the directory the binary is installed into. A leading "~" and any $ENV references are expanded; it defaults to ~/.local/bin.
func WithName ¶ added in v0.2.0
WithName sets the human-facing display name shown in messages; it defaults to the binary (and thus repo) name.
func WithPrerelease ¶ added in v0.2.0
func WithPrerelease() Option
WithPrerelease makes the default channel (used by Check and the notify integration) consider prereleases.
func WithSkipChecksum ¶ added in v0.2.0
func WithSkipChecksum() Option
WithSkipChecksum disables sha256 verification of the downloaded asset against a published checksums file. Verification is on by default.
func WithTokenEnv ¶ added in v0.2.0
WithTokenEnv names an environment variable consulted before the gh CLI's stored credentials for a GitHub token; it defaults to "GITHUB_TOKEN".
func WithUniversalArch ¶ added in v0.2.0
WithUniversalArch sets the architecture name of a macOS universal binary asset (e.g. "all"); that asset is chosen when none matches the host's specific arch.