updatecheck

package
v1.1.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package updatecheck reports whether a newer nvfleetint release is published on GitHub. It is CLI-only support code: the SDK never reaches out to GitHub.

Index

Constants

View Source
const (

	// DefaultTimeout bounds the release lookup. It is deliberately short: the
	// check is a courtesy, and `nvfleetint version` must stay fast offline.
	DefaultTimeout = 3 * time.Second
)

Variables

View Source
var ErrInstallerUnavailable = errors.New("no installer for this release")

ErrInstallerUnavailable reports that a release publishes no installer for the running platform, so it cannot be installed in place.

View Source
var ErrReleaseNotFound = errors.New("no such release")

ErrReleaseNotFound reports that a requested release is not published.

Functions

func DisplayVersion

func DisplayVersion(version string) string

DisplayVersion prints the running version the way releases are tagged, so the two versions in a message are directly comparable. The version injected at build time carries no "v" prefix, while release tags do.

func IsNewer

func IsNewer(candidate, current string) (bool, error)

IsNewer reports whether candidate is a later version than current. Both accept an optional leading "v": goreleaser injects the bare number while the git tag carries the prefix.

func IsReleaseVersion

func IsReleaseVersion(version string) bool

IsReleaseVersion reports whether version parses as a semantic version, i.e. whether it came from a release build's ldflags rather than the `dev` default.

func IsSame

func IsSame(a, b string) (bool, error)

IsSame reports whether two versions name the same release, ignoring an optional leading "v" and build metadata, neither of which affects precedence.

func ManualUpgradeCommand

func ManualUpgradeCommand() string

ManualUpgradeCommand returns the documented install command for this platform, for the paths where the CLI cannot upgrade itself.

func Notice

func Notice(result Result, current string) string

Notice renders the upgrade prompt shown when an update is available. It returns an empty string when there is nothing to say.

func ReleaseTag

func ReleaseTag(version string) (string, error)

ReleaseTag canonicalizes a user-supplied version into the tag a release is published under, rejecting anything that is not a version at all. Validating here means a typo fails immediately rather than as a 404 from GitHub, and a hostile value never reaches the network or the installer in the first place.

Types

type Checker

type Checker struct {
	// ReleasesURL is the repository's release index; releasesPage when empty.
	// The permalink for the newest release and a single release's page are both
	// derived from it.
	ReleasesURL string
	// HTTPClient issues the request; a DefaultTimeout client when nil.
	HTTPClient *http.Client
}

Checker resolves published releases from GitHub.

func (Checker) Latest

func (c Checker) Latest(ctx context.Context) (Release, error)

Latest returns the newest published release.

It issues a HEAD against the latest-release permalink and reads the redirect instead of following it: GitHub answers with the release's own page, whose URL both names the tag and is the page a user wants to open. Fetching that page would add nothing.

func (Checker) NewUpgradePlan

func (c Checker) NewUpgradePlan(current string, release Release) (UpgradePlan, error)

NewUpgradePlan describes how to replace the running binary with release. It hangs off Checker so the installer and the release lookup are addressed through one base URL.

func (Checker) Release

func (c Checker) Release(ctx context.Context, version string) (Release, error)

Release resolves a single published release by version. The version may be given with or without the leading "v" that release tags carry.

It requests the release's own page and treats a 404 as ErrReleaseNotFound, so a version that was never published is refused before anything is downloaded — the alternative is the installer failing halfway through on a 404 of its own, after the binary has already been moved aside.

type Release

type Release struct {
	// Version is the release tag as published, e.g. "v1.2.0".
	Version string `json:"latestVersion"`
	// URL points at the release page for those notes.
	URL string `json:"releaseUrl,omitempty"`
}

Release describes the newest published nvfleetint release.

type Result

type Result struct {
	Release
	// Available reports whether Version is newer than the running build.
	Available bool `json:"updateAvailable"`
}

Result reports the outcome of comparing the running build against Release.

func Check

func Check(ctx context.Context, checker Checker, current string) (Result, error)

Check compares current against the newest published release. A build whose version is not a release version — the `dev` default of a `go build` — has nothing meaningful to compare, so it is reported as up to date without a network call.

type UpgradePlan

type UpgradePlan struct {
	// CurrentVersion is the running build's version.
	CurrentVersion string
	// Release is the release to install.
	Release Release
	// ExecutablePath is the binary that will be replaced, with symlinks resolved.
	ExecutablePath string
	// InstallDir is where the installer is told to write, i.e. the directory
	// holding the running binary.
	InstallDir string
	// InstallerURL is the installer published with Release.
	InstallerURL string
}

UpgradePlan describes the upgrade that `nvfleetint upgrade` would perform.

func (UpgradePlan) CheckInstallerAvailable

func (p UpgradePlan) CheckInstallerAvailable(ctx context.Context) error

CheckInstallerAvailable reports whether the target release actually publishes the installer this platform needs.

It runs before the confirmation prompt, because not every published release can be installed in place: releases made before the installers were added to the release ship no install.sh or install.ps1 at all. Without this the user confirms an upgrade, and only then does the installer download 404 — a confirmation for something that was never going to work.

func (UpgradePlan) CheckWritable

func (p UpgradePlan) CheckWritable() error

CheckWritable reports whether the installer will be able to replace the binary. It runs before anything is downloaded, so a system-wide installation that needs elevated privileges fails immediately and says so, rather than after a download and a confirmation.

func (UpgradePlan) Run

func (p UpgradePlan) Run(ctx context.Context, progress io.Writer) error

Run downloads the release's installer and executes it, streaming the installer's own output to progress.

func (UpgradePlan) Summary

func (p UpgradePlan) Summary() string

Summary renders what the upgrade will do, for the confirmation prompt.

Jump to

Keyboard shortcuts

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