mirror of
https://github.com/semaphoreui/semaphore.git
synced 2025-01-20 15:29:28 +01:00
Upgrade
This commit is contained in:
parent
030fe5522b
commit
697e456802
9
main.go
9
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)
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
87
upgrade/upgrade.go
Normal file
87
upgrade/upgrade.go
Normal file
@ -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
|
||||
}
|
@ -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
|
||||
|
@ -1,3 +1,3 @@
|
||||
package util
|
||||
|
||||
var Version string = "0.0.0"
|
||||
var Version string = "2.0-beta"
|
||||
|
Loading…
Reference in New Issue
Block a user