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 ¶
const ChecksumsName = "checksums.txt"
ChecksumsName is the checksum file published with every release — a cross-repo contract with .goreleaser.yaml and both installers.
const DefaultAPIBase = "https://api.github.com"
DefaultAPIBase is the GitHub REST API the release lookups go to.
const DefaultRepo = "Positronick/cli"
DefaultRepo is the owner/name of the CLI's release repository.
Variables ¶
This section is empty.
Functions ¶
func AssetName ¶
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 ¶
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 ¶
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 ¶
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 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 ¶
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.