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