From 697e456802eabec346856f12d9956fb2c412a5d7 Mon Sep 17 00:00:00 2001 From: Matej Kramny Date: Tue, 26 Apr 2016 19:18:28 +0100 Subject: [PATCH] Upgrade --- main.go | 9 +++++ public/css/semaphore.css | 13 +++--- upgrade/upgrade.go | 87 ++++++++++++++++++++++++++++++++++++++++ util/config.go | 2 + util/version.go | 2 +- 5 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 upgrade/upgrade.go diff --git a/main.go b/main.go index 507c0784..1a3bf41f 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,7 @@ import ( "github.com/ansible-semaphore/semaphore/routes" "github.com/ansible-semaphore/semaphore/routes/sockets" "github.com/ansible-semaphore/semaphore/routes/tasks" + "github.com/ansible-semaphore/semaphore/upgrade" "github.com/ansible-semaphore/semaphore/util" "github.com/bugsnag/bugsnag-go" "github.com/gin-gonic/gin" @@ -26,6 +27,14 @@ func main() { os.Exit(doSetup()) } + if util.Upgrade { + if err := upgrade.Upgrade(util.Version); err != nil { + panic(err) + } + + os.Exit(0) + } + fmt.Printf("Semaphore %v\n", util.Version) fmt.Printf("Port %v\n", util.Config.Port) fmt.Printf("MySQL %v@%v %v\n", util.Config.MySQL.Username, util.Config.MySQL.Hostname, util.Config.MySQL.DbName) diff --git a/public/css/semaphore.css b/public/css/semaphore.css index ec4c7f29..36318ff5 100644 --- a/public/css/semaphore.css +++ b/public/css/semaphore.css @@ -9583,13 +9583,16 @@ ul.nav > li.active a { position: absolute; left: 0; bottom: 0; - transform: scale(-1, -1); + transform: rotate(360deg) scale(-1, -1); mix-blend-mode: darken; color: #ffffff; fill: #000000; } +.octo-body { + transform: rotate(-226deg) translate(-250px, -260px); +} .octo-arm { - transform-origin: 130px 110px; + transform: rotate(-226deg) translate(-250px, -260px); } .github-corner:hover .octo-arm { animation: octocat-wave 0.56s; @@ -9597,14 +9600,14 @@ ul.nav > li.active a { @keyframes octocat-wave { 0%, 100% { - transform: rotate(0); + transform: rotate(-226deg) translate(-250px, -260px); } 20%, 60% { - transform: rotate(-20deg); + transform: rotate(-227deg) translate(-250px, -260px); } 40%, 80% { - transform: rotate(10deg); + transform: rotate(-226deg) translate(-250px, -260px); } } diff --git a/upgrade/upgrade.go b/upgrade/upgrade.go new file mode 100644 index 00000000..e5c99eff --- /dev/null +++ b/upgrade/upgrade.go @@ -0,0 +1,87 @@ +package upgrade + +import ( + "errors" + "fmt" + "io" + "net/http" + "os" + "os/exec" + "path/filepath" + "runtime" + + "github.com/google/go-github/github" +) + +// Adapted from github.com/apex/apex + +func Upgrade(version string) error { + fmt.Printf("current release is v%s\n", version) + + // fetch releases + gh := github.NewClient(nil) + releases, _, err := gh.Repositories.ListReleases("ansible-semaphore", "semaphore", nil) + if err != nil { + return err + } + + // see if it's new + latest := releases[0] + fmt.Printf("latest release is %s\n", *latest.TagName) + + if (*latest.TagName)[1:] == version { + return nil + } + + asset := findAsset(&latest) + if asset == nil { + return errors.New("cannot find binary for your system") + } + + // create tmp file + tmpPath := filepath.Join(os.TempDir(), "semaphore-upgrade") + f, err := os.OpenFile(tmpPath, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0755) + if err != nil { + return err + } + + // download binary + fmt.Printf("downloading %s\n", *asset.BrowserDownloadURL) + res, err := http.Get(*asset.BrowserDownloadURL) + if err != nil { + return err + } + defer res.Body.Close() + + // copy it down + _, err = io.Copy(f, res.Body) + if err != nil { + return err + } + + // replace it + cmdPath, err := exec.LookPath("semaphore") + if err != nil { + return err + } + + fmt.Printf("replacing %s\n", cmdPath) + err = os.Rename(tmpPath, cmdPath) + if err != nil { + return err + } + + fmt.Println("visit https://github.com/ansible-semaphore/semaphore/releases for the changelog") + return nil +} + +// findAsset returns the binary for this platform. +func findAsset(release *github.RepositoryRelease) *github.ReleaseAsset { + for _, asset := range release.Assets { + if *asset.Name == fmt.Sprintf("semaphore_%s_%s", runtime.GOOS, runtime.GOARCH) { + return &asset + } + } + + return nil +} diff --git a/util/config.go b/util/config.go index a3be7484..6ab2b135 100644 --- a/util/config.go +++ b/util/config.go @@ -17,6 +17,7 @@ import ( var mandrillAPI *gochimp.MandrillAPI var Migration bool var InteractiveSetup bool +var Upgrade bool type mySQLConfig struct { Hostname string `json:"host"` @@ -48,6 +49,7 @@ var Config configType func init() { flag.BoolVar(&InteractiveSetup, "setup", false, "perform interactive setup") flag.BoolVar(&Migration, "migrate", false, "execute migrations") + flag.BoolVar(&Upgrade, "upgrade", false, "upgrade semaphore") path := flag.String("config", "", "config path") var pwd string diff --git a/util/version.go b/util/version.go index a8187659..434fc16c 100644 --- a/util/version.go +++ b/util/version.go @@ -1,3 +1,3 @@ package util -var Version string = "0.0.0" +var Version string = "2.0-beta"