upgrade

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 29 Imported by: 0 modules, 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 upgrade downloads a ytrack release, verifies it and replaces the running binary with it.

Trust chain: the release's checksums file must carry a Sigstore keyless signature by this repository's release workflow (ReleaseIdentity); the archive must match its SHA-256 in that file. Only then is the binary extracted and swapped in. Any failed check refuses the upgrade and leaves the installed binary untouched.

Index

Constants

View Source
const LockFile = "upgrade.lock"

LockFile is the file in the state directory that an upgrade holds.

View Source
const LogFile = "auto-upgrade.log"

LogFile is the file in the state directory where the background upgrade writes its output.

View Source
const OldSuffix = ".old"

OldSuffix names the previous binary that a Windows upgrade moves aside.

Variables

View Source
var ErrLocked = errors.New("another ytrack upgrade is running")

ErrLocked is returned when another upgrade holds the lock.

View Source
var ErrRefused = errors.New("refusing to upgrade")

ErrRefused wraps every verification failure.

View Source
var Executable = os.Executable

Executable returns the running binary's path. A var so tests can name another binary.

View Source
var ReleaseIdentity = Identity{
	Issuer: "https://token.actions.githubusercontent.com",
	SubjectRegexp: `^https://github\.com/BrainerVirus/youtrack-cli/\.github/workflows/release\.yml@refs/` +
		`tags/v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?$`,
}

ReleaseIdentity is the release workflow of this repository on GitHub Actions, run for a release tag: a tag push signs with refs/tags/vX.Y.Z, and a manual rerun must be dispatched from that tag (never from a branch), so it signs with the same ref.

Spawn starts the background upgrade. A var so tests can watch it instead of starting a process.

Functions

func AcquireLock added in v0.6.0

func AcquireLock(path string) (release func(), err error)

AcquireLock takes the lock at path, replacing one older than lockStale. It returns ErrLocked when another upgrade holds it.

func ArchiveName

func ArchiveName(version, goos, goarch string) string

ArchiveName returns the release archive for version (no "v") on goos/goarch, as .goreleaser.yaml names it.

func BundleName

func BundleName(version string) string

BundleName returns the Sigstore bundle that signs the checksums file.

func CheckSHA256

func CheckSHA256(data []byte, want string) error

CheckSHA256 reports an error unless data hashes to the hex digest want.

func ChecksumsName

func ChecksumsName(version string) string

ChecksumsName returns the checksums file of a release.

func DirWritable added in v0.6.0

func DirWritable(dir string) bool

DirWritable reports whether a file can be created in dir, as ReplaceExecutable needs.

func ExpectedSHA256

func ExpectedSHA256(checksums []byte, name string) (string, error)

ExpectedSHA256 returns the hex digest listed for name in a checksums file ("<hex> <name>" lines, as sha256sum writes them).

func ExtractBinary

func ExtractBinary(archive []byte, name string) ([]byte, error)

ExtractBinary returns the ytrack executable from a release archive (tar.gz, or zip for Windows).

func LockHeld added in v0.6.0

func LockHeld(path string) bool

LockHeld reports whether an upgrade holds the lock at path.

func PublicGoodTrustedRoot

func PublicGoodTrustedRoot() (root.TrustedMaterial, error)

PublicGoodTrustedRoot returns Sigstore's public-good trusted root (Fulcio CAs, Rekor v1 and v2 logs, CT logs, timestamp authorities), fetched and verified through Sigstore's TUF repository, starting from the TUF root that sigstore-go embeds. The TUF metadata is cached under ytrack's user cache directory, so key rotations reach ytrack without a new release.

func RemoveOld

func RemoveOld(exe string)

RemoveOld deletes the binary a previous Windows upgrade moved aside.

func ReplaceExecutable

func ReplaceExecutable(exe string, data []byte, check func(candidate string) error) error

ReplaceExecutable atomically replaces the file at exe with data, keeping its permissions. The new file is written next to exe and renamed over it, so exe is either the old or the new binary, never a partial one. check, when not nil, runs on the written candidate before the rename; an error from it leaves exe untouched. Windows cannot overwrite a running executable but can rename it, so there the old binary is first moved to exe+OldSuffix (removed by the next upgrade).

func RunBinary added in v0.6.0

func RunBinary(ctx context.Context, exe string, args ...string) ([]byte, error)

RunBinary is the real Runner. The binary runs with the release check and the background upgrade turned off, so it never starts one of its own.

func SmokeTest added in v0.6.0

func SmokeTest(ctx context.Context, run Runner, candidate, version string) error

SmokeTest runs the candidate binary's `version` and refuses it unless it exits 0 and names version.

func StartDetached added in v0.6.0

func StartDetached(exe string, args []string, logPath string) error

StartDetached starts exe with args in its own session (its own process group without a console on Windows), with no standard input and its output in logPath, and returns without waiting for it: the caller can exit at once, and a pipe the caller's caller reads never stays open for the child.

func SyncSkills added in v0.6.0

func SyncSkills(ctx context.Context, run Runner, exe string) (string, error)

SyncSkills runs `ytrack skill sync` of the binary at exe, which refreshes the agent skill copies it installed, and returns its output. A binary without that command is not an error.

func VerifyBundle

func VerifyBundle(bundleJSON, artifact []byte, t Trust) error

VerifyBundle checks with sigstore-go that bundleJSON (a Sigstore bundle, as `cosign sign-blob --bundle` writes it) is a keyless signature of artifact by t.Identity: the certificate chains to a trusted Fulcio CA at a time attested by a transparency log entry (Rekor v1 or v2) or a signed timestamp, carries a valid SCT, names the identity, and its key signed the artifact's SHA-256. Any failed check is an error.

Types

type Downloader

type Downloader struct {
	HTTP      *http.Client
	Trust     Trust
	GOOS      string
	GOARCH    string
	UserAgent string
	// APIURL is the GitHub REST API root used for the fallback;
	// update.DefaultAPIURL when empty.
	APIURL string
	// Sleep waits between retries; nil waits on a timer, honouring ctx.
	Sleep func(ctx context.Context, d time.Duration) error
	// Notice, when set, is told each time a file came through the API
	// fallback.
	Notice func(msg string)
	// contains filtered or unexported fields
}

Downloader fetches and verifies release binaries.

Each file is fetched from its release download URL; a transient failure (transport error, HTTP 5xx or 429) is retried with backoff. If that URL still fails, or answers another HTTP error, the file is fetched once more through the GitHub REST API (the asset's API URL with Accept: application/octet-stream), with the same retries. GitHub's download CDN can serve an edge-cached error for one asset while the API serves it fine. Both paths keep the same guards (https only, no redirect off https, size limit, User-Agent), and the signature and checksum checks run on the bytes either way.

func (*Downloader) Binary

func (d *Downloader) Binary(ctx context.Context, rel *update.Release) ([]byte, error)

Binary downloads the release archive for d.GOOS/d.GOARCH and returns the ytrack executable inside it, after checking the signature of the checksums file and the archive's checksum.

type Identity

type Identity struct {
	Issuer        string // OIDC issuer, matched exactly
	SubjectRegexp string // certificate SAN (for GitHub Actions, the workflow URI)
}

Identity is the signer a bundle's Fulcio certificate must name.

type Runner added in v0.6.0

type Runner func(ctx context.Context, exe string, args ...string) ([]byte, error)

Runner runs the ytrack binary at exe with args and returns its combined output.

type Trust

type Trust struct {
	Material root.TrustedMaterial
	Identity Identity
	// NoSCT skips the certificate transparency (SCT) check. Only for test
	// Sigstores, whose certificates carry no SCT; never set in production.
	NoSCT bool
}

Trust is what a release signature must verify against.

Directories

Path Synopsis
Package upgradetest provides Sigstore bundles signed by sigstore-go's virtual Sigstore and a fake GitHub release server for tests.
Package upgradetest provides Sigstore bundles signed by sigstore-go's virtual Sigstore and a fake GitHub release server for tests.

Jump to

Keyboard shortcuts

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