selfupgrade

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 31 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package selfupgrade replaces the running rune binary with the latest stable release. Nothing is extracted or installed until the release's checksum list is proven to be signed by the release workflow and the downloaded archive matches it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PublicTrust

func PublicTrust(client *http.Client) func(context.Context) (root.TrustedMaterial, error)

PublicTrust returns a source of the public Sigstore trust root. It is fetched through TUF on every call and nothing is cached on disk, so a run writes nothing outside the install directory.

Types

type Config

type Config struct {
	// Version is the version this binary reports; Stamped says whether it was
	// set at build time (a release build) or read from module build info.
	Version string
	Stamped bool
	ExePath string
	GOOS    string
	GOARCH  string
	Getenv  func(string) string
	Now     func() time.Time

	HTTP         *http.Client
	APIBase      string
	DownloadBase string

	// Trust returns the Sigstore trust root; Issuer and Subject are the only
	// signer identity accepted.
	Trust   func(context.Context) (root.TrustedMaterial, error)
	Issuer  string
	Subject string

	// Logf receives progress lines, without a prefix or newline.
	Logf func(format string, args ...any)
}

Config is everything an upgrade depends on. All of it is injected so tests run without the network and nothing lives in package globals.

type Error

type Error struct {
	Reason    Reason
	Installed string
	Target    string
	// Subject is what the message is about: a host, a file, a directory, a
	// path, or an os/arch pair, depending on Reason.
	Subject string
	Limit   string
	Until   string
	// Status is the HTTP status behind a failed request, when there was one.
	Status int
	Err    error
}

Error is an expected failure of an upgrade. The installed binary is unchanged whenever one is returned, with one exception the message spells out: a Windows replacement that failed and could not be rolled back.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Origin

type Origin string

Origin is how the running binary was installed. Only a standalone install is upgraded in place; every other origin has its own upgrade path, and overwriting it would leave that tool's records wrong.

const (
	OriginDevelopment Origin = "development"
	OriginGoInstall   Origin = "go-install"
	OriginContainer   Origin = "container"
	OriginHomebrew    Origin = "homebrew"
	OriginScoop       Origin = "scoop"
	OriginStandalone  Origin = "standalone"
)

type Outcome

type Outcome string

Outcome is what a successful run did.

const (
	OutcomeUpgraded Outcome = "upgraded"
	OutcomeCurrent  Outcome = "current"
)

type Reason

type Reason string

Reason names why an upgrade did not happen. Each has its own message.

const (
	ReasonOffline             Reason = "offline"
	ReasonTimeout             Reason = "timeout"
	ReasonRateLimited         Reason = "rate-limited"
	ReasonReleaseLookup       Reason = "release-lookup"
	ReasonUnsupportedPlatform Reason = "unsupported-platform"
	ReasonUnverified          Reason = "unverified"
	ReasonChecksumMismatch    Reason = "checksum-mismatch"
	ReasonDownloadFailed      Reason = "download-failed"
	ReasonTooLarge            Reason = "too-large"
	ReasonBadArchive          Reason = "bad-archive"
	ReasonNotWritable         Reason = "not-writable"
	ReasonInProgress          Reason = "in-progress"
	ReasonReplaceFailed       Reason = "replace-failed"
)

type Refused

type Refused struct {
	Origin  Origin
	Path    string
	Version string
}

Refused is returned when the install is not Rune's to upgrade. The message names the command that upgrades it the way it was installed.

func (*Refused) Error

func (r *Refused) Error() string

type Result

type Result struct {
	Outcome   Outcome
	Installed string
	Target    string
	Path      string
}

Result describes a run. Installed and Path are set as soon as they are known, so they are meaningful next to an error too.

type Upgrader

type Upgrader struct {
	// contains filtered or unexported fields
}

Upgrader runs one self-upgrade.

func New

func New(cfg Config) (*Upgrader, error)

New validates cfg and returns an Upgrader.

func (*Upgrader) Run

func (u *Upgrader) Run(ctx context.Context) (Result, error)

Run performs the upgrade. The installed binary changes only in the last step, after the release's signature and the archive's checksum have passed.

Directories

Path Synopsis
Package upgradetest builds a signed fixture release on a local TLS server, in the layout a real Rune release has.
Package upgradetest builds a signed fixture release on a local TLS server, in the layout a real Rune release has.

Jump to

Keyboard shortcuts

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