selfupdate

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package selfupdate implements `positronick self update`: it classifies how the binary was installed (only the installer receipt authorizes an in-place replace), talks to the GitHub releases API, verifies the downloaded archive against checksums.txt, and swaps the binary atomically.

Index

Constants

View Source
const ChecksumsName = "checksums.txt"

ChecksumsName is the checksum file published with every release — a cross-repo contract with .goreleaser.yaml and both installers.

View Source
const DefaultAPIBase = "https://api.github.com"

DefaultAPIBase is the GitHub REST API the release lookups go to.

View Source
const DefaultRepo = "Positronick/cli"

DefaultRepo is the owner/name of the CLI's release repository.

Variables

This section is empty.

Functions

func AssetName

func AssetName(goos, goarch string) string

AssetName returns the release archive name for a platform — the same cross-repo naming contract (windows releases use .zip, which this updater does not handle).

func DetectMethod

func DetectMethod(receiptMethod, binPath, goBin string) string

DetectMethod classifies the install method. The receipt is authoritative when it says "installer"; otherwise the resolved binary path is matched against homebrew, npm and go-install conventions (goBin is the caller's resolved go-install bin directory, "" when unknown). Everything else is "unknown" and treated like a package-manager install.

func SameVersion

func SameVersion(current, tag string) bool

SameVersion reports whether the current build version and a release tag name the same version, ignoring any leading "v" (goreleaser injects "0.2.0", tags are "v0.2.0").

func UpgradeCommand

func UpgradeCommand(method string) string

UpgradeCommand returns the copy-pasteable upgrade command for a non-installer method ("" only for "installer" itself).

Types

type Asset

type Asset struct {
	Name               string `json:"name"`
	BrowserDownloadURL string `json:"browser_download_url"`
}

Asset is one downloadable file attached to a release.

type Release

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

Release is the subset of the GitHub release object the updater needs.

type Updater

type Updater struct {
	// APIBase is the GitHub REST API base URL (DefaultAPIBase in production).
	APIBase string
	// Repo is the owner/name release repository.
	Repo string
	// HTTP is the client used for every request; nil gets a 30s-timeout default.
	HTTP *http.Client
	// BinPath is the resolved (symlink-free) path of the running binary.
	BinPath string
	// GOOS and GOARCH pick the release asset, e.g. positronick_linux_amd64.tar.gz.
	GOOS, GOARCH string
}

Updater performs release lookups and the in-place binary swap. APIBase is injectable so tests run against httptest instead of api.github.com.

func (*Updater) Apply

func (u *Updater) Apply(ctx context.Context, rel *Release) error

Apply downloads the platform archive and checksums.txt from rel, verifies the archive's sha256 against the published checksum, extracts the binary, and replaces BinPath atomically (a temp file in the same directory renamed into place, mode 0755). On success the install receipt next to the binary is rewritten with the new version. Verification failures leave the existing binary and receipt untouched.

func (*Updater) ByTag

func (u *Updater) ByTag(ctx context.Context, tag string) (*Release, error)

ByTag fetches one release by tag; a missing "v" prefix is added so both "0.2.0" and "v0.2.0" work.

func (*Updater) Latest

func (u *Updater) Latest(ctx context.Context) (*Release, error)

Latest fetches the most recent release.

Jump to

Keyboard shortcuts

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