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

updatecheck

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package updatecheck reports when a newer Grafo release exists and names the command that upgrades the binary the caller is actually running.

Every operation here is advisory. A failed lookup, an unreadable cache or an unreachable network leaves the caller with no notice rather than an error: an update check that interrupts a command is worse than no update check.

Index

Constants

View Source
const EnvCachePath = "GRAFO_UPDATE_CACHE"

EnvCachePath overrides where the last lookup is remembered. Tests and sandboxed environments set it so a check never touches the real cache.

View Source
const EnvDisable = "GRAFO_NO_UPDATE_CHECK"

EnvDisable turns the automatic check off entirely.

View Source
const LatestReleaseURL = "https://api.github.com/repos/cafecito-games/grafo/releases/latest"

LatestReleaseURL is the GitHub endpoint that reports the newest published release. The endpoint skips prereleases, which matters because the release workflow marks them automatically.

Variables

This section is empty.

Functions

func CachePath

func CachePath() (string, error)

CachePath is where the last lookup is remembered. It sits in the user cache directory beside the embedding cache so one check serves every repository on the machine.

func Comparable

func Comparable(version string) string

Comparable normalizes a Grafo version or Git tag into the form golang.org/x/mod/semver accepts. Releases are stamped without the leading "v" by GoReleaser while the Git tags carry it, so both spellings have to resolve to the same comparable value.

func Disabled

func Disabled(lookupEnv func(string) (string, bool)) bool

Disabled reports whether the environment turns the automatic check off. Continuous integration is excluded by default because a notice there reaches a log nobody upgrades from.

func Display

func Display(version string) string

Display renders a version for the terminal without the leading "v", matching how `grafo version` already prints the running build.

func Hint

func Hint(method Method, version, executablePath string) string

Hint names the command that upgrades an install of the given method to version. executablePath is only used by the archive form, which has to say which file to replace; an empty path drops that clause.

func IsRelease

func IsRelease(version string) bool

IsRelease reports whether a version string came from a release build. Local builds and `go install` from a branch carry the in-tree default, which has no release to compare against, so they are never offered an upgrade.

func Newer

func Newer(current, candidate string) bool

Newer reports whether candidate supersedes current. Anything unparsable on either side answers false, so a malformed feed response can never produce a notice.

func Notice

func Notice(currentVersion, latestVersion string, method Method, executablePath string) string

Notice is the two-line advisory printed after a command finishes. The first line states the fact, the second states the action, so a reader who already knows about the release can stop after one line.

Types

type Checker

type Checker struct {
	CurrentVersion string
	ExecutablePath string
	Method         Method
	Feed           Feed
	CachePath      string
	Now            func() time.Time
	MaxAge         time.Duration
	FetchTimeout   time.Duration
	WaitBudget     time.Duration
}

Checker decides whether a newer release exists and renders the advisory. Its clock, feed and cache location are fields so no test reaches the network or the real cache directory.

func NewChecker

func NewChecker(currentVersion string) *Checker

NewChecker builds the production checker for the running binary. A cache path that cannot be resolved yields a checker that still works, lookup by lookup, without remembering anything.

func (*Checker) LatestRelease

func (c *Checker) LatestRelease(ctx context.Context) (string, error)

LatestRelease reads the feed directly, bypassing the cache. It is the path `grafo version --check` takes, and the only path that reports its errors.

func (*Checker) Start

func (c *Checker) Start(ctx context.Context) *Lookup

Start begins a check. It reads the remembered lookup, which costs one small local file read, and starts a background request only when that record is missing or older than MaxAge. The command itself is never blocked.

func (*Checker) UpgradeHint

func (c *Checker) UpgradeHint(latest string) string

UpgradeHint names the command that moves this install to latest.

type Feed

type Feed interface {
	LatestRelease(ctx context.Context) (string, error)
}

Feed reports the newest published release tag.

type GitHubFeed

type GitHubFeed struct {
	URL    string
	Client *http.Client
}

GitHubFeed reads the latest release from the GitHub API.

func (GitHubFeed) LatestRelease

func (f GitHubFeed) LatestRelease(ctx context.Context) (string, error)

type Lookup

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

Lookup is an in-progress or already-answered check. A nil Lookup renders no notice, so callers that skipped the check need no special case.

func (*Lookup) Notice

func (l *Lookup) Notice() string

Notice renders the advisory for a finished command, or an empty string when there is nothing to say. It waits at most WaitBudget for a lookup that is still in flight.

type Method

type Method string

Method is how the running binary was installed, which decides the upgrade command the caller is told to run.

const (
	// MethodHomebrew is an install from the cafecito-games/homebrew-tap cask.
	MethodHomebrew Method = "homebrew"
	// MethodGoInstall is an install from `go install`, which lands in GOBIN.
	MethodGoInstall Method = "go-install"
	// MethodArchive is an install from a release archive, or anything this
	// package cannot attribute to a package manager.
	MethodArchive Method = "archive"
)

func Detect

func Detect(executablePath string) Method

Detect classifies the binary at executablePath. The caller passes the path so tests can cover every layout, and so a failure to locate the running executable degrades to MethodArchive instead of guessing.

The path is resolved through its symlinks first: Homebrew links <prefix>/bin/grafo at a versioned file inside the Caskroom, so an unresolved path reports every cask install as an archive install.

func DetectRunning

func DetectRunning() Method

DetectRunning classifies the currently running binary.

Jump to

Keyboard shortcuts

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