Documentation
¶
Overview ¶
Package selfupdate checks GitHub for new releases of the CLI, installs them, and renders their release notes in the terminal.
Index ¶
- Constants
- func AfterUpgrade(ctx context.Context, w io.Writer, c *Client, ...) error
- func AssetName(goos, goarch string) string
- func ChecksOff(enabled bool) bool
- func CleanupOld()
- func Executable() (string, error)
- func HomeDir() string
- func IsNewer(current, candidate string) bool
- func IsRelease(v string) bool
- func RenderNotes(w io.Writer, releases []Release, maxLines int)
- func StatePath(home string) string
- type Asset
- type Client
- type Installer
- type Method
- type Notice
- type Notifier
- type Release
- type State
- type Version
Constants ¶
const ( // CheckInterval is how often GitHub is asked for a new release, and how // often the "new version available" message is shown. CheckInterval = 24 * time.Hour )
const ClientTimeout = 15 * time.Second
ClientTimeout is how long a request from the update check or `shipyard upgrade` waits for GitHub before giving up.
const DefaultAPIBaseURL = "https://api.github.com"
DefaultAPIBaseURL is the GitHub API origin releases are read from.
const DefaultNotesLines = 40
DefaultNotesLines caps how much of the release notes is printed after an upgrade, so a jump across several releases doesn't flood the terminal.
const NoCheckEnv = "SHIPYARD_NO_UPDATE_CHECK"
NoCheckEnv turns the update check off.
Variables ¶
This section is empty.
Functions ¶
func AfterUpgrade ¶
func AfterUpgrade(ctx context.Context, w io.Writer, c *Client, statePath, current, installed string, latest *Release, now time.Time) error
AfterUpgrade reports an upgrade from current to installed, where latest is the release that was asked for, prints the notes for the versions in between, and records them as seen in the state at statePath (skipped when statePath is empty). installed differs from latest when Homebrew's formula is behind the GitHub release.
func ChecksOff ¶
ChecksOff reports whether update checks are turned off: by NoCheckEnv, by running in CI, or by the update_check setting, which the caller passes as enabled. The terminal notice and the MCP server's notice both honor it.
func CleanupOld ¶
func CleanupOld()
CleanupOld removes what an earlier upgrade left next to the binary: the binary a Windows upgrade renamed out of the way, and downloads abandoned by Ctrl-C, which skips the deferred removal. Downloads under an hour old may belong to an upgrade running in another shell, so they're kept.
func Executable ¶
Executable returns the running binary's path with symlinks resolved, which is where a direct install has to write the new binary.
func HomeDir ¶
func HomeDir() string
HomeDir is the home directory whose state file to use: the invoking user's under sudo, which on Linux sets HOME to root's, so that notes recorded as seen by `sudo shipyard upgrade` aren't shown to the user again.
func IsNewer ¶
IsNewer reports whether candidate is a newer version than current. It is false when either fails to parse, so a dev build is never told to upgrade.
func IsRelease ¶
IsRelease reports whether v looks like a released version, as opposed to a local build ("undefined", "1.9.0-8-g94afae8") or a goreleaser snapshot ("1.9.1-SNAPSHOT-abc"). A local build parses as a pre-release older than the tag it's based on, so treating it as a release would "upgrade" it backwards.
func RenderNotes ¶
RenderNotes prints the releases' notes, newest first, as terminal text: headings in bold, bullets as "•", code in cyan, links as their text. Output stops after maxLines with a pointer to the full notes.
Types ¶
type Asset ¶
type Asset struct {
Name string `json:"name"`
BrowserDownloadURL string `json:"browser_download_url"`
}
Asset is a file attached to a release.
type Client ¶
Client reads releases from the GitHub API.
func (*Client) Between ¶
Between returns the releases newer than from and no newer than to, newest first: the notes a user moving from one version to the other has missed. Pre-releases are left out unless to is itself that pre-release.
type Installer ¶
type Installer struct {
HTTP *http.Client
Out io.Writer
Exe string
Method Method
// Current is the running version; a Homebrew upgrade that leaves it in
// place is reported as a failure, not a success.
Current string
// Brew runs a brew subcommand; tests replace it.
Brew func(ctx context.Context, out io.Writer, args ...string) error
// BrewVersion returns the version of shipyard Homebrew has installed.
BrewVersion func(ctx context.Context) (string, error)
}
Installer upgrades the running binary to a release.
func NewInstaller ¶
NewInstaller returns an installer for the running binary, at version current.
type Method ¶
type Method int
Method is how the running binary was installed, which decides how to upgrade it.
const ( // MethodDirect is a binary placed on disk by the install script, a // download from the releases page, or a previous self-upgrade. MethodDirect Method = iota // MethodHomebrew is a binary in Homebrew's Cellar. Overwriting it would // leave Homebrew recording the old version, so upgrades go through brew. MethodHomebrew )
func DetectMethod ¶
DetectMethod reports how the binary at the resolved path exe was installed.
type Notice ¶
type Notice struct {
Text string
// contains filtered or unexported fields
}
Notice is the text to print after the command. Call Shown once it has been printed, so the same notes and message aren't printed again.
type Notifier ¶
type Notifier struct {
Current string
StatePath string
Client *Client
Now func() time.Time
// LatestOnly checks for a newer release and leaves the upgrade notes
// alone, for a caller that never shows the notice (the MCP server): it
// would otherwise fetch notes nobody sees and use up the terminal's retry.
LatestOnly bool
}
Notifier works out what to tell the user after a command: the notes for a version they upgraded to since the last run, and whether a newer release is out. It never asks anything, so it can't block a script or an agent.
type Release ¶
type Release struct {
TagName string `json:"tag_name"`
Body string `json:"body"`
HTMLURL string `json:"html_url"`
Draft bool `json:"draft"`
Prerelease bool `json:"prerelease"`
Assets []Asset `json:"assets"`
}
Release is the subset of a GitHub release the updater uses.
type State ¶
type State struct {
// LastChecked is when GitHub last answered the latest-release check. Before
// each attempt it's set back so that, if the attempt fails or the command
// exits first, the next check is due in checkRetry.
LastChecked time.Time `json:"last_checked"`
// LatestVersion is the newest release that check found.
LatestVersion string `json:"latest_version,omitempty"`
// NotifiedAt is when the "new version available" message was last shown;
// it's shown at most once per CheckInterval.
NotifiedAt time.Time `json:"notified_at,omitzero"`
// LastSeenVersion is the version whose release notes the user has seen,
// or the version they first ran. A newer running version means it was
// upgraded since, by any method, and its notes are shown once.
LastSeenVersion string `json:"last_seen_version,omitempty"`
// NotesTried is when the notes for an upgrade made elsewhere were last
// fetched; a failed fetch is retried at most hourly.
NotesTried time.Time `json:"notes_tried,omitzero"`
}
State is what the updater remembers between runs. It lives in its own file, not config.yaml, because commands such as set_org rewrite config.yaml.
type Version ¶
Version is a parsed semantic version: MAJOR.MINOR.PATCH with an optional pre-release suffix such as "rc.1". Build metadata after "+" is ignored.
func ParseVersion ¶
ParseVersion accepts "1.9.0", "v1.9.0" and "1.10.0-rc.1".