updater

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package updater installs releases of Compa published on github.com/kayiik/compa.

Every release ships one archive per platform, compa_<version>_<os>_<arch> (.zip on Windows, .tar.gz elsewhere), holding BOTH programs -- compa, the launcher, and compa-kernel, the harness it supervises -- plus a SHA256SUMS file listing the SHA-256 of every asset. An update installs both programs from the same verified archive, so the launcher and the kernel beside it cannot drift onto different versions.

Index

Constants

View Source
const (
	// Owner and Repo name the only repository updates come from.
	Owner = "kayiik"
	Repo  = "compa"

	// LauncherName and KernelName are the two programs every archive holds
	// (with ".exe" on Windows).
	LauncherName = "compa"
	KernelName   = "compa-kernel"

	// ChecksumsName is the release asset listing the SHA-256 of every other
	// asset, in the format sha256sum writes.
	ChecksumsName = "SHA256SUMS"
)

Variables

This section is empty.

Functions

func ArchiveName

func ArchiveName(version, goos, goarch string) string

ArchiveName is the release asset holding both programs for goos/goarch.

func CompareVersions

func CompareVersions(a, b string) int

CompareVersions compares two versions such as "v1.2.3" or "1.2.3-rc.1" as semantic versions: -1, 0 or +1. A version that is not one, such as a development build's, compares as equal to anything, so it never blocks.

func NewUpdateCommand

func NewUpdateCommand(binaryName string) *cobra.Command

NewUpdateCommand returns the "update" command. It installs a release into the directory of the running program -- both compa-kernel and compa, from the same archive -- whichever of the two binaryName is.

func NormalizeTag

func NormalizeTag(version string) (string, error)

NormalizeTag turns "1.2.3" or "v1.2.3" into the release tag "v1.2.3". An empty string stays empty and means the latest release.

func TagFromURL

func TagFromURL(raw string) (string, error)

TagFromURL returns the release a github.com/kayiik/compa release URL names, or "" for the latest release. Updates never come from anywhere else, so any other URL is an error. Accepted forms:

https://github.com/kayiik/compa[/releases[/latest]]
https://github.com/kayiik/compa/releases/tag/<tag>
https://api.github.com/repos/kayiik/compa/releases/latest
https://api.github.com/repos/kayiik/compa/releases/tags/<tag>

Types

type Options

type Options struct {
	// Tag is the release to install, such as "v1.2.3" ("1.2.3" works too).
	// Empty installs the latest release.
	Tag string

	// Dir is the directory holding compa and compa-kernel. Empty means the
	// directory of the running executable, which is where an install keeps
	// both programs.
	Dir string

	// Log receives one line per step for a person to read. Nil discards them.
	Log io.Writer

	// APIBaseURL replaces https://api.github.com and HTTPClient replaces the
	// default client. Tests point them at a fake release; nothing else
	// should set them.
	APIBaseURL string
	HTTPClient *http.Client

	// SelfTest replaces the check that the new compa-kernel runs (with
	// "version", it must exit successfully). Tests whose programs are not
	// real ones set it; nothing else should.
	SelfTest func(ctx context.Context, path string) error

	// AllowDowngrade installs a release older than the running version,
	// which is refused otherwise.
	AllowDowngrade bool
}

Options selects the release to install and where to install it.

type Result

type Result struct {
	Tag     string // release tag, e.g. "v1.2.3"
	Version string // the tag without its leading "v"
	Dir     string // directory holding the updated programs
	Archive string // the archive both programs came from
}

Result describes an installed release.

func Update

func Update(ctx context.Context, opts Options) (*Result, error)

Update installs one release of Compa into opts.Dir. It downloads the archive for the running OS and architecture, verifies it against the release's SHA256SUMS, and replaces compa-kernel and then compa -- the launcher last, because it is normally the program running the update. Both programs are replaced or neither is. Running programs keep the old version until they restart.

Directories

Path Synopsis
Package updatertest serves fake GitHub releases of kayiik/compa, shaped like the ones the release workflow publishes, for tests of the updater and of the endpoints built on it.
Package updatertest serves fake GitHub releases of kayiik/compa, shaped like the ones the release workflow publishes, for tests of the updater and of the endpoints built on it.

Jump to

Keyboard shortcuts

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