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 ¶
- Constants
- func Apply(ctx context.Context, r *Release, progress io.Writer) error
- func CachedNotice() string
- func CachedSkills() (latest string, checkedAt time.Time, ok bool)
- func ChangelogURL(version string) string
- func LatestSkills(ctx context.Context) (string, error)
- func Notice(r *Release) string
- func RecordCheck(r *Release)
- func Refresh(ctx context.Context) error
- func RenderNotes(w io.Writer, notes []Notes, limit int, s cliui.TerminalStyles, width int)
- func Stale() bool
- type Line
- type Notes
- type Release
Constants ¶
const ReleasesURL = "https://github.com/" + repoSlug + "/releases"
ReleasesURL is the page listing every release and its notes.
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 ChangelogURL ¶ added in v0.17.0
ChangelogURL is where CHANGELOG.md is as of version's release: its notes, and every release's before it.
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.
func Refresh ¶
Refresh runs a live check, of anfra and of the skills, and updates the cache. One failing doesn't stop the other. Called from the detached background refresh (see cmd/anfra), never in a command's hot path.
func RenderNotes ¶ added in v0.15.1
RenderNotes writes what the newest limit releases in notes changed, then a link to the rest: per release, a heading and its page, then its changelog's sections, a change per line wrapped under its text to width (0 doesn't wrap). The zero styles write plain text. The notes come from GitHub: they are written as text, never as escapes.
Types ¶
type Line ¶ added in v0.15.1
Line is a line of a changelog: a section's heading ("Features"), or a change and, when it names one, the part of anfra it touches, its scope ("cli").
type Notes ¶ added in v0.15.1
type Notes struct {
Version string
URL string // the release's page
// Changelog is the release's changelog as plain text, empty when its notes
// have none.
Changelog []Line
}
Notes is what one release changed, from its notes on GitHub.
func ReleaseNotes ¶ added in v0.15.1
ReleaseNotes fetches the notes of the releases after from, up to and including to, newest first: everything an update from one to the other brings, the releases it skips included.
It reads them from CHANGELOG.md at to's tag, of which each release's notes are a section (scripts/release-notes.sh), rather than from GitHub's API, which allows 60 anonymous calls an hour (see Latest).
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.