Documentation ¶
Overview ¶
Package update implements an API for fetching updates to workflows from remote servers.
The Updater/Releaser API provides the ability to check for newer versions of your workflow. Support for updating from GitHub and Gitea releases is built in. See GitHub example.
You can use your own backend by implementing the Releaser interface.
The only hard requirement is support for (mostly) semantic version numbers. See SemVer documentation and http://semver.org for details.
This package is the "backend". You should set an Updater on an aw.Workflow struct (using e.g. the GitHub aw.Option) and use the Workflow methods CheckForUpdate(), UpdateAvailable() and InstallUpdate() to interact with the Updater.
See ../_examples/update for one possible way to use this API.
Index ¶
- Variables
- func GitHub(repo string) aw.Option
- func Gitea(repo string) aw.Option
- func SortSemVer(versions []SemVer)
- type Download
- type SemVer
- func (v SemVer) Compare(v2 SemVer) int
- func (v SemVer) Eq(v2 SemVer) bool
- func (v SemVer) Gt(v2 SemVer) bool
- func (v SemVer) Gte(v2 SemVer) bool
- func (v SemVer) IsZero() bool
- func (v SemVer) Lt(v2 SemVer) bool
- func (v SemVer) Lte(v2 SemVer) bool
- func (v SemVer) Ne(v2 SemVer) bool
- func (v SemVer) String() string
- type SemVers
- type Source
- type Updater
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func GitHub ¶
GitHub2is a Workflow Option. It sets a Workflow Updater for the specified GitHub repo. Repo name should be of the form "username/repo", e.g. "deanishe/alfred-ssh".
Example ¶
Configure Workflow to update from a GitHub repo.
// Set source repo using GitHub Option wf := aw.New(GitHub("deanishe/alfred-ssh")) // Is a check for a newer version due? fmt.Println(wf.UpdateCheckDue())
Output: true
func Gitea ¶ added in v0.16.0
Gitea is a Workflow Option. It sets a Workflow Updater for the specified Gitea repo. Repo name should be of the form "username/repo", e.g. "git.deanishe.net/deanishe/alfred-ssh".
Example ¶
Configure Workflow to update from a Gitea repo.
// Set source repo using Gitea Option wf := aw.New(Gitea("git.deanishe.net/deanishe/alfred-ssh")) // Is a check for a newer version due? fmt.Println(wf.UpdateCheckDue())
Output: true
Types ¶
type Download ¶ added in v0.17.0
type Download struct { // URL is the download location the workflow file can be downloaded from URL string // Filename for downloaded file. // Must have extension .alfredworkflow or .alfredXworkflow where X is a number, // otherwise the Download will be ignored. Filename string Version SemVer // Workflow version no. Prerelease bool // Whether this version is a pre-release }
Download is an Alfred workflow available for download & installation.
func (Download) AlfredVersion ¶ added in v0.17.0
AlfredVersion returns minimum compatible version of Alfred based on file extension. For example, Workflow.alfred4workflow has version 4, while Workflow.alfred3workflow has version 3. The standard .alfredworkflow extension returns a zero version.
type SemVer ¶
type SemVer struct { Major uint64 // Increment for breaking changes. Minor uint64 // Increment for added/deprecated functionality. Patch uint64 // Increment for bugfixes. Build string // Build metadata (ignored in comparisons) Prerelease string // Pre-release version (treated as string) }
SemVer is a (mostly) semantic version number.
Unlike the semver standard:
- Minor and patch versions are not required, e.g. "v1" and "v1.0" are valid.
- Version string may be prefixed with "v", e.g. "v1" or "v3.0.1-beta". The "v" prefix is stripped, so "v1" == "1.0.0".
- Dots and integers are ignored in pre-release identifiers: they are compared purely alphanumerically, e.g. "v1-beta.11" < "v1-beta.2". Use "v1-beta.02" instead.
func NewSemVer ¶
NewSemVer creates a new SemVer. An error is returned if the version string is not valid. See the SemVer struct documentation for deviations from the semver standard.
func (SemVer) Compare ¶
Compare compares two Versions. Returns:
-1 if v < v2 0 if v == v2 1 if v > v2
type Source ¶ added in v0.17.0
Source provides workflow files that can be downloaded. This is what concrete updaters (e.g. GitHub, Gitea) should implement. Source is called by the Updater after every updater interval.
type Updater ¶
type Updater struct { Source Source // Provides downloads CurrentVersion SemVer // Version of the installed workflow Prereleases bool // Include pre-releases when checking for updates // AlfredVersion is the version of the running Alfred application. // Read from $alfred_version environment variable. AlfredVersion SemVer // When the remote release list was last checked (and possibly cached) LastCheck time.Time // contains filtered or unexported fields }
Updater checks for newer version of the workflow. Available versions are provided by a Source, such as the built-in GitHub source, which reads the releases in a GitHub repo.
CheckForUpdate() retrieves the list of available downloads from the source and caches them. UpdateAvailable() reads the cache and returns true if there is a download with a higher version than the current workflow. Install() downloads the latest version and asks Alfred to install it.
Because downloading releases is slow and workflows need to run fast, you should not run CheckForUpdate() in a Script Filter.
If an Updater is set on a Workflow struct, a magic action will be set for updates, so you can just add an Item that autocompletes to the update magic argument ("workflow:update" by default), and AwGo will check for an update and install it if available.
See ../examples/update for a full example implementation of updates.
func NewUpdater ¶ added in v0.17.0
NewUpdater creates a new Updater from Source.
func (*Updater) CheckDue ¶
CheckDue returns true if the time since the last check is greater than Updater.UpdateInterval.
func (*Updater) CheckForUpdate ¶
CheckForUpdate fetches the list of releases from remote (via Releaser) and caches it locally.
func (*Updater) Install ¶
Install downloads and installs the latest available version. After the workflow file is downloaded, Install calls Alfred to install the update.
func (*Updater) UpdateAvailable ¶
UpdateAvailable returns true if an update is available. Retrieves the list of releases from the cache written by CheckForUpdate.