Documentation
¶
Overview ¶
Package release manages GitHub release interactions and background update notifications for the Harness CLI.
The main process calls MaybeSpawn to potentially launch a detached subprocess, then calls NagIfDue to print a notice from the cache. The subprocess is launched as "harness --background-update-check" and calls RunBackgroundCheck to do the fetch.
Index ¶
Constants ¶
const (
// Repo is the GitHub repo for Harness CLI releases.
Repo = "harness/cli"
)
Variables ¶
var ErrReleaseNotFound = errors.New("release not found")
ErrReleaseNotFound is returned by FetchReleaseByTag when the GitHub API responds 404 — the tag exists in git but has no release, or does not exist.
Functions ¶
func FetchLatestVersion ¶
FetchLatestVersion calls the GitHub releases API and returns the latest version tag (e.g. "v1.2.3").
func MaybeSpawn ¶
func MaybeSpawn()
MaybeSpawn checks gating conditions and, when appropriate, writes last_spawn and launches a detached "harness --background-update-check" subprocess. It is a no-op (never errors) — update checking must never break normal commands.
func NagIfDue ¶
func NagIfDue(currentVersion string)
NagIfDue prints an update notice to stderr if a newer version is known and the nag interval has elapsed. It reads from the cache only — no network call.
func RunBackgroundCheck ¶
func RunBackgroundCheck()
RunBackgroundCheck is the subprocess entry point. It fetches the latest version, updates the cache, and always exits 0.
Types ¶
type Asset ¶
type Asset struct {
Name string `json:"name"`
BrowserDownloadURL string `json:"browser_download_url"`
URL string `json:"url"`
}
Asset is a single downloadable file attached to a GitHub release.
BrowserDownloadURL works unauthenticated, but only for a published (non-draft) release on a public repo. URL is the GitHub API asset endpoint, which — with an Authorization header and Accept: application/octet-stream — also serves drafts and private-repo assets; it's what a --github-token download must use instead.
type Release ¶
type Release struct {
TagName string `json:"tag_name"`
Draft bool `json:"draft"`
Prerelease bool `json:"prerelease"`
Assets []Asset `json:"assets"`
}
Release is the subset of the GitHub release API response the CLI resolves installs against: the tag it was published under and its downloadable assets.
func ResolveRelease ¶
ResolveRelease finds the release in repo matching prefix and version, and returns it with its asset list attached.
version, when non-empty, must already be a normalized "vX.Y.Z" string — the caller validates user input before this is reached, since that's a CLI/UX concern, not a GitHub-API-mechanics one. version == "" resolves to the latest release for prefix.
prefix == "" means the plain "vX.Y.Z" tag convention core itself releases under: latest resolves via GitHub's own "latest" marker, since only core releases are ever marked latest. prefix != "" means the "{prefix}/vX.Y.Z" convention every module releases under: GitHub's "latest" marker doesn't apply, so latest is resolved by listing releases and picking the highest-semver tag matching the prefix.
token, when non-empty, is sent as a bearer token on every GitHub API call — this is how a caller can see draft releases or releases in a private repo, neither of which an unauthenticated request can see.
allowDrafts includes draft releases when resolving "latest" for a prefixed (module/plugin) release — only meaningful with a token, since an unauthenticated request never sees a draft's assets to begin with. An explicit --version tag lookup always returns a draft when it matches, token or not; allowDrafts only affects the "list and pick highest semver" path below, where a draft would otherwise be filtered out alongside prereleases.