updatecheck

package
v0.16.355 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package updatecheck tells a self-hosted runtime whether a newer release is published: a periodic GET of the project's latest-release address, compared with the running version. It sends nothing but that request.

Index

Constants

View Source
const (
	ChannelStable = "stable"
	ChannelLatest = "latest"
)

The update channels of an installation. "latest" is every published release. "stable" is the release the stable pointer names: a small file beside the releases that moves only when somebody promotes a release (tools/relchannel, docs/update-channels.md), never by a merge.

View Source
const (
	// DefaultInterval is the time between checks.
	DefaultInterval = 12 * time.Hour
	// Timeout bounds one request.
	Timeout = 10 * time.Second
)
View Source
const DefaultStableURL = "https://github.com/ly-solutions/harnessly/releases/download/channels/stable.json"

DefaultStableURL is the project's stable pointer: an asset of the "channels" release, read without the API.

View Source
const DefaultURL = "https://api.github.com/repos/ly-solutions/harnessly/releases/latest"

DefaultURL is the project's latest published (non-draft, non-pre-release) release.

View Source
const DefaultWindow = 7 * 24 * time.Hour

DefaultWindow is how long a release must have been out before it may become stable.

View Source
const PointerSchema = 1

PointerSchema is the version of the pointer's format.

View Source
const WithdrawnMark = "[withdrawn]"

WithdrawnMark in the title or the notes of a release says it was withdrawn: it never becomes stable.

Variables

View Source
var ErrNoStable = errors.New("no stable release is named")

ErrNoStable: the source of releases names no stable one, so an installation on the stable channel stays as it is.

View Source
var ErrRefused = errors.New("not promoted")

ErrRefused wraps every reason a release may not become stable.

Functions

func Comparable

func Comparable(current string) bool

Comparable says whether the running version can be compared with a release at all.

func Compare

func Compare(a, b Version) int

Compare returns -1, 0 or 1. A pre-release is older than its release.

func ParseChannel

func ParseChannel(raw string) (channel string, ok bool)

ParseChannel reads a channel setting. Empty is the default, stable. ok is false for a word that is no channel; the answer is then stable too: the careful one.

Types

type Candidate

type Candidate struct {
	TagName     string `json:"tag_name"`
	Name        string `json:"name"`
	Body        string `json:"body"`
	HTMLURL     string `json:"html_url"`
	PublishedAt string `json:"published_at"`
	Draft       bool   `json:"draft"`
	Prerelease  bool   `json:"prerelease"`
}

Candidate is a published release as the releases API describes it, the part a promotion reads.

type Checker

type Checker struct {
	// Current is the running version, as built in ("dev" or unparsable means there is nothing to compare).
	Current string
	// URL is the latest-release address; empty means DefaultURL.
	URL string
	// Channel is ChannelStable or ChannelLatest; empty reads the latest release, as a checker without channels did.
	Channel string
	// StableURL is the stable pointer's address. Empty means DefaultStableURL while URL is the project's own; a
	// mirror named by URL has no pointer until StableURL names it.
	StableURL string
	// Client makes the request; nil means one that honours the proxy environment and times out.
	Client *http.Client
	// Interval is the time between checks; zero means DefaultInterval.
	Interval time.Duration
	// Log gets one line per failed check; may be nil.
	Log func(msg string, err error)
	// contains filtered or unexported fields
}

Checker asks for the newest release of its channel and keeps the answer. Set Current.

func (*Checker) Check

func (c *Checker) Check(ctx context.Context) error

Check makes one request and updates Status. A 304 keeps the previous answer.

func (*Checker) Run

func (c *Checker) Run(ctx context.Context)

Run checks at once and then every Interval until ctx ends. Start it with go: the first request must not hold up anything.

func (*Checker) Status

func (c *Checker) Status() Status

Status is the last answer; before the first one, or when nothing is newer, UpdateAvailable is false.

type Pointer

type Pointer struct {
	Schema  int    `json:"schema"`
	Channel string `json:"channel"`
	// Version is the stable release, X.Y.Z.
	Version string `json:"version"`
	// URL is the release's page.
	URL string `json:"url,omitempty"`
	// ReleasedAt is when the release was published, PromotedAt when it became stable; RFC 3339.
	ReleasedAt string `json:"released_at,omitempty"`
	PromotedAt string `json:"promoted_at,omitempty"`
}

Pointer is the stable pointer's file.

func ParsePointer

func ParsePointer(body []byte) (Pointer, error)

ParsePointer reads a stable pointer. Fields it does not know are ignored, so a later format that only adds reads too.

func Promote

func Promote(rel Candidate, p Promotion) (Pointer, error)

Promote decides whether the release may become the stable one and answers with the pointer that says so. It is refused (ErrRefused) when the release is a draft, a pre-release or withdrawn, has been out for less than the window, or is older than the stable one in place.

type Promotion

type Promotion struct {
	// Now is the time of the promotion.
	Now time.Time
	// Window is how long the release must have been out; zero means DefaultWindow.
	Window time.Duration
	// Current is the pointer in place, nil when there is none yet.
	Current *Pointer
	// AllowOlder lets the pointer move back to an older release (taking a bad stable one away).
	AllowOlder bool
}

Promotion is what a promotion is decided by.

type Status

type Status struct {
	Current         string `json:"current"`
	Latest          string `json:"latest,omitempty"`
	URL             string `json:"url,omitempty"`
	PublishedAt     string `json:"publishedAt,omitempty"`
	UpdateAvailable bool   `json:"updateAvailable"`
	// Channel is the update channel the answer is of (channel.go); empty when the checker was given none.
	Channel string `json:"channel,omitempty"`
	// Note says, for the person, why the channel has no answer (no stable release was named yet, say).
	Note string `json:"note,omitempty"`
}

Status is what the page is told.

type Version

type Version struct {
	Major, Minor, Patch int
	Pre                 string
}

Version is a parsed semantic version: major.minor.patch with an optional pre-release (build metadata is dropped).

func Parse

func Parse(s string) (v Version, ok bool)

Parse reads "1.2.3", "v1.2.3" or "1.2.3-rc.1"; ok is false for anything else (including "dev").

func (Version) String

func (v Version) String() string

Jump to

Keyboard shortcuts

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