update

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRepository = "Twigpine/zero"
	DefaultTimeout    = 5 * time.Second
)
View Source
const DefaultDownloadTimeout = 5 * time.Minute

DefaultDownloadTimeout bounds the archive/checksum download phase of a standalone Apply, separately from Options.Timeout (which only covers the small release-metadata check), so a stalled connection can't hang forever.

Variables

View Source
var ErrTargetPossiblyTampered = errors.New("target executable path may hold unverified content after a failed update")

ErrTargetPossiblyTampered reports that an executable path may hold content this updater could not verify, because a promotion failed and the original could not be restored over it. Only the Windows promotion path produces it today (see replace_windows.go for why that platform has the gap and the POSIX descriptor-bound path does not), but it is declared here so callers on every platform can test for it without build tags — the helper-refresh loop below must fail the apply on it rather than downgrade it to a warning.

Functions

func Endpoint

func Endpoint(repository string) string

Endpoint returns the GitHub latest-release API endpoint for a repository.

func Format

func Format(result Result) string

func FormatApply added in v0.2.0

func FormatApply(result ApplyResult) string

FormatApply renders an ApplyResult as human-readable text.

Types

type ApplyResult added in v0.2.0

type ApplyResult struct {
	Result
	Applied       bool          `json:"applied"`
	InstallMethod InstallMethod `json:"installMethod,omitempty"`
	BinaryPath    string        `json:"binaryPath,omitempty"`
	Message       string        `json:"message,omitempty"`
	Warnings      []string      `json:"warnings,omitempty"`
}

ApplyResult reports the outcome of Apply.

func Apply added in v0.2.0

func Apply(ctx context.Context, options Options) (ApplyResult, error)

Apply checks for an update and, if one is available, installs it: via `npm install -g` for npm-managed installs, or by downloading, verifying, and atomically replacing the binary for standalone installs.

type Asset

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

type AssetCheck

type AssetCheck struct {
	Platform      string `json:"platform"`
	Arch          string `json:"arch"`
	ArchiveName   string `json:"archiveName"`
	ArchiveURL    string `json:"archiveUrl,omitempty"`
	ChecksumName  string `json:"checksumName"`
	ChecksumURL   string `json:"checksumUrl,omitempty"`
	ArchiveFound  bool   `json:"archiveFound"`
	ChecksumFound bool   `json:"checksumFound"`
	Verified      bool   `json:"verified"`
}

type InstallMethod added in v0.2.0

type InstallMethod string

InstallMethod identifies how the running zero binary was installed.

const (
	InstallMethodNpm InstallMethod = "npm"
	// InstallMethodNpmLegacy is an npm install of legacyNpmPackageName.
	InstallMethodNpmLegacy  InstallMethod = "npm-legacy"
	InstallMethodHomebrew   InstallMethod = "homebrew"
	InstallMethodStandalone InstallMethod = "standalone"
)

func DetectInstallMethod added in v0.2.0

func DetectInstallMethod(executablePath string) InstallMethod

DetectInstallMethod reports how the binary at executablePath was installed.

Symlinks are resolved here rather than at the call sites. Homebrew links <prefix>/bin/zero to the keg, and Check did not resolve while Apply did, so the two disagreed about what a Homebrew install was: the check printed standalone guidance for an install the apply path would have handled differently.

type Options

type Options struct {
	CurrentVersion string
	// Endpoint accepts a full release API URL, an owner/repo slug, or a data:
	// endpoint for deterministic tests.
	Endpoint   string
	Repository string
	Timeout    time.Duration
	GOOS       string
	GOARCH     string
	// Fetch overrides the release fetcher for tests and alternate transports.
	Fetch func(context.Context, string) (Release, error)
}

Options configures a release update check.

type Release

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

type Result

type Result struct {
	CurrentVersion  string     `json:"currentVersion"`
	LatestVersion   string     `json:"latestVersion"`
	ReleaseURL      string     `json:"releaseUrl"`
	TagName         string     `json:"tagName"`
	ReleaseAsset    AssetCheck `json:"releaseAsset"`
	UpdateAvailable bool       `json:"updateAvailable"`
	// SourceFlag is the `--repo`/`--endpoint` argument this check was given, in
	// the form a caller would repeat on `zero upgrade`. Empty when the check used
	// the default release source. Format needs it because `zero upgrade` is a
	// fresh invocation: it does not inherit the flags of the check that suggested
	// it, so recommending it bare after a custom-source check would send the user
	// to install from somewhere they did not ask about.
	SourceFlag string `json:"sourceFlag,omitempty"`
	// contains filtered or unexported fields
}

func Check

func Check(ctx context.Context, options Options) (Result, error)

type Target

type Target struct {
	Name     string `json:"name"`
	GOOS     string `json:"goos"`
	GOARCH   string `json:"goarch"`
	Platform string `json:"platform"`
	Arch     string `json:"arch"`
}

Target identifies a supported release archive target.

func ResolveTarget

func ResolveTarget(target string) (Target, error)

ResolveTarget maps a release target name like windows-x64 to Go build coordinates and release asset naming fields.

Jump to

Keyboard shortcuts

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