Documentation
¶
Overview ¶
Package update notifies, at most once a day, of a newer or deprecated release, and replaces a self-managed binary with a release from GitHub Releases on request.
Index ¶
- Constants
- Variables
- func Enabled() bool
- func Newer(a, b string) bool
- func Notice(current string, r Result, exe string) string
- func ReleaseNotesURL(version string) string
- func RemoveOld(exe string)
- func Replace(exe, staged string) error
- func ValidVersion(v string) bool
- type Channel
- type Checker
- type Result
- type Updater
Constants ¶
const ( // SignerIdentity is the certificate identity of the release workflow, as in scripts/install.sh. SignerIdentity = `^https://github\.com/sepayvn/sepay-cli/\.github/workflows/release\.yml@refs/(heads/main|tags/v.*)$` // RequireSignatureEnv refuses an update without cosign, as it refuses an install in the scripts. RequireSignatureEnv = "SEPAY_REQUIRE_SIGNATURE" )
const ( // Package is the npm package; its latest dist-tag is the newest stable release. Package = "sepay-cli" // DisableEnv turns the check off. DisableEnv = "SEPAY_NO_UPDATE_NOTIFIER" )
Variables ¶
var ErrChecksum = errors.New("checksum mismatch")
ErrChecksum means a download does not match its SHA-256 in checksums.txt.
Functions ¶
func Enabled ¶
func Enabled() bool
Enabled reports whether a check may run: interactive stderr, not CI, not disabled, a release build.
func Newer ¶ added in v0.1.8
Newer reports whether release a is newer than release b; false when either is not a version.
func Notice ¶
Notice returns the stderr text for r, or "". exe, with symlinks resolved, tells the install channel.
func ReleaseNotesURL ¶ added in v0.1.8
ReleaseNotesURL is the GitHub release page of version.
func RemoveOld ¶ added in v0.1.8
func RemoveOld(exe string)
RemoveOld deletes the executable a Windows update left beside exe. It fails silently while that file still runs.
func Replace ¶ added in v0.1.8
Replace puts the binary at staged in place of exe. A running Windows executable cannot be overwritten but can be renamed, so there exe moves to exe+".old" first; RemoveOld deletes it later.
func ValidVersion ¶ added in v0.1.8
ValidVersion reports whether v is a release version without the "v" of its tag, e.g. 0.2.0 or 0.2.0-rc.1.
Types ¶
type Channel ¶ added in v0.1.8
type Channel string
Channel is how sepay was installed.
const ( ChannelNPM Channel = "npm" ChannelHomebrew Channel = "homebrew" ChannelScoop Channel = "scoop" ChannelGo Channel = "go" // ChannelStandalone is a binary from install.sh, install.ps1 or an archive unpacked by hand. ChannelStandalone Channel = "standalone" )
The install channels. Only a standalone binary is replaced by "sepay update"; a package manager keeps its own record of what it installed, so it does the update.
func DetectChannel ¶ added in v0.1.8
DetectChannel reads the channel off exe, which must have its symlinks resolved: Homebrew and npm start sepay through one.
func (Channel) InstallCommand ¶ added in v0.1.8
InstallCommand is the command that installs exactly version through ch; "" when ch only installs its newest release.
func (Channel) UpdateCommand ¶ added in v0.1.8
UpdateCommand is the command that updates sepay through ch: to latest, or along the prerelease line of current when latest is "".
type Checker ¶
type Checker struct {
Client *http.Client
// BaseURL is the package document URL ending in "/".
BaseURL string
StatePath string
Now func() time.Time
}
Checker queries the registry and caches the answer.
type Result ¶
type Result struct {
Latest string
Deprecated string
// Recommended is the release the registry points to when the running final release is
// deprecated and nothing newer exists, i.e. the version to go back to.
Recommended string
}
Result is what one check found; empty means nothing to say.
type Updater ¶ added in v0.1.8
type Updater struct {
Client *http.Client
// BaseURL is the releases URL ending in "/".
BaseURL string
GOOS, GOARCH string
// Cosign verifies checksums.txt against its signature and certificate; nil when cosign is not
// installed, and then only the SHA-256 is checked.
Cosign func(ctx context.Context, checksums, sig, cert string) error
// Probe runs the unpacked binary and returns its version banner.
Probe func(ctx context.Context, path string) (string, error)
}
Updater fetches a release of sepay for one platform from GitHub Releases.
func NewUpdater ¶ added in v0.1.8
func NewUpdater() *Updater
NewUpdater returns an Updater for the running platform.
func (*Updater) Archive ¶ added in v0.1.8
Archive names the release archive of version for the Updater's platform.
func (*Updater) Fetch ¶ added in v0.1.8
Fetch downloads version for this platform into dir, checks it against checksums.txt (and its signature when Cosign is set), unpacks the binary and probes it. It returns the path of the unpacked binary, inside dir so that Replace is a rename; on error nothing is left in dir.