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
- func CachePath() (string, error)
- func Comparable(version string) string
- func Disabled(lookupEnv func(string) (string, bool)) bool
- func Display(version string) string
- func Hint(method Method, version, executablePath string) string
- func IsRelease(version string) bool
- func Newer(current, candidate string) bool
- func Notice(currentVersion, latestVersion string, method Method, executablePath string) string
- type Checker
- type Feed
- type GitHubFeed
- type Lookup
- type Method
Constants ¶
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.
const EnvDisable = "GRAFO_NO_UPDATE_CHECK"
EnvDisable turns the automatic check off entirely.
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 ¶
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 ¶
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 ¶
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 ¶
Display renders a version for the terminal without the leading "v", matching how `grafo version` already prints the running build.
func Hint ¶
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 ¶
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 ¶
Newer reports whether candidate supersedes current. Anything unparsable on either side answers false, so a malformed feed response can never produce a notice.
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 ¶
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 ¶
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 ¶
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 ¶
UpgradeHint names the command that moves this install to latest.
type GitHubFeed ¶
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.
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 ¶
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.