Documentation
¶
Overview ¶
Package selfupdate checks GitHub for newer agent-init releases and replaces the running binary in place. It is the engine behind `agent-init upgrade`.
The flow is deliberately conservative: a download is never installed without first verifying its SHA-256 against the release's checksums.txt, and the binary is swapped atomically (write-temp-then-rename) so a failure can't leave a half-written executable on disk.
Index ¶
Constants ¶
const DefaultRepo = "Lillevang/agent-init"
DefaultRepo is the GitHub "owner/name" releases are pulled from.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CheckResult ¶
CheckResult reports the outcome of a version check.
type GitHubSource ¶
type GitHubSource struct {
Repo string // "owner/name"
APIBaseURL string // default "https://api.github.com"
HTTPClient *http.Client
// Token is sent as a bearer credential to lift the unauthenticated rate
// limit. Optional; release assets are public.
Token string
}
GitHubSource implements Source against the GitHub releases REST API.
func NewGitHubSource ¶
func NewGitHubSource(repo string) *GitHubSource
NewGitHubSource returns a source for repo, reading an optional token from GITHUB_TOKEN or GH_TOKEN so authenticated users avoid the low anonymous rate limit.
type Source ¶
type Source interface {
Latest(ctx context.Context) (Release, error)
Download(ctx context.Context, url string) ([]byte, error)
}
Source fetches release metadata and downloads release assets. It is the seam the CLI fills with a GitHub client and tests fill with an in-memory fake.
type Updater ¶
type Updater struct {
Source Source
Out io.Writer
GOOS string
GOARCH string
ExePath func() (string, error)
}
Updater drives a check or an upgrade against a Source. GOOS/GOARCH and ExePath are fields rather than hard-coded calls so tests can target arbitrary platforms and a throwaway file instead of the real executable.
func NewUpdater ¶
NewUpdater returns an Updater wired to the current platform and the running executable's path.
type UpgradeOptions ¶
type UpgradeOptions struct {
Current string
// Force installs the latest release even when current is already newest (or
// unparseable, e.g. a dev build).
Force bool
// DryRun downloads and verifies the release but stops before replacing the
// binary.
DryRun bool
}
UpgradeOptions tunes an upgrade run.