Skip to content

Commit

Permalink
Upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
matejkramny committed Apr 26, 2016
1 parent 030fe55 commit 697e456
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 6 deletions.
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
13 changes: 8 additions & 5 deletions public/css/semaphore.css
Original file line number Diff line number Diff line change
Expand Up @@ -9583,28 +9583,31 @@ 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;
}
@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);
}
}
87 changes: 87 additions & 0 deletions upgrade/upgrade.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions util/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion util/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package util

var Version string = "0.0.0"
var Version string = "2.0-beta"

0 comments on commit 697e456

Please sign in to comment.