Documentation
¶
Overview ¶
Package update implements anfra's self-update: discover the latest GitHub release, compare it to the compiled-in version, download the binary for this platform, and atomically replace the running executable.
Follows the common CLI pattern (gh, deno, bun): a manual `anfra update` command plus a cached, non-blocking "update available" notice. Fully-automatic update is opt-in (ANFRA_AUTO_UPDATE), never the default.
Index ¶
- func Apply(ctx context.Context, r *Release, progress io.Writer) error
- func CachedNotice() string
- func CachedSkills() (latest string, checkedAt time.Time, ok bool)
- func LatestSkills(ctx context.Context) (string, error)
- func Notice(r *Release) string
- func RecordCheck(r *Release)
- func Refresh(ctx context.Context) error
- func Stale() bool
- type Release
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
Apply downloads the platform asset and atomically replaces the running binary. If progress is non-nil, download progress is rendered to it (a single, in-place updated line); pass nil for a silent download (agents/CI).
func CachedNotice ¶
func CachedNotice() string
CachedNotice returns a one-line "update available" message from the cached check, or "" if none is available / the cache says we're current.
func CachedSkills ¶ added in v0.15.0
CachedSkills is the latest anfra skills version from the cached check, and when it was checked; false when it wasn't, or the fetch failed. No network.
func LatestSkills ¶ added in v0.15.0
LatestSkills fetches the latest anfra skills version: the version in the skills repo's plugin manifest on main. It is a file GitHub serves from its CDN, not its API, so it doesn't count against the API's rate limit, which everyone behind one address shares (60 an hour, anonymous).
func Notice ¶
Notice is the one-line "update available" message for r, or "" when r is not newer than the running version.
func RecordCheck ¶
func RecordCheck(r *Release)
RecordCheck stores an already-fetched release in the cache (no network), so a foreground check refreshes the notice cache without a second request. It keeps the skills' check as it was.
Types ¶
type Release ¶
type Release struct {
Version string // e.g. "0.2.0" (the tag without its prefix)
Tag string // e.g. "v0.2.0"
AssetURL string // where this platform's asset downloads
}
Release is the latest release plus the asset for the running platform.
func Cached ¶
func Cached() *Release
Cached returns the latest release from the cached check (no network), or nil when there is none. Its AssetURL is empty: it can be reported, not applied.
func Check ¶
Check returns the latest release: the cached one while it is fresh, else a live lookup, which it caches. For a long-running process (serve), which can afford the request off its hot path; a short command uses Cached and Refresh.
func Latest ¶
Latest fetches the newest release and resolves the asset for this platform.
It asks GitHub's site, not its API: the API allows 60 anonymous calls an hour, shared by everyone behind one address, such as an office or CI. The site's latest release redirects to its tag, and its asset downloads at a fixed path. A release whose asset for this platform isn't there yet, as while its build uploads, isn't the latest.