Documentation
¶
Overview ¶
Package update checks the GitHub releases for a newer build and installs it. It is used only by kvit-coder-ui: the headless agent never checks, and the model is never offered it as a tool.
Releases are built by GoReleaser on v* tags with predictable asset names (kvit-coder_<number>_<os>_<arch>.tar.gz, zip on Windows) plus a checksums.txt, so the check needs no API token: the /releases/latest redirect names the tag, and the archive is verified against checksums.txt before anything is replaced.
On unix the new binaries are renamed over the old ones atomically. A running Windows .exe cannot be overwritten, but it can be renamed, so there the current file is renamed aside to .old and the staged .new takes its name; the .old is removed on the next start. No launcher shim or versioned directories are needed on either platform.
Index ¶
- Constants
- func AssetName(tag, goos, goarch string) string
- func AssetURL(tag, goos, goarch string) string
- func BinaryNames(goos string) []string
- func ChecksumsURL(tag string) string
- func CleanupBackups(dirs ...string)
- func CleanupForPaths(paths ...string)
- func Compare(a, b string) int
- func Destinations(uiExe, agentPath string) (uiDest, coderDest string, err error)
- func DisabledByEnv() bool
- func ExtractBinaries(archivePath, destDir string) (coderPath, uiPath string, err error)
- func FetchRelease(ctx context.Context, tag, dir string) (string, error)
- func Install(coderSrc, uiSrc, coderDest, uiDest string) error
- func IsDevVersion(v string) bool
- func LatestTag(ctx context.Context) (string, error)
- func NewerThan(current, latest string) bool
- func NormalizeTag(tag string) string
- func NoteCheck(tag string)
- func PendingStaged(dirs ...string) []string
- func ReleaseURL(tag string) string
- func Resolve(p string) string
- func ShouldAutoCheck(now time.Time, current string, st *State, enabled bool, interval time.Duration) bool
- func StatePath() (string, error)
- func VerifyArchive(archivePath, sumsPath string) error
- type Pending
- type Result
- type State
Constants ¶
const DefaultInterval = 24 * time.Hour
DefaultInterval is the automatic check cadence when the config names none.
const NoCheckEnv = "KVIT_NO_UPDATE_CHECK"
NoCheckEnv disables the automatic check when set to 1/true/yes/on.
const Repo = "kvit-s/kvit-coder"
Repo is the GitHub repository releases are read from.
Variables ¶
This section is empty.
Functions ¶
func AssetName ¶
AssetName is the release file for a tag and platform, following GoReleaser's convention: the tag's number without the v.
func BinaryNames ¶
BinaryNames are the two files a release archive holds for an OS.
func ChecksumsURL ¶
ChecksumsURL serves the release's SHA256 list.
func CleanupBackups ¶
func CleanupBackups(dirs ...string)
CleanupBackups removes leftover .old files from a previous Windows swap. Best effort: errors are ignored.
func CleanupForPaths ¶
func CleanupForPaths(paths ...string)
CleanupForPaths removes leftover backups beside the UI and agent binaries.
func Compare ¶
Compare orders two versions: -1 when a is older, 0 when equal, +1 when a is newer. Tags carry a leading v; normalization strips it, compares three numeric parts, and orders a bare release above its prereleases. Anything unparsable compares as zeros, so "dev" is older than any release.
A git-describe suffix (v0.4.0-1-gSHA, what git describe prints for commits past a tag) is newer than the tag itself, not a prerelease: it names real commits on top. Two such suffixes order by commit count.
func Destinations ¶
Destinations returns where the two running binaries live: the UI behind uiExe (empty means this process) and the agent behind agentPath.
func DisabledByEnv ¶
func DisabledByEnv() bool
DisabledByEnv reports whether the environment turns the automatic check off.
func ExtractBinaries ¶
ExtractBinaries unpacks the two binaries from a release archive into destDir (flat, ignoring the docs the archive also carries) and returns their paths.
func FetchRelease ¶
FetchRelease downloads a release's archive and checksums into dir, verifies the archive, and returns its path.
func Install ¶
Install replaces both binaries with freshly extracted ones. On unix each replacement is a copy into the destination directory followed by an atomic rename, so a crash never leaves half a binary. On Windows the running files cannot be overwritten, but renaming them aside is allowed, so the current files move to .old and the staged .new files take their names; the .old files are removed on the next start. When the swap cannot happen the staged .new files are left and a *Pending explains the manual move.
func IsDevVersion ¶
IsDevVersion reports whether a stamped version is a development build, which is never auto-checked: "dev" from a plain go build, or a -dirty tree.
func LatestTag ¶
LatestTag asks GitHub which release is newest by following the /releases/latest redirect to /releases/tag/<tag> and reading the tag.
func NormalizeTag ¶
NormalizeTag accepts what a person types for :update ("0.5.0" or "v0.5.0") and returns the release tag form.
func NoteCheck ¶
func NoteCheck(tag string)
NoteCheck records that a check just ran. An empty tag keeps the previous one, so even a failed (offline) attempt throttles the next one to the next interval instead of retrying on every start.
func PendingStaged ¶
PendingStaged lists staged .new files waiting for a manual move.
func ReleaseURL ¶
ReleaseURL is the human page for a tag, where the notes live.
func Resolve ¶
Resolve returns the real file behind a path: bare names go through the PATH, symlinks (the ~/.local/bin farm scripts/install.sh builds) resolve to the checkout, and a missing file falls back to the absolute path.
func ShouldAutoCheck ¶
func ShouldAutoCheck(now time.Time, current string, st *State, enabled bool, interval time.Duration) bool
ShouldAutoCheck reports whether a background check is due. The first run (no record) checks; afterwards the interval gates it.
func VerifyArchive ¶
VerifyArchive checks the archive against its checksums.txt entry. The sums file lists every platform's archive, so only the downloaded file's line is compared.
Types ¶
type Pending ¶
type Pending struct {
Pairs [][2]string
}
Pending names updates that were staged (.new) but could not be swapped into place, as new-file/destination pairs.