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
- Variables
- func Apply(staged, root string) error
- func CheckSum(sums, file string) error
- func Compare(a, b string) int
- func DesktopAsset(goos, goarch, version string) (string, error)
- func ExtractPrograms(archive, dir string, programs ...string) (map[string]string, error)
- func Fetch(ctx context.Context, url, to string) error
- func FileExists(p string) bool
- func PackageManager(exe string) string
- func ProgramName(p string) string
- func ReplaceFiles(pairs [][2]string) (err error)
- func Stage(ctx context.Context, src Source, tag, goos, goarch, dir, cacheDir string) (string, error)
- func VerifySignature(ctx context.Context, artifact io.Reader, bundleJSON []byte, cacheDir string) error
- type Install
- type Source
Constants ¶
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 ¶
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).
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.
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.
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 ¶
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 Compare ¶
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 ¶
DesktopAsset is the release's desktop package for goos and goarch at version (no v): the one the app updates itself from.
func ExtractPrograms ¶
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 PackageManager ¶
PackageManager names what installed exe, if a package manager did: it updates it, not Blitz.
func ProgramName ¶
ProgramName is a program's file name here (.exe on Windows).
func ReplaceFiles ¶
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_038_electron).
func FindInstall ¶
FindInstall is the installation whose host program is hostExe, on goos.
type Source ¶
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.