selfupdate

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package selfupdate replaces the running binary with a release from GitHub, after it checks the keyless Sigstore signature of checksums.txt and the SHA-256 of the archive.

Index

Constants

View Source
const (
	// Repo is the GitHub repository of the releases.
	Repo = "AlfrescoLabs/openarch-cli"
	// Issuer is the OIDC issuer of the release signature: GitHub Actions.
	Issuer = "https://token.actions.githubusercontent.com"
	// ChecksumsFile and BundleFile are release assets.
	ChecksumsFile = "checksums.txt"
	BundleFile    = "checksums.txt.sigstore.json"
)

Variables

This section is empty.

Functions

func AssetName

func AssetName(tag, goos, goarch string) string

AssetName is the archive name of tag for one platform, as GoReleaser writes it.

func Download

func Download(ctx context.Context, env Env, plan Plan) ([]byte, error)

Download fetches the archive of plan, checks the signature and the checksum, and returns the openarch binary from the archive.

func Identity

func Identity(tag string) string

Identity is the certificate identity of a release signature: the release workflow of Repo, running for tag.

func Install

func Install(exe string, bin []byte, goos string) error

Install replaces exe with bin. The new file is written next to exe and then renamed, so exe is never half written. Windows cannot replace a running executable, so there the old one is first renamed to exe.old.

func IsRelease

func IsRelease(v string) bool

IsRelease reports whether v is a release version such as 0.2.0. Builds from source (dev, or git describe output such as v0.1.0-3-gabc1234) are not.

func LatestTag

func LatestTag(ctx context.Context, env Env) (string, error)

LatestTag returns the tag of the latest published release. It reads the redirect of /releases/latest, so it needs no GitHub API token.

func PackageManager

func PackageManager(exe string) string

PackageManager returns "brew" or "scoop" when exe was installed by one of them.

func RemoveOld

func RemoveOld(exe string)

RemoveOld deletes the exe.old file that an update on Windows leaves behind.

func VerifySigstore

func VerifySigstore(ctx context.Context, tag string, sums, bundleJSON []byte) error

VerifySigstore checks bundleJSON against the public Sigstore instance.

Types

type Env

type Env struct {
	HTTP *http.Client
	// BaseURL is https://github.com, or a test server.
	BaseURL    string
	Executable func() (string, error)
	GOOS       string
	GOARCH     string
	// Verify checks that bundleJSON is a valid signature of sums, made by the
	// release workflow for tag.
	Verify func(ctx context.Context, tag string, sums, bundleJSON []byte) error
}

Env gives the package access to the system. Tests replace its fields.

func SystemEnv

func SystemEnv() Env

SystemEnv uses GitHub, the running executable and the public Sigstore instance.

type Plan

type Plan struct {
	Current         string `json:"current"`
	Target          string `json:"target"`
	UpdateAvailable bool   `json:"updateAvailable"`
	Asset           string `json:"asset"`
	Executable      string `json:"executable"`
}

Plan describes an update.

func Prepare

func Prepare(ctx context.Context, env Env, current, tag string) (Plan, error)

Prepare compares the current version with tag. An empty tag means the latest release.

Jump to

Keyboard shortcuts

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