updater

package
v1.40.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2022 License: Apache-2.0, Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrNoNewRelease = errors.New("no new release")
	ErrNoAsset      = errors.New("no asset found")
	ErrMissingFile  = errors.New("file missing in archive")

	AssetSeperators = []string{"_", "-"}
	AssetExtensions = []string{".tar.xz", ".tar.gz", ""}
)
View Source
var Disabled bool

Disabled globally disables the automatic updater. This is helpful for when using an external package manager, such as brew. This should usually be done with an ldflag.

Functions

func GetYesOrNoInput

func GetYesOrNoInput(ctx context.Context) (bool, error)

GetYesOrNoInput returns true if the user selected yes

func NeedsUpdate deprecated

func NeedsUpdate(ctx context.Context, log logrus.FieldLogger, repo, version string, disabled,
	debugLog, includePrereleases, forceCheck bool) bool

Deprecated: Use UseUpdater instead. NeedsUpdate is a deprecated method of UseUpdater.

Example
package main

import (
	"context"
	"os"

	"github.com/getoutreach/gobox/pkg/updater"
	"github.com/sirupsen/logrus"
)

func main() {
	if updater.NeedsUpdate(context.Background(), logrus.New(), "", "v1.0.0", false, false, false, false) {
		// Stop to use the newer version
		os.Exit(0)
	}
}
Output:

func UseUpdater added in v1.39.0

func UseUpdater(ctx context.Context, opts ...Option) (*updater, error)

UseUpdater creates an automatic updater.

Types

type Github

type Github struct {

	// Configuration Options
	Silent bool
	// contains filtered or unexported fields
}

func NewGithubUpdater deprecated

func NewGithubUpdater(ctx context.Context, token cfg.SecretData, org, repo string) *Github

Deprecated: Use NewGithubUpdaterWithClient with github.NewClient instead NewGithubUpdater creates a new updater powered by Github

func NewGithubUpdaterWithClient

func NewGithubUpdaterWithClient(ctx context.Context, client *github.Client, org, repo string) *Github

NewGithubUpdaterWithClient creates a new updater with the provided Github Client

func (*Github) Check

func (g *Github) Check(ctx context.Context) error

Check checks if the credentials / repo are valid.

func (*Github) DownloadRelease

func (g *Github) DownloadRelease(ctx context.Context, r *github.RepositoryRelease,
	assetName, execName string) (downloadedBinary string, cleanup func(), err error)

DownloadRelease attempts to download a binary from a release.

If the asset found is an archive, it'll be extracted and the value of `execName` will be used to pull a file out of the root of the archive. If `execName` is not provided it is inferred as the name of the currently running basename of the running executable. The downloaded file is returned as `downloadedBinary` with a cleanup function being returned to remove all leftover data.

The cleanup function should be called even when an error occurs

func (*Github) GetLatestVersion

func (g *Github) GetLatestVersion(ctx context.Context, currentVersion string, includePrereleases bool) (*github.RepositoryRelease, error)

GetLatestVersion finds the latest release, based on semver, of a Github Repository (supplied when client was created). This is determined by the following algorithm:

Finding new release:

Github releases are then streaming evaluated to find the currentVersion. All releases
that are not == to the current version end up being stored in memory as "candidates"
for being evaluated as a possible new version. If the current version is not found
then it is ignored.

Including pre-releases:

If the current version is a pre-release:
 - pre-releases are considered
If includePrereleases is true
 - pre-releases are considered

Selecting a new version:

Once the current releases has been found (or not found) then all versions found before
it are considered as candidates and checked to see if a newer release exists. Using the
aforementioned pre-release logic pre-releases are included based on that.

func (*Github) GetRelease

func (g *Github) GetRelease(ctx context.Context, version string) (*github.RepositoryRelease, error)

GetRelease finds a release with a given version (tag)

func (*Github) ReplaceRunning

func (g *Github) ReplaceRunning(ctx context.Context, newBinary string) error

ReplaceRunning replaces the running executable with the specified path. This path is renamed to the current executable.

The running process is replaced with a new invocation of the new binary.

func (*Github) SelectAsset

func (g *Github) SelectAsset(ctx context.Context, assets []*github.ReleaseAsset,
	name string) (string, *github.ReleaseAsset, error)

SelectAsset finds an asset on a Github Release. Returned is the URL to download it and the asset itself. This looks up the following file patterns: - name_GOOS_GOARCH - name_version_GOOS_GOARCH - name_GOOS_GOARCH.tar.gz - name_version_GOOS_GOARCH.tar.gz

type Option added in v1.39.0

type Option func(*updater)

Options configures an updater

func WithApp added in v1.39.0

func WithApp(app *cli.App) Option

WithApp sets the cli.App to setup commands on.

func WithCheckInterval added in v1.39.0

func WithCheckInterval(interval time.Duration) Option

WithCheckInterval sets the interval to check for updates. Defaults to 30 minutes.

func WithDisabled added in v1.39.0

func WithDisabled(disabled bool) Option

WithDisabled sets if we should disable the updater or not

func WithForceCheck added in v1.39.0

func WithForceCheck(forceCheck bool) Option

WithForceCheck sets whether or not to force the updater to check for updates otherwise updates are checked for only if the last check was more than the update check interval.

func WithLogger added in v1.39.0

func WithLogger(logger logrus.FieldLogger) Option

WithLogger sets the logger to use for logging. If not set a io.Discard logger is created.

func WithPrereleases added in v1.39.0

func WithPrereleases(prereleases bool) Option

WithPrereleases sets whether or not to include prereleases in the update check.

func WithRepo added in v1.39.0

func WithRepo(repo string) Option

WithRepo sets the repository to use for checking for updates. The expected format is: owner/repo

func WithVersion added in v1.39.0

func WithVersion(version string) Option

WithVersion sets the version to use as the current version when checking for updates. Defaults to app.Info().Version.

Jump to

Keyboard shortcuts

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