selfupdate

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package selfupdate implements grant's self-update: GitHub release discovery, platform asset selection, SHA-256 checksum verification and archive extraction, with the binary replacement itself delegated to github.com/minio/selfupdate.

Trust model: checksums.txt is published by GoReleaser alongside the archives and is fetched from the same origin as the binary. Verifying it protects against truncated or corrupted downloads and CDN/transport tampering. It does NOT protect against a compromised GitHub account or release pipeline, since an attacker able to replace the archive can also replace checksums.txt.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareVersions

func CompareVersions(a, b string) (int, error)

CompareVersions parses both versions and compares them by SemVer precedence.

func InterruptedUpdate

func InterruptedUpdate(targetPath string) (hint string, interrupted bool)

InterruptedUpdate reports whether targetPath looks like a previous update that was interrupted between the two renames - the binary is missing but its backup is still there - and returns the command that repairs it.

Types

type Updater

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

Updater checks GitHub Releases and replaces the running binary.

func New

func New(slug, version string) *Updater

New creates an Updater for the given "owner/repo" slug. version is the running build's version, used only for the User-Agent; an empty value becomes "dev".

func (*Updater) UpdateSelf

func (u *Updater) UpdateSelf(ctx context.Context, current string) (newVersion string, updated bool, err error)

UpdateSelf checks for a newer release and, if one exists, downloads, verifies and installs it. It returns the latest published version, whether the binary was replaced, and any error.

type Version

type Version struct {
	Major int
	Minor int
	Patch int
	// Prerelease is the dot-separated pre-release string without the leading
	// "-" (empty when the version is a normal release).
	Prerelease string
	// Build is the build metadata without the leading "+". It never affects
	// ordering.
	Build string
}

Version is a Semantic Versioning 2.0.0 version.

GoReleaser normally emits plain MAJOR.MINOR.PATCH tags, but it can also produce pre-release (`1.2.3-rc.1`) and build-metadata (`1.2.3+build.5`) tags, and grant must be able to update from such a build. Ordering follows SemVer precedence: build metadata is ignored, and a pre-release sorts before its corresponding release.

func ParseVersion

func ParseVersion(s string) (Version, error)

ParseVersion parses a SemVer 2.0.0 version. A leading "v" or "V" is tolerated, since Git tags conventionally carry one and GitHub reports the tag verbatim.

func (Version) Compare

func (v Version) Compare(other Version) int

Compare returns -1 if v < other, 0 if they have equal precedence, and 1 if v > other. Build metadata is ignored, per SemVer 2.0.0 §10.

func (Version) String

func (v Version) String() string

String renders the version without a leading "v".

Jump to

Keyboard shortcuts

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