git.deanishe.net/deanishe/awgo.git@v0.15.0/workflow_update.go (about) 1 // 2 // Copyright (c) 2018 Dean Jackson <deanishe@deanishe.net> 3 // 4 // MIT Licence. See http://opensource.org/licenses/MIT 5 // 6 // Created on 2018-02-11 7 // 8 9 package aw 10 11 import ( 12 "errors" 13 "log" 14 "time" 15 ) 16 17 // Updater can check for and download & install newer versions of the workflow. 18 // There is a concrete implementation and documentation in subpackage "update". 19 type Updater interface { 20 UpdateInterval(time.Duration) // Set interval between checks 21 UpdateAvailable() bool // Return true if a newer version is available 22 CheckDue() bool // Return true if a check for a newer version is due 23 CheckForUpdate() error // Retrieve available releases, e.g. from a URL 24 Install() error // Install the latest version 25 } 26 27 // -------------------------------------------------------------------- 28 // Updating 29 30 // setUpdater sets an updater for the workflow. 31 func (wf *Workflow) setUpdater(u Updater) { 32 wf.Updater = u 33 wf.MagicActions.Register(&updateMA{wf.Updater}) 34 } 35 36 // UpdateCheckDue returns true if an update is available. 37 func (wf *Workflow) UpdateCheckDue() bool { 38 if wf.Updater == nil { 39 log.Println("No updater configured") 40 return false 41 } 42 return wf.Updater.CheckDue() 43 } 44 45 // CheckForUpdate retrieves and caches the list of available releases. 46 func (wf *Workflow) CheckForUpdate() error { 47 if wf.Updater == nil { 48 return errors.New("No updater configured") 49 } 50 return wf.Updater.CheckForUpdate() 51 } 52 53 // UpdateAvailable returns true if a newer version is available to install. 54 func (wf *Workflow) UpdateAvailable() bool { 55 if wf.Updater == nil { 56 log.Println("No updater configured") 57 return false 58 } 59 return wf.Updater.UpdateAvailable() 60 } 61 62 // InstallUpdate downloads and installs the latest version of the workflow. 63 func (wf *Workflow) InstallUpdate() error { 64 if wf.Updater == nil { 65 return errors.New("No updater configured") 66 } 67 return wf.Updater.Install() 68 }