upgrade

package
v2.11.2 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CacheTTL is how long the cache is valid.
	CacheTTL = 24 * time.Hour
)

Variables

This section is empty.

Functions

func CanSelfUpgrade

func CanSelfUpgrade() (bool, string)

CanSelfUpgrade returns true if dagu can perform a self-upgrade.

func CheckWritePermission

func CheckWritePermission(targetPath string) error

CheckWritePermission verifies we can write to the target directory.

func CompareVersions

func CompareVersions(current, target *semver.Version) int

CompareVersions compares two versions. Returns: -1 if current < target, 0 if equal, 1 if current > target

func Download

func Download(ctx context.Context, opts DownloadOptions) error

Download downloads a file with checksum verification. The entire GET + stream-to-file + checksum-verify is wrapped in a retry loop so that mid-stream failures (io.Copy errors) are also retried.

func ExtractVersionFromTag

func ExtractVersionFromTag(tag string) string

ExtractVersionFromTag extracts the version number from a tag like "v1.30.3".

func FormatBytes

func FormatBytes(bytes int64) string

FormatBytes formats byte count in human-readable format.

func FormatCheckResult

func FormatCheckResult(r *Result) string

FormatCheckResult formats the check result for display.

func FormatResult

func FormatResult(r *Result) string

FormatResult formats the upgrade result for display.

func GetExecutablePath

func GetExecutablePath() (string, error)

GetExecutablePath returns the path to the currently running binary.

func IsCacheValid

func IsCacheValid(cache *UpgradeCheckCache) bool

IsCacheValid checks if the cache is still valid (not expired).

func IsNewer

func IsNewer(current, target *semver.Version) bool

IsNewer returns true if target is newer than current.

func NormalizeVersionTag

func NormalizeVersionTag(version string) string

NormalizeVersionTag ensures a version string has a 'v' prefix.

func ParseVersion

func ParseVersion(s string) (*semver.Version, error)

ParseVersion parses a version string into a semver.Version.

func SupportedPlatformsMessage

func SupportedPlatformsMessage() string

SupportedPlatformsMessage returns a message listing all supported platforms.

func ValidateVersionTag

func ValidateVersionTag(tag string) error

ValidateVersionTag rejects tags that contain path-traversal sequences, directory separators, or control characters.

func VerifyBinary

func VerifyBinary(binaryPath, expectedVersion string) error

VerifyBinary runs the installed binary with "version" argument to verify it works.

func VerifyChecksum

func VerifyChecksum(filePath, expectedHash string) error

VerifyChecksum computes SHA256 and compares with expected hash.

Types

type Asset

type Asset struct {
	Name               string `json:"name"`
	BrowserDownloadURL string `json:"browser_download_url"`
	Size               int64  `json:"size"`
	ContentType        string `json:"content_type"`
}

Asset represents a GitHub release asset.

func FindAsset

func FindAsset(release *Release, platform Platform, version string) (*Asset, error)

FindAsset finds the appropriate asset for the given platform in a release.

type CacheStore

type CacheStore interface {
	Load() (*UpgradeCheckCache, error)
	Save(cache *UpgradeCheckCache) error
}

CacheStore provides persistence for upgrade check cache data.

type DownloadOptions

type DownloadOptions struct {
	URL          string
	Destination  string // Temp file path
	ExpectedHash string // SHA256 from checksums.txt
	OnProgress   func(downloaded, total int64)
}

DownloadOptions configures the download operation.

type GitHubClient

type GitHubClient struct {
	// contains filtered or unexported fields
}

GitHubClient is an HTTP client for the GitHub Releases API.

func NewGitHubClient

func NewGitHubClient() *GitHubClient

NewGitHubClient creates a new GitHub API client.

func (*GitHubClient) GetChecksums

func (c *GitHubClient) GetChecksums(ctx context.Context, release *Release) (map[string]string, error)

GetChecksums downloads and parses checksums.txt from a release. Returns a map of filename to SHA256 hash.

func (*GitHubClient) GetLatestRelease

func (c *GitHubClient) GetLatestRelease(ctx context.Context, includePreRelease bool) (*Release, error)

GetLatestRelease fetches the latest release from GitHub. If includePreRelease is true, it may return a pre-release version.

func (*GitHubClient) GetRelease

func (c *GitHubClient) GetRelease(ctx context.Context, tag string) (*Release, error)

GetRelease fetches a specific release by tag.

type InstallMethod

type InstallMethod int

InstallMethod represents how dagu was installed.

const (
	InstallMethodUnknown InstallMethod = iota
	InstallMethodBinary
	InstallMethodHomebrew
	InstallMethodSnap
	InstallMethodDocker
	InstallMethodGoInstall
)

func DetectInstallMethod

func DetectInstallMethod() InstallMethod

DetectInstallMethod checks how dagu was installed.

func (InstallMethod) String

func (m InstallMethod) String() string

String returns a human-readable name for the install method.

type InstallOptions

type InstallOptions struct {
	ArchivePath     string // Downloaded .tar.gz
	TargetPath      string // Path to current dagu binary
	CreateBackup    bool
	ExpectedVersion string // for verification after install
}

InstallOptions configures the installation operation.

type InstallResult

type InstallResult struct {
	BackupPath string
	Installed  bool
}

InstallResult contains information about the installation.

func Install

func Install(ctx context.Context, opts InstallOptions) (*InstallResult, error)

Install extracts the binary from the archive and replaces the current binary.

type Options

type Options struct {
	TargetVersion     string // Empty = latest
	CheckOnly         bool
	DryRun            bool
	CreateBackup      bool
	Force             bool
	IncludePreRelease bool
	OnProgress        func(downloaded, total int64)
}

Options configures the upgrade operation.

type Platform

type Platform struct {
	OS   string // runtime.GOOS: linux, darwin, freebsd, openbsd, windows
	Arch string // Mapped from runtime.GOARCH to release asset naming
}

Platform represents the current operating system and architecture.

func Detect

func Detect() Platform

Detect returns the current platform.

func (Platform) AssetName

func (p Platform) AssetName(version string) string

AssetName returns the expected filename for this platform and version. Format: dagu_<version_without_v>_<os>_<arch>.tar.gz

func (Platform) IsSupported

func (p Platform) IsSupported() bool

IsSupported checks if the current platform is supported for self-upgrade.

func (Platform) String

func (p Platform) String() string

String returns a human-readable representation of the platform.

type Release

type Release struct {
	TagName    string  `json:"tag_name"`
	Name       string  `json:"name"`
	Draft      bool    `json:"draft"`
	Prerelease bool    `json:"prerelease"`
	HTMLURL    string  `json:"html_url"`
	Assets     []Asset `json:"assets"`
}

Release represents a GitHub release.

type ReleaseInfo

type ReleaseInfo struct {
	Release       *Release
	Checksums     map[string]string
	Asset         *Asset
	TargetVersion *semver.Version
}

ReleaseInfo contains pre-fetched release data to avoid multiple API calls.

func FetchReleaseInfo

func FetchReleaseInfo(ctx context.Context, opts Options) (*ReleaseInfo, error)

FetchReleaseInfo fetches all release information in a single set of API calls. This allows checking and upgrading without making duplicate requests. Note: Callers are expected to check CanSelfUpgrade() before calling this.

type Result

type Result struct {
	CurrentVersion         string
	TargetVersion          string
	UpgradeNeeded          bool
	WasUpgraded            bool
	BackupPath             string
	DryRun                 bool
	AssetName              string
	AssetSize              int64
	DownloadURL            string
	ExecutablePath         string
	SpecificVersionRequest bool
}

Result contains the result of an upgrade operation.

func UpgradeWithReleaseInfo

func UpgradeWithReleaseInfo(ctx context.Context, opts Options, info *ReleaseInfo, store CacheStore) (*Result, error)

UpgradeWithReleaseInfo performs the upgrade using pre-fetched release information.

type UpgradeCheckCache

type UpgradeCheckCache struct {
	LastCheck       time.Time `json:"lastCheck"`
	LatestVersion   string    `json:"latestVersion"`
	CurrentVersion  string    `json:"currentVersion"`
	UpdateAvailable bool      `json:"updateAvailable"`
}

UpgradeCheckCache stores the result of an upgrade check.

func CheckAndUpdateCache

func CheckAndUpdateCache(ctx context.Context, store CacheStore, currentVersion string) (*UpgradeCheckCache, error)

CheckAndUpdateCache checks for updates if cache is stale and updates the cache. This function is designed to be called asynchronously.

func GetCachedUpdateInfo

func GetCachedUpdateInfo(store CacheStore) *UpgradeCheckCache

GetCachedUpdateInfo returns cached update information if available. Returns nil if no valid cache exists.

Jump to

Keyboard shortcuts

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