Help us shape the future of Go! Take the 2026 Go Developer Survey

selfupdate

package
v0.19.12 Latest Latest
Warning

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

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

Documentation

Overview

Package selfupdate replaces the running orb with a signed release: it fetches the same archive and checksums.txt that scripts/install.sh does, verifies the signature and sha256, and swaps the binary by atomic rename. Deliberately absent: backups, retries, elevation.

Index

Constants

View Source
const (
	MetadataWait = 30 * time.Second
	DownloadWait = 5 * time.Minute

	LatestReleaseURL = "https://api.github.com/repos/OrdalieTech/orb/releases/latest"
)

Variables

View Source
var (
	ErrDevelopment = errors.New("development build")
	ErrOffline     = errors.New("offline")
	ErrCurrent     = errors.New("already current")
)

Functions

func BuildVersion

func BuildVersion(stamped string, info *debug.BuildInfo, ok bool) string

BuildVersion recovers the version for `go install ...@latest`, which builds without the release ldflags: the module proxy stamps the tag into the build info. A "(devel)" build has none and skips.

func IsDevelopment

func IsDevelopment(value string) bool

func LatestTag

func LatestTag(ctx context.Context, currentVersion string, client *http.Client, endpoint string, timeout time.Duration) (string, error)

LatestTag asks endpoint, GitHub's latest-release API, for its tag.

func Plain

func Plain(value string) string

func Swap

func Swap(target string, payload []byte, before os.FileInfo) error

Swap stages the payload beside the target so the rename is atomic on the same filesystem, and leaves the target untouched on every failure.

Types

type Updater

type Updater struct {
	Key            ed25519.PublicKey
	CurrentVersion string
	ReleaseURL     string
	ReleaseBase    string
	Client         *http.Client
	Offline        bool
	Executable     func() (string, error)
	ResolveLinks   func(string) (string, error)
}

Updater injects every effect an update has, so a test never resolves or overwrites the binary running it.

func New

func New(stamped string, offline bool) Updater

New updates this build, whose stamped version is stamped.

func (Updater) Download

func (u Updater) Download(ctx context.Context, tag, goos, goarch string) ([]byte, error)

Download fetches and verifies the orb binary of release tag for goos/goarch, from the exact URLs scripts/install.sh builds.

func (Updater) Latest

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

Latest is the tag of the latest release.

func (Updater) Update

func (u Updater) Update(ctx context.Context, step func(string) func()) (tag, target string, err error)

Update brings the running binary to the latest release. step announces "checking release", "fetching release" and "replacing binary" as each begins and returns the func that ends it. It returns the release installed and the file replaced; ErrDevelopment, ErrOffline and ErrCurrent leave everything as it was.

Jump to

Keyboard shortcuts

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