update

package
v0.12.4 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package update checks GitHub for newer clawker releases.

CheckForUpdate reads the last-checked timestamp from the CLI state facade (internal/state) for freshness gating and persists the check there on every successful fetch (RecordUpdateCheck — a field merge that never touches the changelog cursor, so it cannot clobber a concurrent cursor write). A non-nil *ReleaseInfo result means a strictly newer release exists; nil means up-to-date, TTL-fresh, or not newer. Env/CI opt-out suppression is the caller's responsibility — only the TTL freshness gate lives here.

Designed for background use — the caller launches CheckForUpdate in a goroutine with a cancellable context. Context cancellation cleanly aborts the HTTP request when the CLI command finishes before the check completes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ReleaseInfo added in v0.12.4

type ReleaseInfo struct {
	CurrentVersion string
	LatestVersion  string
	ReleaseURL     string
}

ReleaseInfo describes a strictly newer release than the running version. A non-nil *ReleaseInfo MEANS "a newer release exists" — CheckForUpdate only returns one when LatestVersion is a newer semver than CurrentVersion, so the caller never has to re-check a flag.

func CheckForUpdate

func CheckForUpdate(ctx context.Context, client *http.Client, st state.StateStore, currentVersion, repo string) (*ReleaseInfo, error)

CheckForUpdate checks the GitHub API for the latest release of the given repo, persists the check to CLI state, and reports a strictly newer release.

Return contract:

  • (nil, nil) — up-to-date, TTL-fresh, or the latest release is not newer than currentVersion. A non-nil result MEANS a newer release exists.
  • (*ReleaseInfo, nil) — a strictly newer release is available.
  • (nil, error) — the fetch failed (API/network/decode).

Persistence is keyed on FETCH SUCCESS, not on whether a newer release was found: on every successful fetch (newer or not) it records checked_at + latest_version via st.RecordUpdateCheck BEFORE the newer/not-newer decision. This is what lets the TTL gate throttle — if persistence only happened on a newer release, checked_at would never advance on the common not-newer path and the GitHub API would be hit on every run. A nil st is a programming error (the caller wires state via the factory) and returns an error before any fetch.

client supplies the transport and timeout (the caller's Factory HttpClient in production; an internal/httpmock stub in tests).

Opt-out suppression (e.g. an env-var kill switch or CI detection) is the CALLER's responsibility — shouldCheckForUpdate only applies the TTL freshness gate. Defense-in-depth note: a future second caller that bypasses the cmd.go opt-out gate would still reach the GitHub API here; the opt-out is not enforced inside this package.

The context controls the HTTP request lifetime — cancel it to abort cleanly. repo should be "owner/name", e.g. "schmitthub/clawker".

Jump to

Keyboard shortcuts

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