update

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package update checks for an available update on GitHub. It has baked in assumptions, but is mostly portable. Makes it easy for the notifiarr client application to send a notification when a new version is available.

Index

Constants

View Source
const LatestGH = "https://api.github.com/repos/%s/releases/latest"

LatestGH is where we find the latest release.

Variables

View Source
var (
	ErrInvalidURL = errors.New("invalid URL provided")
	ErrNoPath     = errors.New("a path to the file being replaced must be provided")
)

Errors. Don't trigger these.

View Source
var (
	ErrNoFile = errors.New("no downloadable file found in release")
)

Custom errors.

View Source
var OSsuffixMap = map[string]string{
	"darwin":    "Notifiarr.dmg",
	mnd.Windows: ".exe.zip",
	"freebsd":   ".txz",
	"linux":     "",
}

OSsuffixMap is the OS to file suffix map for downloads.

Functions

func Now

func Now(ctx context.Context, u *Command) (string, error)

Now downloads the new file to a temp name in the same folder as the running file. Moves the running file to a backup name in the same folder. Moves the new file to the same location that the running file was at. Triggers another invocation of the app that sleeps 5 seconds then restarts. The running app must exit after this returns! The restart command can trigger the above Restart() procedure. And that procedure relaunches the app; this allows "in-place" upgrades. This also makes sure the new file works before this app exits. This is not required though, and you can totally upgrade "a different app".

func NowWithContext

func NowWithContext(ctx context.Context, update *Command) (string, error)

NowWithContext is the same as Now() except you can pass in your own context.

func Restart

func Restart(cmd *Command) error

Restart is meant to be called from a special flag that reloads the app after an upgrade.

Types

type Command

type Command struct {
	URL        string   // file to download.
	Path       string   // file to be updated.
	Args       []string // optional, but non-nil will crash.
	mnd.Logger          // debug logs.
}

Command is the input data to perform an in-place update.

type GHasset

type GHasset struct {
	URL                string    `json:"url"`
	ID                 int64     `json:"id"`
	NodeID             string    `json:"node_id"`
	Name               string    `json:"name"`
	Label              string    `json:"label"`
	Uploader           GHuser    `json:"uploader"`
	ContentType        string    `json:"content_type"`
	State              string    `json:"state"`
	Size               int64     `json:"size"`
	DownloadCount      int       `json:"download_count"`
	CreatedAt          time.Time `json:"created_at"`
	UpdatedAt          time.Time `json:"updated_at"`
	BrowserDownloadURL string    `json:"browser_download_url"`
}

GHasset is part of GitHubReleasesLatest.

type GHuser

type GHuser struct {
	Login             string `json:"login"`
	ID                int64  `json:"id"`
	NodeID            string `json:"node_id"`
	AvatarURL         string `json:"avatar_url"`
	GravatarID        string `json:"gravatar_id"`
	URL               string `json:"url"`
	HTMLURL           string `json:"html_url"`
	FollowersURL      string `json:"followers_url"`
	FollowingURL      string `json:"following_url"`
	GistsURL          string `json:"gists_url"`
	StarredURL        string `json:"starred_url"`
	SubscriptionsURL  string `json:"subscriptions_url"`
	OrganizationsURL  string `json:"organizations_url"`
	ReposURL          string `json:"repos_url"`
	EventsURL         string `json:"events_url"`
	ReceivedEventsURL string `json:"received_events_url"`
	Type              string `json:"type"`
	SiteAdmin         bool   `json:"site_admin"`
}

GHuser is part of GitHubReleasesLatest.

type GitHubReleasesLatest

type GitHubReleasesLatest struct {
	URL             string    `json:"url"`
	AssetsURL       string    `json:"assets_url"`
	UploadURL       string    `json:"upload_url"`
	HTMLURL         string    `json:"html_url"`
	ID              int64     `json:"id"`
	Author          GHuser    `json:"author"`
	NodeID          string    `json:"node_id"`
	TagName         string    `json:"tag_name"`
	TargetCommitish string    `json:"target_commitish"`
	Name            string    `json:"name"`
	Draft           bool      `json:"draft"`
	Prerelease      bool      `json:"prerelease"`
	CreatedAt       time.Time `json:"created_at"`
	PublishedAt     time.Time `json:"published_at"`
	Assets          []GHasset `json:"assets"`
	TarballURL      string    `json:"tarball_url"`
	ZipballURL      string    `json:"zipball_url"`
	Body            string    `json:"body"`
}

GitHubReleasesLatest is the output from the releases/latest API on GitHub.

func GetRelease

func GetRelease(ctx context.Context, uri string) (*GitHubReleasesLatest, error)

GetRelease returns a GitHub release. See Check for an example on how to use it.

type Signal

type Signal struct {
	Text string
}

Signal provides a fake signal to close the app when an upgrade is requested.

func (*Signal) Signal

func (s *Signal) Signal()

Signal allows you to pass this into an exit signal channel. This does not do anything, it only satisfies an interface.

func (*Signal) String

func (s *Signal) String() string

String allows you to pass this into an exit signal channel.

type UnstableFile added in v0.7.3

type UnstableFile struct {
	Time time.Time `json:"time"`
	File string    `json:"file"`
	Ver  string    `json:"version"`
	Rev  int       `json:"revision"`
	Size int64     `json:"size"`
}

func GetUnstable added in v0.7.3

func GetUnstable(ctx context.Context, uri string) (*UnstableFile, error)

GetUnstable returns an unstable release. See CheckUnstable for an example on how to use it.

type Update

type Update struct {
	Outdate bool      // True if we're outdated, update available.
	Version string    // Version passed in externally.
	Current string    // Current release available on GH or US.
	CurrURL string    // URL of current release on GH or US.
	RelDate time.Time // Current version release date.
	RelSize int64     // Current release file size.
}

Update contains running Version, Current version and Download URL for Current version. Outdate is true if the running version is older than the current version.

func CheckGitHub added in v0.7.3

func CheckGitHub(ctx context.Context, userRepo string, version string) (*Update, error)

CheckGitHub checks if the app this library lives in has an updated version on GitHub.

func CheckUnstable added in v0.7.3

func CheckUnstable(ctx context.Context, app string, revision string) (*Update, error)

CheckUnstable checks if the provided app has an updated version on GitHub. Pass in revision only, no version.

func FillUpdate

func FillUpdate(release *GitHubReleasesLatest, version string) (*Update, error)

FillUpdate compares a current version with the latest GitHub release.

Jump to

Keyboard shortcuts

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