update

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

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

View Source
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

func Apply(ctx context.Context, r *Release, progress io.Writer) error

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

func CachedSkills() (latest string, checkedAt time.Time, ok bool)

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

func ChangelogURL(version string) string

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

func LatestSkills(ctx context.Context) (string, error)

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

func Notice(r *Release) string

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

func Refresh(ctx context.Context) error

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 RefreshSkills added in v0.19.0

func RefreshSkills(ctx context.Context) error

RefreshSkills runs a live check of the skills alone, and updates the cache. A failure is cached as unknown.

func RenderNotes added in v0.15.1

func RenderNotes(w io.Writer, notes []Notes, limit int, s cliui.TerminalStyles, width int)

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.

func Stale

func Stale() bool

Stale reports whether the cached check, of anfra or of the skills, is missing or older than the TTL, unless anfra's check failed less than retryAfter ago. A time in the future, left by a clock moved back, counts as long ago, so checks don't pause until the clock catches up.

Types

type Line added in v0.15.1

type Line struct {
	Heading bool
	Scope   string
	Text    string
}

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

func ReleaseNotes(ctx context.Context, from, to string) ([]Notes, error)

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

func Check(ctx context.Context) (*Release, error)

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

func Latest(ctx context.Context) (_ *Release, err error)

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.

func (*Release) IsNewer

func (r *Release) IsNewer() bool

IsNewer reports whether the latest version is newer than the running one, so worth announcing and installing. Never for a build from source: it was built on purpose, and a release would replace it with something else.

Jump to

Keyboard shortcuts

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