-
Notifications
You must be signed in to change notification settings - Fork 46
/
workflow_update.go
61 lines (52 loc) · 1.72 KB
/
workflow_update.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) 2018 Dean Jackson <[email protected]>
// MIT Licence - http://opensource.org/licenses/MIT
package aw
import (
"errors"
"log"
)
// Updater can check for and download & install newer versions of the workflow.
// There is a concrete implementation and documentation in subpackage update.
type Updater interface {
UpdateAvailable() bool // Return true if a newer version is available
CheckDue() bool // Return true if a check for a newer version is due
CheckForUpdate() error // Retrieve available releases, e.g. from a URL
Install() error // Install the latest version
}
// --------------------------------------------------------------------
// Updating
// setUpdater sets an updater for the workflow.
func (wf *Workflow) setUpdater(u Updater) {
wf.Updater = u
wf.magicActions.register(&updateMA{wf.Updater})
}
// UpdateCheckDue returns true if an update is available.
func (wf *Workflow) UpdateCheckDue() bool {
if wf.Updater == nil {
log.Println("No updater configured")
return false
}
return wf.Updater.CheckDue()
}
// CheckForUpdate retrieves and caches the list of available releases.
func (wf *Workflow) CheckForUpdate() error {
if wf.Updater == nil {
return errors.New("No updater configured")
}
return wf.Updater.CheckForUpdate()
}
// UpdateAvailable returns true if a newer version is available to install.
func (wf *Workflow) UpdateAvailable() bool {
if wf.Updater == nil {
log.Println("No updater configured")
return false
}
return wf.Updater.UpdateAvailable()
}
// InstallUpdate downloads and installs the latest version of the workflow.
func (wf *Workflow) InstallUpdate() error {
if wf.Updater == nil {
return errors.New("No updater configured")
}
return wf.Updater.Install()
}