go-github-selfupdate: github.com/rhysd/go-github-selfupdate/selfupdate Index | Files

package selfupdate

import "github.com/rhysd/go-github-selfupdate/selfupdate"

Package selfupdate provides self-update mechanism to Go command line tools.

Go does not provide the way to install/update the stable version of tools. By default, Go command line tools are updated

- using `go get -u` (updating to HEAD) - using system's package manager (depending on the platform) - downloading executables from GitHub release page manually

By using this library, you will get 4th choice:

- from your command line tool directly (and automatically)

go-github-selfupdate detects the information of the latest release via GitHub Releases API and check the current version. If newer version than itself is detected, it downloads released binary from GitHub and replaces itself.

- Automatically detects the latest version of released binary on GitHub - Retrieve the proper binary for the OS and arch where the binary is running - Update the binary with rollback support on failure - Tested on Linux, macOS and Windows - Many archive and compression formats are supported (zip, gzip, xzip, tar)

There are some naming rules. Please read following links.

Naming Rules of Released Binaries:

https://github.com/rhysd/go-github-selfupdate#naming-rules-of-released-binaries

Naming Rules of Git Tags:

https://github.com/rhysd/go-github-selfupdate#naming-rules-of-git-tags

This package is hosted on GitHub:

https://github.com/rhysd/go-github-selfupdate

Small CLI tools as wrapper of this library are available also:

https://github.com/rhysd/go-github-selfupdate/cmd/detect-latest-release
https://github.com/rhysd/go-github-selfupdate/cmd/go-get-release

Index

Package Files

detect.go doc.go log.go release.go uncompress.go update.go updater.go

func DisableLog Uses

func DisableLog()

DisableLog disables to output logging messages in library

func EnableLog Uses

func EnableLog()

EnableLog enables to output logging messages in library

func UncompressCommand Uses

func UncompressCommand(src io.Reader, url, cmd string) (io.Reader, error)

UncompressCommand uncompresses the given source. Archive and compression format is automatically detected from 'url' parameter, which represents the URL of asset. This returns a reader for the uncompressed command given by 'cmd'. '.zip', '.tar.gz', '.tar.xz', '.gz' and '.xz' are supported.

func UpdateTo Uses

func UpdateTo(assetURL, cmdPath string) error

UpdateTo downloads an executable from assetURL and replace the current binary with the downloaded one. This function is low-level API to update the binary. Because it does not use GitHub API and downloads asset directly from the URL via HTTP, this function is not available to update a release for private repositories. cmdPath is a file path to command executable.

type Config Uses

type Config struct {
    // APIToken represents GitHub API token. If it's not empty, it will be used for authentication of GitHub API
    APIToken string
    // EnterpriseBaseURL is a base URL of GitHub API. If you want to use this library with GitHub Enterprise,
    // please set "https://{your-organization-address}/api/v3/" to this field.
    EnterpriseBaseURL string
    // EnterpriseUploadURL is a URL to upload stuffs to GitHub Enterprise instance. This is often the same as an API base URL.
    // So if this field is not set and EnterpriseBaseURL is set, EnterpriseBaseURL is also set to this field.
    EnterpriseUploadURL string
}

Config represents the configuration of self-update.

type Release Uses

type Release struct {
    // Version is the version of the release
    Version semver.Version
    // AssetURL is a URL to the uploaded file for the release
    AssetURL string
    // AssetSize represents the size of asset in bytes
    AssetByteSize int
    // AssetID is the ID of the asset on GitHub
    AssetID int64
    // URL is a URL to release page for browsing
    URL string
    // ReleaseNotes is a release notes of the release
    ReleaseNotes string
    // Name represents a name of the release
    Name string
    // PublishedAt is the time when the release was published
    PublishedAt *time.Time
    // RepoOwner is the owner of the repository of the release
    RepoOwner string
    // RepoName is the name of the repository of the release
    RepoName string
}

Release represents a release asset for current OS and arch.

func DetectLatest Uses

func DetectLatest(slug string) (*Release, bool, error)

DetectLatest detects the latest release of the slug (owner/repo). This function is a shortcut version of updater.DetectLatest() method.

func DetectVersion Uses

func DetectVersion(slug string, version string) (*Release, bool, error)

DetectVersion detects the given release of the slug (owner/repo) from its version.

func UpdateCommand Uses

func UpdateCommand(cmdPath string, current semver.Version, slug string) (*Release, error)

UpdateCommand updates a given command binary to the latest version. This function is a shortcut version of updater.UpdateCommand.

func UpdateSelf Uses

func UpdateSelf(current semver.Version, slug string) (*Release, error)

UpdateSelf updates the running executable itself to the latest version. This function is a shortcut version of updater.UpdateSelf.

type Updater Uses

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

Updater is responsible for managing the context of self-update. It contains GitHub client and its context.

func DefaultUpdater Uses

func DefaultUpdater() *Updater

DefaultUpdater creates a new updater instance with default configuration. It initializes GitHub API client with default API base URL. If you set your API token to $GITHUB_TOKEN, the client will use it.

func NewUpdater Uses

func NewUpdater(config Config) (*Updater, error)

NewUpdater creates a new updater instance. It initializes GitHub API client. If you set your API token to $GITHUB_TOKEN, the client will use it.

func (*Updater) DetectLatest Uses

func (up *Updater) DetectLatest(slug string) (release *Release, found bool, err error)

DetectLatest tries to get the latest version of the repository on GitHub. 'slug' means 'owner/name' formatted string. It fetches releases information from GitHub API and find out the latest release with matching the tag names and asset names. Drafts and pre-releases are ignored. Assets would be suffixed by the OS name and the arch name such as 'foo_linux_amd64' where 'foo' is a command name. '-' can also be used as a separator. File can be compressed with zip, gzip, zxip, tar&zip or tar&zxip. So the asset can have a file extension for the corresponding compression format such as '.zip'. On Windows, '.exe' also can be contained such as 'foo_windows_amd64.exe.zip'.

func (*Updater) DetectVersion Uses

func (up *Updater) DetectVersion(slug string, version string) (release *Release, found bool, err error)

DetectVersion tries to get the given version of the repository on Github. `slug` means `owner/name` formatted string. And version indicates the required version.

func (*Updater) UpdateCommand Uses

func (up *Updater) UpdateCommand(cmdPath string, current semver.Version, slug string) (*Release, error)

UpdateCommand updates a given command binary to the latest version. 'slug' represents 'owner/name' repository on GitHub and 'current' means the current version.

func (*Updater) UpdateSelf Uses

func (up *Updater) UpdateSelf(current semver.Version, slug string) (*Release, error)

UpdateSelf updates the running executable itself to the latest version. 'slug' represents 'owner/name' repository on GitHub and 'current' means the current version.

func (*Updater) UpdateTo Uses

func (up *Updater) UpdateTo(rel *Release, cmdPath string) error

UpdateTo downloads an executable from GitHub Releases API and replace current binary with the downloaded one. It downloads a release asset via GitHub Releases API so this function is available for update releases on private repository. If a redirect occurs, it fallbacks into directly downloading from the redirect URL.

Package selfupdate imports 22 packages (graph) and is imported by 9 packages. Updated 2018-09-27. Refresh now. Tools for package owners.