upgrade

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package upgrade replaces the running octo binary with the latest GitHub release: resolve the latest version from the releases/latest redirect, download the platform archive plus checksums.txt, verify the archive's SHA-256, extract the binary, and atomically swap it into place. The trust anchor is GitHub's TLS plus the release assets' integrity — there is no signature layer. See dev-docs/octo-upgrade-design.md.

Index

Constants

This section is empty.

Variables

View Source
var BaseURL = "https://github.com/Leihb/octo-agent"

BaseURL is the release origin. A var so tests point it at httptest.

View Source
var ErrUpToDate = errors.New("already up to date")

ErrUpToDate reports that the installed version is already the latest. Callers treat it as success, not failure.

Functions

func AssetName

func AssetName(ver string) string

AssetName returns the release archive for this platform and version.

func Check

func Check(ctx context.Context) (string, error)

Check resolves the latest released version (no leading "v") by following none of the releases/latest redirect: the target tag is in the Location header. No GitHub API, so no rate-limit coupling.

func CompareVersions

func CompareVersions(a, b string) int

CompareVersions returns -1/0/+1 for a<b, a==b, a>b on the numeric major.minor.patch triple. Non-numeric parts compare as 0.

func Eligible

func Eligible() error

Eligible reports whether the running build may be auto-upgraded: a release build carries a plain SemVer version AND a commit SHA. Dev builds (-dev/-snapshot suffix from make, or a bare `go build` with no ldflags at all) refuse so a local build isn't silently replaced by an older release.

func Run

func Run(ctx context.Context, opts Options) error

Run upgrades the binary at opts.TargetPath (default: this executable) to the latest release: Prepare + Install in one call, for callers with no gate to scope (the CLI). ErrUpToDate means nothing was done because nothing needed doing.

Types

type Options

type Options struct {
	// Force proceeds despite a dev build or an already-latest version.
	Force bool
	// Log receives one human-readable progress line per step. Nil is fine.
	Log func(string)
	// TargetPath overrides the binary to replace. Defaults to
	// os.Executable() (symlinks resolved); tests point it at a temp file.
	TargetPath string
}

Options configures Run.

type Prepared

type Prepared struct {
	// Latest is the version Install will put in place.
	Latest string
	// contains filtered or unexported fields
}

Prepared holds a verified, extracted new binary ready to install. The split from Run exists so the server can do the slow part (download) outside the restart drain gate and hold the gate only for the seconds-long Install.

func Prepare

func Prepare(ctx context.Context, opts Options) (*Prepared, error)

Prepare checks eligibility, resolves the latest release, downloads and verifies the archive, and extracts the binary — everything except touching the installed file. ErrUpToDate means nothing needs doing. Callers must Close the result.

func (*Prepared) Close

func (p *Prepared) Close()

Close removes the temp download dir.

func (*Prepared) Install

func (p *Prepared) Install() error

Install swaps the prepared binary into place. Fast (local renames only), so a caller holding a drain gate holds it for seconds, not for the download.

Jump to

Keyboard shortcuts

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