release

package
v0.25.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package release contains build metadata and best-effort release update checks.

Index

Constants

View Source
const (

	// CheckInterval bounds both persistent-cache freshness and UI refreshes.
	// It deliberately keeps GitHub traffic low for short-lived TUI processes.
	CheckInterval = 6 * time.Hour
)

Variables

This section is empty.

Functions

func Update

func Update(ctx context.Context, opts UpdateOptions) error

Update replaces the running binary with the latest stable release. It never restarts anything: the caller is told to restart Moa however it runs.

Types

type Checker

type Checker struct {
	Info      Info
	Client    *http.Client
	URL       string // exported for deterministic tests; empty uses GitHub.
	CachePath string
	Now       func() time.Time
	// contains filtered or unexported fields
}

Checker checks GitHub's public releases API. It has no telemetry: the only network request is to api.github.com, and can be disabled by callers.

func NewChecker

func NewChecker(info Info) *Checker

NewChecker creates a checker using ~/.config/moa/update.json (or MOA_CONFIG_DIR) as its shared persistent cache.

func (*Checker) Check

func (c *Checker) Check(ctx context.Context) (Result, error)

Check returns a release result. Errors are intentionally returned to the caller so an interactive frontend can ignore them silently.

func (*Checker) LatestVersion

func (c *Checker) LatestVersion(ctx context.Context) (string, error)

LatestVersion returns the newest stable release, always asking GitHub. It bypasses both the cache interval and MOA_NO_UPDATE_CHECK because it serves an explicit user request (`moa update`) rather than the passive check.

type Info

type Info struct {
	Version string
	Commit  string
	Date    string
}

Info is build metadata injected by the release build. Development builds use the default "dev" version and deliberately never make update requests.

func (Info) DisplayVersion

func (i Info) DisplayVersion() string

DisplayVersion returns the conventional v-prefixed version, or the raw build label when it is not a release version.

func (Info) IsRelease

func (i Info) IsRelease() bool

IsRelease reports whether this build has a valid semantic release version.

func (Info) String

func (i Info) String() string

String is a concise human-readable build identifier.

type Result

type Result struct {
	Current         string `json:"current"`
	Latest          string `json:"latest,omitempty"`
	UpdateAvailable bool   `json:"update_available"`
	// BuildID identifies the frontend bundle the server is serving. It is set
	// by the web layer, not by the release check: a self-built binary reports
	// the same Current ("dev") across deploys, so only the bundle's own id can
	// tell a running client that its code is stale.
	BuildID string `json:"build_id,omitempty"`
}

Result is safe to display even when the check was unavailable.

type Semver

type Semver struct {
	Major, Minor, Patch int
	Pre                 string
}

Semver is a parsed semantic version. Build metadata is ignored for ordering.

func ParseSemver

func ParseSemver(s string) (Semver, bool)

ParseSemver parses SemVer 2.0.0 versions with an optional v prefix.

func (Semver) Compare

func (v Semver) Compare(other Semver) int

Compare returns -1, 0, or 1 according to SemVer precedence.

type UpdateOptions

type UpdateOptions struct {
	Info      Info      // build metadata of the running binary
	CheckOnly bool      // report what would happen, download nothing
	Out       io.Writer // defaults to os.Stdout
	Checker   *Checker  // defaults to NewChecker(Info)
	Client    *http.Client
	BaseURL   string // release download root, defaults to downloadBaseURL
	ExecPath  string // binary to replace, defaults to the running executable
	GOOS      string // defaults to runtime.GOOS
	GOARCH    string // defaults to runtime.GOARCH
}

UpdateOptions configures a self-update run. The zero value targets the running binary and the public GitHub releases; the remaining fields are seams that keep the flow testable without network or install access.

Jump to

Keyboard shortcuts

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