Documentation
¶
Overview ¶
Package version checks GitHub for latest releases, compares semantic versions, and manages update workflows for the sidecar and td binaries.
Index ¶
- Variables
- func CheckProductAsync(d Descriptor, currentVersion string, force bool) tea.Cmd
- func CommandAvailable(env *Environment, d Descriptor) bool
- func FailureDetail(r Result, maxOutputLines int) []string
- func GoCommandEnv(base []string) []string
- func HomebrewAvailable(env *Environment) bool
- func InstallCommand(d Descriptor) string
- func InstallCommands(t Target) [][]string
- func InstalledVersion(ctx context.Context, env *Environment, d Descriptor) string
- func IsCacheValid(entry *CacheEntry, currentVersion string) bool
- func NormalizeVersion(s string) string
- func RefreshPackageMetadata(ctx context.Context, env *Environment, plan []Target)
- func RestartRequired(results []Result) bool
- func SameVersion(a, b string) bool
- func SaveCacheFile(name string, entry *CacheEntry) error
- func Summarize(results []Result) string
- type CacheEntry
- type CheckResult
- type Descriptor
- type Environment
- type ExecRunner
- type InstallMethod
- type InstallOutcome
- type Installation
- type ProductID
- type ProductStatusMsg
- type Release
- type Result
- type ResultStatus
- type Runner
- type SuiteBinary
- type Target
Constants ¶
This section is empty.
Variables ¶
var ErrNoFormula = errors.New("no Homebrew formula for this product")
ErrNoFormula reports a product with no Homebrew formula to install from.
var ErrNoHomebrew = errors.New("homebrew is not installed")
ErrNoHomebrew reports that Homebrew is not available on this machine.
Functions ¶
func CheckProductAsync ¶ added in v0.96.0
func CheckProductAsync(d Descriptor, currentVersion string, force bool) tea.Cmd
CheckProductAsync returns a Bubble Tea command that discovers one product's installed version, release status, and install provenance in the background.
currentVersion is the in-process version for Sidecar; pass "" for products whose version must be read from the installed executable. Callers only schedule this for products that are effectively enabled, so a disabled feature adds no startup process or network work.
func CommandAvailable ¶ added in v1.0.0
func CommandAvailable(env *Environment, d Descriptor) bool
CommandAvailable reports whether a product's primary executable is on PATH.
func FailureDetail ¶ added in v1.0.2
FailureDetail returns the diagnostic lines to show for a failed result: the error itself, followed by the tail of the failing command's combined output.
The output is the part that matters and it used to be discarded entirely, so a failed update reported only the command and "exit status 1" — enough to see that `go install` failed, never enough to see why. The tail is what carries the compiler or toolchain message; earlier lines are download progress.
State-free so the exact reported lines are testable without a UI.
func GoCommandEnv ¶ added in v1.0.1
GoCommandEnv returns the environment an automated `go install` runs with, derived from base (os.Environ() form). It is a pure function so the exact resulting environment is testable.
Two adjustments matter:
- GOWORK=off. Sidecar usually runs with its own repository as the working directory, and that repository has a go.work with local `replace` directives. A workspace must not influence `go install pkg@version`: it either fails outright or resolves the release against local, possibly unbuildable, checkouts.
- CGO_CFLAGS gains the warning suppressions above, appended to whatever the user already set rather than replacing it.
func HomebrewAvailable ¶ added in v1.0.0
func HomebrewAvailable(env *Environment) bool
HomebrewAvailable reports whether `brew` is on PATH.
func InstallCommand ¶ added in v1.0.0
func InstallCommand(d Descriptor) string
InstallCommand is the exact command InstallWithHomebrew would run, so the confirmation, the copyable instruction, and the execution are the same string.
func InstallCommands ¶ added in v0.96.0
InstallCommands returns the exact commands an automated update runs for a target, or nil when the target is not safely updatable.
func InstalledVersion ¶ added in v0.96.0
func InstalledVersion(ctx context.Context, env *Environment, d Descriptor) string
InstalledVersion reads a product's installed version by running its executable. It returns "" when the product is not installed, the command fails, or the output carries no release version (a development build).
func IsCacheValid ¶
func IsCacheValid(entry *CacheEntry, currentVersion string) bool
IsCacheValid checks if cache exists and is not expired. Also invalidates if user version changed (upgrade or downgrade).
func NormalizeVersion ¶ added in v0.96.0
NormalizeVersion extracts a comparable version from arbitrary `--version` output (e.g. "tasks version 1.5.0" or "v1.5.0"). It returns "" when the output carries no release version, which is how development builds and unparsable output are told apart from a real release.
func RefreshPackageMetadata ¶ added in v0.96.0
func RefreshPackageMetadata(ctx context.Context, env *Environment, plan []Target)
RefreshPackageMetadata refreshes Homebrew metadata once per confirmed batch so `brew upgrade` can see new releases. Best effort: a failure here is not a target failure.
func RestartRequired ¶ added in v0.96.0
RestartRequired reports whether any settled result changed Sidecar itself. Standalone td/Tasks updates do not require quitting Sidecar.
func SameVersion ¶ added in v0.96.0
SameVersion reports whether two version strings name the same release.
func SaveCacheFile ¶ added in v0.96.0
func SaveCacheFile(name string, entry *CacheEntry) error
SaveCacheFile writes a version check result to a named cache file.
Types ¶
type CacheEntry ¶
type CacheEntry struct {
LatestVersion string `json:"latestVersion"`
CurrentVersion string `json:"currentVersion"`
CheckedAt time.Time `json:"checkedAt"`
HasUpdate bool `json:"hasUpdate"`
}
CacheEntry stores cached version check result.
func LoadCacheFile ¶ added in v0.96.0
func LoadCacheFile(name string) (*CacheEntry, error)
LoadCacheFile reads a cached version check result for a named cache file.
type CheckResult ¶
type CheckResult struct {
CurrentVersion string
LatestVersion string
UpdateURL string
ReleaseNotes string
HasUpdate bool
Error error
}
CheckResult holds the result of a version check.
func Check ¶
func Check(currentVersion string) CheckResult
Check fetches the latest release from GitHub and compares versions.
func CheckRepo ¶
func CheckRepo(owner, repo, currentVersion string) CheckResult
CheckRepo fetches the latest release for a repo and compares versions.
type Descriptor ¶ added in v0.96.0
type Descriptor struct {
Product ProductID
DisplayName string
RepoOwner string
RepoName string
// Executable is the command used to read the installed version and to
// resolve install provenance.
Executable string
// SuiteBinaries lists every binary the release ships, with the exact
// arguments each one accepts for printing its version. A product is only
// verified as updated when all of them report the released version; for
// Tasks that is the distribution contract.
//
// The arguments are per binary because they genuinely differ: `tasks` is
// subcommand-dispatched and wants `tasks version`, while `tasks-tui` and
// `tasks-api` parse flags and reject positional arguments.
SuiteBinaries []SuiteBinary
// Formula is the fully qualified Homebrew formula name.
Formula string
// GoPackages are the packages an automated `go install` update must build.
// Empty means a Go install cannot be expressed safely and must be manual.
GoPackages []string
// GoLdflags stamps the version into main.Version (Sidecar's release does
// this; the other products embed their version at tag time).
GoLdflags bool
// CacheFile is the per-product release-check cache file name. Distinct per
// product so similarly numbered releases cannot collide.
CacheFile string
ReleasesURL string
}
Descriptor describes how to discover and update one product. Everything that differs between products lives here so the checking, planning, install, and verification code stays product-neutral.
func DescriptorFor ¶ added in v0.96.0
func DescriptorFor(id ProductID) (Descriptor, bool)
DescriptorFor returns the descriptor for a product id.
func SidecarDescriptor ¶ added in v0.96.0
func SidecarDescriptor() Descriptor
SidecarDescriptor describes Sidecar itself.
func TasksDescriptor ¶ added in v0.96.0
func TasksDescriptor() Descriptor
TasksDescriptor describes the standalone Tasks command suite.
func TdDescriptor ¶ added in v0.96.0
func TdDescriptor() Descriptor
TdDescriptor describes the td CLI.
func (Descriptor) InstallHint ¶ added in v0.96.0
func (d Descriptor) InstallHint() string
InstallHint is the supported way to install a product that is not installed at all. Sidecar never runs it: turning an update confirmation into a new product installation is a separate decision.
func (Descriptor) UnmanagedHint ¶ added in v0.96.0
func (d Descriptor) UnmanagedHint() string
UnmanagedHint is what to tell someone whose installed copy Sidecar does not manage — a downloaded binary, a packaged build, or an active development selector. Deliberately not `brew install`: that would create a second, shadowing installation rather than updating the one they actually run.
func (Descriptor) VersionArgs ¶ added in v0.96.0
func (d Descriptor) VersionArgs() []string
VersionArgs returns the arguments that make the product's primary executable print its version.
type Environment ¶ added in v0.96.0
type Environment struct {
Runner Runner
LookPath func(string) (string, error)
EvalSymlinks func(string) (string, error)
// Self resolves the running Sidecar binary.
Self func() (string, error)
}
Environment is the adapter edge for everything the updater needs from the host: process execution and executable resolution. Tests substitute it to assert exact commands without invoking real package managers.
func DefaultEnvironment ¶ added in v0.96.0
func DefaultEnvironment() *Environment
DefaultEnvironment returns the real host environment.
func (*Environment) ResolveExecutable ¶ added in v0.96.0
func (e *Environment) ResolveExecutable(d Descriptor) (string, error)
ResolveExecutable returns the resolved on-disk path of a product's primary executable, following symlinks.
type ExecRunner ¶ added in v0.96.0
type ExecRunner struct{}
ExecRunner is the real process runner.
type InstallMethod ¶
type InstallMethod string
InstallMethod represents how a product was installed.
const ( InstallMethodHomebrew InstallMethod = "homebrew" InstallMethodGo InstallMethod = "go" // InstallMethodBinary covers anything Sidecar does not manage: a // downloaded binary, a packaged build, or an active local development // selector. These are never overwritten automatically. InstallMethodBinary InstallMethod = "binary" )
func (InstallMethod) String ¶ added in v0.96.0
func (m InstallMethod) String() string
String returns the human-readable name of an install method.
type InstallOutcome ¶ added in v1.0.0
type InstallOutcome struct {
// Installed is true only when the product's command resolves afterwards.
Installed bool
// Command is exactly what was run, for a message the user can act on.
Command string
Output string
Err error
}
InstallOutcome is the settled result of one confirmed install attempt.
func InstallWithHomebrew ¶ added in v1.0.0
func InstallWithHomebrew(ctx context.Context, env *Environment, d Descriptor) InstallOutcome
InstallWithHomebrew installs a product's formula. It is never called without an explicit user confirmation, and it verifies the result rather than trusting the package manager's exit code.
type Installation ¶ added in v0.96.0
type Installation struct {
Method InstallMethod
ExecutablePath string
// Managed is true only when Sidecar can safely run an automated update for
// this exact executable. An unmanaged target is reported with a manual
// command instead of being overwritten.
Managed bool
ManualCommand string
// Detail explains an unmanaged target (e.g. a local development selector).
Detail string
}
Installation records how one product's resolved executable is managed.
func DetectInstallation ¶ added in v0.96.0
func DetectInstallation(ctx context.Context, env *Environment, d Descriptor, latestVersion string) Installation
DetectInstallation resolves how the product the user actually runs was installed. Provenance is per product: a Homebrew Sidecar may coexist with a Go-installed td or a local Tasks development selector.
type ProductID ¶ added in v0.96.0
type ProductID string
ProductID identifies an updatable product Sidecar knows how to check.
const ( // ProductSidecar is Sidecar itself. ProductSidecar ProductID = "sidecar" // ProductTd is the td issue tracker CLI. ProductTd ProductID = "td" // ProductTasks is the standalone Tasks command suite. Sidecar embeds the // Tasks TUI library at build time; this target is the separately installed // tasks/tasks-tui/tasks-api commands, which only their own package manager // can refresh. ProductTasks ProductID = "tasks" )
type ProductStatusMsg ¶ added in v0.96.0
ProductStatusMsg reports the discovered state of one product. It is the single product-neutral result of a release check; the app stores one per product instead of parallel per-product fields.
type Release ¶
type Release struct {
TagName string `json:"tag_name"`
Name string `json:"name"`
Body string `json:"body"`
PublishedAt time.Time `json:"published_at"`
HTMLURL string `json:"html_url"`
}
Release represents a GitHub release response.
type Result ¶ added in v0.96.0
type Result struct {
Target Target
Status ResultStatus
// Version is the version actually verified after a successful update.
Version string
Output string
Err error
}
Result is the immutable outcome of attempting one target.
type ResultStatus ¶ added in v0.96.0
type ResultStatus string
ResultStatus is the settled outcome of one target in a confirmed batch.
const ( StatusUpdated ResultStatus = "updated" StatusManual ResultStatus = "manual" StatusFailed ResultStatus = "failed" )
type SuiteBinary ¶ added in v0.96.0
SuiteBinary is one executable a release ships.
type Target ¶ added in v0.96.0
type Target struct {
Product ProductID
DisplayName string
Installed bool
Enabled bool
CurrentVersion string
LatestVersion string
HasUpdate bool
// CheckFailed marks a release check that could not complete. It is
// "unknown", never "up to date".
CheckFailed bool
Install Installation
}
Target is one product Sidecar may offer to update.
func RetryTargets ¶ added in v0.96.0
RetryTargets returns the targets from a settled batch that are worth retrying: failures only. Successful upgrades are never re-run.
func SelectPlan ¶ added in v0.96.0
SelectPlan returns, in deterministic order, the targets a confirmed update will act on. It is a state-free function over discovered products: only enabled, installed products with a real available update take part.