-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add additional os build targets and self updater (#246)
* add additional build targets * add self updater * clean up todo
- Loading branch information
Showing
6 changed files
with
140 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"log" | ||
"os" | ||
"runtime" | ||
|
||
selfupdate "github.com/creativeprojects/go-selfupdate" | ||
) | ||
|
||
func update(version string) error { | ||
latest, found, err := selfupdate.DetectLatest(context.Background(), selfupdate.ParseSlug("simimpact/srsim")) | ||
if err != nil { | ||
return fmt.Errorf("error occurred while detecting version: %w", err) | ||
} | ||
if !found { | ||
return fmt.Errorf("latest version for %s/%s could not be found from github repository", runtime.GOOS, runtime.GOARCH) | ||
} | ||
|
||
if latest.LessOrEqual(version) { | ||
log.Printf("Current version (%s) is the latest", version) | ||
return nil | ||
} | ||
|
||
exe, err := os.Executable() | ||
if err != nil { | ||
return errors.New("could not locate executable path") | ||
} | ||
if err := selfupdate.UpdateTo(context.Background(), latest.AssetURL, latest.AssetName, exe); err != nil { | ||
return fmt.Errorf("error occurred while updating binary: %w", err) | ||
} | ||
log.Printf("Successfully updated to version %s", latest.Version()) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters