update

package
v0.3.22 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package update implements a self-updater that fetches the latest release from GitHub and swaps the running binary in place. It uses only the standard library: the GitHub REST API for release discovery and an atomic rename-based swap that also works on Windows, where a running executable cannot be overwritten but can be renamed aside.

Private repositories are supported via a GitHub token, discovered from GH_TOKEN / GITHUB_TOKEN or, failing that, the `gh` CLI (`gh auth token`).

Index

Constants

View Source
const DefaultRepo = "joshkerr/goplexcli"

DefaultRepo is the GitHub "owner/name" the updater pulls releases from.

Variables

This section is empty.

Functions

func Apply

func Apply(ctx context.Context, asset *Asset, token, exePath string) error

Apply downloads asset and replaces the executable at exePath with it. The swap renames the running binary to "<exe>.old" before moving the new binary into place, which is the only approach that works while the binary is executing on Windows. On success it best-effort removes the ".old" file.

The download uses the API asset endpoint with Accept: application/octet-stream so it works for private repos when token is set; GitHub redirects to a signed URL and Go drops the Authorization header on the cross-host redirect.

func AssetName

func AssetName() string

AssetName returns the release asset name expected for the current platform, matching the names produced by `make build-all` (e.g. "goplexcli-darwin-arm64", "goplexcli-windows-amd64.exe").

func CompareVersions

func CompareVersions(a, b string) int

CompareVersions compares two dotted version strings, ignoring a leading "v". It returns -1 if a < b, 0 if equal, and 1 if a > b. Non-numeric components compare as 0, so unparseable versions degrade to "equal" rather than erroring.

func DownloadAsset added in v0.3.15

func DownloadAsset(ctx context.Context, asset *Asset, token, destPath string) error

DownloadAsset downloads asset to destPath, authenticating with token when set (required for private repos). It uses the API asset endpoint with Accept: application/octet-stream so GitHub redirects to a signed URL. The caller controls timeouts via ctx (pass a generous deadline — GUI bundles are larger than the CLI binary). It verifies the byte count against asset.Size when known. Used by the GUI self-updater, which downloads a zip bundle rather than swapping a bare binary.

func Run

func Run(ctx context.Context, repo, currentVersion string, checkOnly bool, out io.Writer) error

Run performs the full update flow and writes human-readable progress to out. currentVersion is the running build's version; a value of "dev" disables updates. When checkOnly is true it reports availability without downloading.

Types

type Asset

type Asset struct {
	Name               string `json:"name"`
	URL                string `json:"url"`
	BrowserDownloadURL string `json:"browser_download_url"`
	Size               int64  `json:"size"`
}

Asset is a single downloadable file attached to a release. URL is the API asset endpoint (used for authenticated downloads on private repos); BrowserDownloadURL is the public direct link.

type Release

type Release struct {
	TagName string  `json:"tag_name"`
	HTMLURL string  `json:"html_url"`
	Assets  []Asset `json:"assets"`
}

Release is the subset of a GitHub release we care about.

func LatestRelease

func LatestRelease(ctx context.Context, repo, token string) (*Release, error)

LatestRelease fetches the most recent published release for repo ("owner/name"). If token is non-empty it is sent as a bearer credential, which is required for private repositories.

func ResolveLatest added in v0.3.15

func ResolveLatest(ctx context.Context, repo string) (*Release, string, error)

ResolveLatest fetches the latest release for repo, trying each GitHub token candidate in turn (env vars, the gh CLI, then unauthenticated) until one succeeds. It returns the release and the token that worked (empty when the unauthenticated attempt succeeded), so the caller can reuse that same token to download the release's assets. This tolerates a stale env token by falling back to the gh CLI and finally to a public request.

func (*Release) FindAsset

func (r *Release) FindAsset(name string) (*Asset, bool)

FindAsset returns the asset matching the given name, if present.

Jump to

Keyboard shortcuts

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