update

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package update checks GitHub Releases for a newer `teams` and reports it.

It is the one thing in the CLI that talks to a host other than the configured cloud, so it is deliberately small, opt-out and boring:

  • it is never automatic in a non-interactive run (PLAN.md:351) and never runs at all when `TEAMS_NO_UPDATE_CHECK` is set or `update_check = false` is in the config;
  • an answer is cached for DefaultInterval in the profile's state dir, so a daily check is one request a day at most;
  • every failure is the caller's to swallow: an offline machine, a rate limit or a proxy must never turn into a CLI error.

The release list it reads is public and carries no user data; the request sends no token and no identifying header beyond the User-Agent the CLI sets everywhere.

Index

Constants

View Source
const (
	// DefaultAPIBase is GitHub's REST API root. The check never follows a
	// redirect off this host, and the base is only overridden by the in-process
	// tests (there is no flag or environment variable for it, so a released
	// binary cannot be pointed elsewhere).
	DefaultAPIBase = "https://api.github.com"
	// DefaultRepoPath is the GitHub Releases endpoint for this project.
	DefaultRepoPath = "/repos/floriscornel/teams-cli/releases/latest"
	// DefaultInterval is how long a cached answer is reused.
	DefaultInterval = 24 * time.Hour
	// DefaultTimeout bounds the check's own request. It is short on purpose: a
	// user who did not ask for the check must never wait for it.
	DefaultTimeout = 3 * time.Second
)

Defaults for Options.

Variables

View Source
var ErrInvalidVersion = errors.New("update: not a version")

ErrInvalidVersion reports a version string that is not semver-like.

Functions

func Compare

func Compare(a, b string) (int, error)

Compare orders two version strings: -1 when a is older, 0 when they are the same version, +1 when a is newer.

It implements the semver ordering rules that matter here (semver 2.0.0 §11): an optional "v" prefix, dot-separated numeric parts, an optional prerelease that sorts *below* the same version without one, and build metadata (+…) that is ignored. A missing part counts as zero, so "1.0" and "1.0.0" are equal. A plain `go build` reports "dev", which callers detect separately rather than asking Compare to order it.

Types

type Checker

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

Checker performs the check. It is safe to reuse.

func New

func New(opts Options) *Checker

New builds a Checker.

func (*Checker) Check

func (c *Checker) Check(ctx context.Context) (Result, error)

Check answers from the cache when the cached answer is still fresh, and otherwise asks GitHub.

func (*Checker) CheckNow

func (c *Checker) CheckNow(ctx context.Context) (Result, error)

CheckNow always asks GitHub, ignoring the cache, and stores the answer.

func (*Checker) Unversioned

func (c *Checker) Unversioned() bool

Unversioned reports whether the running binary has a version worth comparing.

type Options

type Options struct {
	// Current is the running binary's version, as the CLI reports it ("0.4.0",
	// "v0.4.0", "v0.4.0-rc.1" or "dev").
	Current string
	// APIBase overrides the GitHub API root. Tests only.
	APIBase string
	// RepoPath overrides the releases endpoint. Tests only.
	RepoPath string
	// HTTPClient defaults to a client with the check's own timeout.
	HTTPClient *http.Client
	// CachePath is where the last answer is stored. Empty disables caching, so
	// every check is a request.
	CachePath string
	// Interval is how long a cached answer is trusted.
	Interval time.Duration
	// Now is the injected clock; it decides whether a cached answer is stale.
	Now func() time.Time
	// UserAgent is sent with the request.
	UserAgent string
}

Options configures a Checker. Current is required; everything else has a default.

type Result

type Result struct {
	// Current is the version being compared, as the binary reports it.
	Current string
	// Latest is the newest published release's tag, when one was found.
	Latest string
	// URL is the release's page on GitHub.
	URL string
	// PublishedAt is when that release was published, when GitHub said.
	PublishedAt time.Time
	// Outdated reports that Latest is newer than Current.
	Outdated bool
	// CheckedAt is when the answer was fetched, or when a cached one was
	// originally fetched.
	CheckedAt time.Time
	// FromCache reports that no request was made.
	FromCache bool
	// Unversioned reports a build that has no version to compare (a plain
	// `go build`); Latest is still reported, but Outdated stays false.
	Unversioned bool
}

Result is what a check found.

Jump to

Keyboard shortcuts

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