selfupdate

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChannelStable     = "stable"
	ChannelPrerelease = "prerelease"
)

Variables

This section is empty.

Functions

func CheckWritePermission

func CheckWritePermission(dir string) error

CheckWritePermission checks if the directory is writable by attempting to create a temporary file.

func DetectPackageManager

func DetectPackageManager(binaryPath string) (string, bool)

DetectPackageManager checks if the binary path is inside a known package-managed prefix. Returns the manager name and whether it was detected.

func DownloadArchive

func DownloadArchive(httpClient *http.Client, url, dir string, isTTY bool) (string, error)

DownloadArchive downloads a file from url to a temp file in dir. Returns the path to the downloaded file. If isTTY is true, displays a progress bar; otherwise uses line-based progress. Checks Content-Length header and caps streaming at maxArchiveSizeLimit.

func ExtractBinary

func ExtractBinary(archivePath, outDir, binaryName string) (string, error)

ExtractBinary extracts the named binary from a .tar.gz archive to a temp file in outDir. Validates that the extracted path contains no separators or traversal components.

func IsDevBuild

func IsDevBuild(version string) bool

IsDevBuild returns true if the version is not a valid semver string, or is a non-canonical short version like "0.0", or has a git describe suffix like "0.1.0-alpha.7-3-gabcdef".

func IsPrerelease

func IsPrerelease(version string) bool

IsPrerelease returns true if the version is a valid semver string with a prerelease suffix (e.g., "0.1.0-alpha.7").

func MergeChanges added in v0.4.0

func MergeChanges(metas []*VersionMetadata) map[string][]MergedEntry

MergeChanges concatenates the structured changes of multiple releases by category, tagging each entry with its source version. metas must be ordered newest-first so that the newest release's entries lead each category.

func OtherChannel added in v0.4.0

func OtherChannel(channel string) string

OtherChannel returns the opposite release channel.

func RenderChanges added in v0.4.0

func RenderChanges(changes map[string][]ChangelogEntry) string

RenderChanges renders a single version's structured changes to the same text the Python generator produces for the rendered "changelog" field. No version prefix is added.

func RenderMerged added in v0.4.0

func RenderMerged(merged map[string][]MergedEntry) string

RenderMerged renders merged changes as a single block, prefixing every entry with its source version (e.g. "- v0.4.0: ...").

func ReplaceBinary

func ReplaceBinary(targetPath, newPath string) error

ReplaceBinary atomically replaces the binary at targetPath with the new binary at newPath using os.Rename (atomic on POSIX). Preserves the original file permissions.

func ResolveBinaryPath

func ResolveBinaryPath() (string, string, error)

ResolveBinaryPath returns the absolute path to the currently running binary, resolving any symlinks. It also returns the original (unresolved) path, which is useful for package manager detection where symlinks (e.g. /snap/bin/foo -> /usr/bin/snap) would cause incorrect prefix matching.

func ShouldUpdate

func ShouldUpdate(current, latest string, crossChannel bool) bool

ShouldUpdate returns true if the binary should be updated from current to latest. If crossChannel is true, the update is always offered (the user explicitly chose to switch channels). Dev builds always get offered updates.

func VerifyCosignBundle

func VerifyCosignBundle(httpClient *http.Client, archivePath, bundleURL string) error

VerifyCosignBundle verifies the cosign bundle for the archive at archivePath. Downloads the bundle from bundleURL and verifies against Sigstore's public good instance.

Verification checks: - Certificate issuer: https://token.actions.githubusercontent.com - Certificate SAN (prefix): https://github.com/bernd/vibepit/.github/workflows/build.yml

func VerifySHA256

func VerifySHA256(path, expected string) error

VerifySHA256 checks that the SHA256 hash of the file at path matches the expected hex-encoded checksum.

Types

type Asset

type Asset struct {
	OS              string `json:"os"`
	Arch            string `json:"arch"`
	URL             string `json:"url"`
	SHA256          string `json:"sha256"`
	CosignBundleURL string `json:"cosign_bundle_url"`
}

Asset represents a platform-specific release asset.

type ChangelogEntry added in v0.4.0

type ChangelogEntry struct {
	Msg   string `json:"msg"`
	PR    string `json:"pr,omitempty"`
	Issue string `json:"issue,omitempty"`
}

ChangelogEntry is a single structured changelog entry parsed from a docs/changelogs/{version}.yml file.

type ChannelIndex

type ChannelIndex struct {
	Latest   string         `json:"latest"`
	Releases []ReleaseEntry `json:"releases"`
}

ChannelIndex represents a channel index file (e.g., stable.json).

func (*ChannelIndex) ReleasesBetween added in v0.4.0

func (idx *ChannelIndex) ReleasesBetween(current, target string) []ReleaseEntry

ReleasesBetween returns the releases newer than current and no newer than target (current < v <= target), sorted newest-first. The caller must ensure current is a valid release version; an invalid semver sorts below all releases and would match everything.

type Client

type Client struct {
	HTTPClient *http.Client
	BaseURL    string
}

Client fetches release metadata from vibepit.dev.

func NewClient

func NewClient() *Client

NewClient creates a new release metadata client.

func (*Client) FetchChannelIndex

func (c *Client) FetchChannelIndex(channel string) (*ChannelIndex, bool, error)

FetchChannelIndex fetches and parses a channel index file. Returns the index and a boolean indicating whether the file was found.

func (*Client) FetchVersionMetadata

func (c *Client) FetchVersionMetadata(version string) (*VersionMetadata, error)

FetchVersionMetadata fetches and parses a version metadata file.

func (*Client) ResolveChannel

func (c *Client) ResolveChannel(preferPre bool) (*ChannelIndex, string, error)

ResolveChannel determines which channel to use and fetches the index. Implements fallback logic: if stable is not found and --pre was not explicitly set, falls back to prerelease.

type MergedEntry added in v0.4.0

type MergedEntry struct {
	Entry   ChangelogEntry
	Version string
}

MergedEntry is a ChangelogEntry tagged with the release version it came from, used when merging changelogs across multiple releases.

type ReleaseEntry

type ReleaseEntry struct {
	Version   string `json:"version"`
	Timestamp string `json:"timestamp"`
}

ReleaseEntry is a single entry in the channel index releases array.

func CombineReleases added in v0.4.0

func CombineReleases(a, b *ChannelIndex) []ReleaseEntry

CombineReleases returns the union of the two indexes' release entries, deduplicated by version (first occurrence wins). Stable and prerelease releases live in separate indexes, so a cross-channel update needs both to see every release it skipped; a single index alone would omit the other channel's intervening releases. nil indexes are ignored.

type VersionMetadata

type VersionMetadata struct {
	Version   string                      `json:"version"`
	Timestamp string                      `json:"timestamp"`
	Changelog string                      `json:"changelog"`
	Changes   map[string][]ChangelogEntry `json:"changes,omitempty"`
	Assets    []Asset                     `json:"assets"`
}

VersionMetadata represents a per-version metadata file (e.g., 0.2.0.json).

func (*VersionMetadata) FindAsset

func (m *VersionMetadata) FindAsset(os, arch string) (*Asset, error)

FindAsset returns the asset matching the given OS and architecture.

Jump to

Keyboard shortcuts

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