selfupdate

package
v0.8.11 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 22 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package selfupdate finds, checks and installs Blitz's releases, for `blitz update` and for the desktop app updating itself: the latest release from GitHub, versions compared, a release's files downloaded and checked against its checksums.txt and that file's signature (the release workflow's, made keylessly with Sigstore, checked here without cosign), then put in place all at once or not at all.

Index

Constants

View Source
const (
	SignerIdentity = `^https://github.com/retail-cortex/blitz/\.github/workflows/release\.yml@refs/tags/v`
	SignerIssuer   = "https://token.actions.githubusercontent.com"
)

The release workflow signs keylessly: a certificate for it, from GitHub's OIDC issuer, on a release tag.

Variables

View Source
var ErrNotInstalled = errors.New("this isn't an installed desktop app (a development build?): it doesn't update itself")

ErrNotInstalled is a host that isn't in an installed desktop app (a development build, run from Bazel).

View Source
var ErrOldBundle = errors.New("the release's signature is in cosign's older format: check it with cosign")

ErrOldBundle is a signature in cosign's older bundle (releases before v0.6.6), which only cosign itself checks.

View Source
var TrustedRoot = func(ctx context.Context, cacheDir string) (root.TrustedMaterial, error) {
	return root.FetchTrustedRootWithOptions(trustOptions(ctx, cacheDir))
}

TrustedRoot is Sigstore's public trust root (its certificate authorities, transparency logs and timestamping), kept current through its TUF repository and cached in cacheDir; tests replace it.

View Source
var VerifyPackage = VerifySignature

VerifyPackage checks a desktop package's signature (VerifySignature); tests, here and in the packages that stage updates, replace it.

Functions

func Apply

func Apply(staged, root string) error

Apply puts the staged app in root's place: root moved aside (root.old), the staged one moved in, and root put back if that fails. Across disks, where a move can't be, the staged app is copied in. The old one is removed afterwards (a file still open keeps it on Windows until next time).

func CheckSum

func CheckSum(sums, file string) error

CheckSum checks file against its line in sums (checksums.txt).

func Compare

func Compare(a, b string) int

Compare compares two versions (v1.2.3, v1.2.3-rc.1): negative when a is older, positive when newer. A pre-release is older than its release.

func DesktopAsset

func DesktopAsset(goos, goarch, version string) (string, error)

DesktopAsset is the release's desktop package for goos and goarch at version (no v): the one the app updates itself from.

func ExtractPrograms

func ExtractPrograms(archive, dir string, programs ...string) (map[string]string, error)

ExtractPrograms takes the programs named (blitz, blitzd: without .exe) out of a release archive (.tar.gz, or .zip) into dir, wherever they are in it; it returns each one's file there.

func Fetch

func Fetch(ctx context.Context, url, to string) error

Fetch downloads url to the file to (512 MB at most).

func FileExists

func FileExists(p string) bool

FileExists reports whether p exists.

func PackageManager

func PackageManager(exe string) string

PackageManager names what installed exe, if a package manager did: it updates it, not Blitz.

func ProgramName

func ProgramName(p string) string

ProgramName is a program's file name here (.exe on Windows).

func ReplaceFiles

func ReplaceFiles(pairs [][2]string) (err error)

ReplaceFiles puts each source over its destination ({src, dst} pairs), all of them or none: every new file is staged beside its destination first, then renamed over it (a running program's file can be replaced so). The old files are kept until all are in place, and put back if one can't be.

func Stage

func Stage(ctx context.Context, src Source, tag, goos, goarch, dir, cacheDir string) (string, error)

Stage downloads tag's desktop package for goos/goarch into dir, checks it against its own signature (the release workflow's), and unpacks it there: it returns the new Blitz.app, or the app's folder, ready for Apply. cacheDir keeps Sigstore's trust root.

func VerifySignature

func VerifySignature(ctx context.Context, artifact io.Reader, bundleJSON []byte, cacheDir string) error

VerifySignature checks that bundleJSON (a Sigstore bundle, as the release workflow writes beside checksums.txt and each desktop package) is the release workflow's signature of artifact, read once as it's checked: its certificate is for the workflow on a release tag, from GitHub's issuer, logged in Sigstore's transparency log. cacheDir keeps Sigstore's trust root between checks ("" for the user's default).

Types

type Install

type Install struct {
	// Root is what an update replaces: Blitz.app on macOS, the app's
	// folder elsewhere.
	Root string
	// Program is what starts the app again afterwards.
	Program string
	// Manager names the package manager that installed it, which updates
	// it instead ("" when the app updates itself).
	Manager string
}

Install is the desktop app's installation, as its host finds it from its own program (…/resources/app/bin/blitz-tray, spec_electron_038).

func FindInstall

func FindInstall(hostExe, goos string) (Install, error)

FindInstall is the installation whose host program is hostExe, on goos.

type Source

type Source struct {
	API      string // …/repos/<owner>/<repo>
	Download string // …/releases/download
}

Source is where releases are: GitHub's API and its downloads.

func GitHub

func GitHub() Source

GitHub is Blitz's releases. BLITZ_UPDATE_URL (a folder served with api/releases/latest and download/<tag>/<file>) replaces it, to try an update against a local release.

func (Source) File

func (s Source) File(tag, name string) string

File is a release's file's address.

func (Source) Latest

func (s Source) Latest(ctx context.Context) (string, error)

Latest is the latest release's tag (GitHub's latest: no drafts or pre-releases).

Jump to

Keyboard shortcuts

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